From nobody Thu Apr 18 09:34:35 2024 Delivered-To: importer2@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1543255767190398.5832339575545; Mon, 26 Nov 2018 10:09:27 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDB7FC05091D; Mon, 26 Nov 2018 18:09:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D85A81057075; Mon, 26 Nov 2018 18:09:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CC947181A968; Mon, 26 Nov 2018 18:09:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wAQI9OcB005353 for ; Mon, 26 Nov 2018 13:09:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 40A4260BEC; Mon, 26 Nov 2018 18:09:24 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A3A460C54 for ; Mon, 26 Nov 2018 18:09:15 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Mon, 26 Nov 2018 19:09:14 +0100 Message-Id: <20181126180914.22161-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH urgent] views: fix Content-Transfer-Encoding and Content-Type of downloaded mbox X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 26 Nov 2018 18:09:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" set_payload expects the argument to be already encoded according to the message's content type and transfer encoding. Force a good charset and transfer encoding, in case the source message's is incompatible with the trailers. Otherwise, adding an 8-bit trailer to a 7-bit message causes the email module to switch to quoted-printable, without the body actually being quoted-printable. As a result, all equals sign in the original message are broken. Signed-off-by: Paolo Bonzini --- I did not have time to make a testcase for this, but it would be nice to have it applied to patchew.org, because /mbox is more or less broken currently. See for example https://patchew.org/QEMU/20181126152836.25379-1-rkagan@virtuozzo.com/mbox www/views.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/www/views.py b/www/views.py index 5927e61..52ae962 100644 --- a/www/views.py +++ b/www/views.py @@ -17,6 +17,7 @@ from django.utils.html import format_html from django.conf import settings import api import email +import quopri from mbox import decode_payload import re from mod import dispatch_module_hook @@ -289,14 +290,22 @@ def view_mbox(request, project, message_id): try: msg =3D email.message_from_string(mbox) except Exception: - return mbox + return mbox.as_bytes(unixfrom=3DTrue) container =3D msg.get_payload(0) if msg.is_multipart() else msg if container.get_content_type() !=3D "text/plain": - return mbox + return mbox.as_bytes(unixfrom=3DTrue) =20 payload =3D decode_payload(container) - container.set_payload('\n'.join(mbox_with_tags_iter(payload, m.tag= s))) - return msg.as_string() + # We might be adding 8-bit trailers to a message with 7bit CTE. F= or + # patches, quoted-printable is safe and mostly human-readable. + try: + container.replace_header('Content-Transfer-Encoding', 'quoted-= printable') + except: + msg.add_header('Content-Transfer-Encoding', 'quoted-printable') + payload =3D '\n'.join(mbox_with_tags_iter(payload, m.tags)) + payload =3D quopri.encodestring(payload.encode('utf-8')) + container.set_payload(payload, charset=3D'utf-8') + return msg.as_bytes(unixfrom=3DTrue) =20 s =3D api.models.Message.objects.find_message(message_id, project) if not s: @@ -310,14 +319,8 @@ def view_mbox(request, project, message_id): =20 mbox_list =3D [] for message in messages: - mbox_list.append( - "From %s %s\n%s" % ( - message.get_sender_addr(), - message.get_asctime(), - get_mbox_with_tags(message) - ) - ) - mbox =3D "\n".join(mbox_list) + mbox_list.append(get_mbox_with_tags(message)) + mbox =3D b"\n".join(mbox_list) return HttpResponse(mbox, content_type=3D"text/plain") =20 =20 --=20 2.19.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel