From nobody Fri Oct 18 05:18:51 2024 Delivered-To: importer@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; dkim=fail; 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 1543308593708854.0860447827605; Tue, 27 Nov 2018 00:49:53 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5FE553086267; Tue, 27 Nov 2018 08:49:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5156860C47; Tue, 27 Nov 2018 08:49:52 +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 436DB3F953; Tue, 27 Nov 2018 08:49:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wAR8np9G010725 for ; Tue, 27 Nov 2018 03:49:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id B8DE25DAA0; Tue, 27 Nov 2018 08:49:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B74DA5DD63; Tue, 27 Nov 2018 08:49:45 +0000 (UTC) Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8CD8C3078AA7; Tue, 27 Nov 2018 08:49:43 +0000 (UTC) Received: by mail-wr1-f47.google.com with SMTP id j2so21771452wrw.1; Tue, 27 Nov 2018 00:49:43 -0800 (PST) Received: from localhost.localdomain ([2001:b07:6468:f312:60a1:384e:4c17:72ad]) by smtp.gmail.com with ESMTPSA id y34sm5083010wrd.68.2018.11.27.00.49.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Nov 2018 00:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ua1AtJxJDRCF3uJdRlvudHpy50kqJfwNljEdFtJ4Xh0=; b=cXA5eC3oXW5HrvmRci5UwyYoujKAVNGL50mTYiB1ABxwVkvGj5VxyyrNsMqvhKo3Ny Lyf1fuBz3oY/cu1ecs7+T4dvNFtVQifArxZc6uyiyktSzb9bJn1L+vGlOv4NQ/smrg21 LlmZXebMBQOnGAS0INDhcF9FNMejccjiC1paW0TMLQQD/kNxvLxJ2eusrvw4QjitMIeF q93KHei4Vi2z01TXvCrwTU+RMqyY4CigPthMOLM9whwlPCTXI33wbb32rt8a9ookY6YW EFe+LUUfyGYq8w+onmVigkvtoL+xrxTZQff8K72+z7TkU7aMWFbm6x7NCgerNzbX8mHj vPtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ua1AtJxJDRCF3uJdRlvudHpy50kqJfwNljEdFtJ4Xh0=; b=WC5LwWbnGMgczjg90G5Uv3v0uwsffGQ3jcAJ2Qa+MRxjfCnVLugWPyispuqQO0s2Zd OdFDFO19YTV9O+/1L+G1nQN30bFhuGoIeblPLjhCfmQFXGVbBuGXw+gF2rqAXVJUDBuk SlgMWvdiuUTrt85mfQJ/vlJsQyRdAgPD2toAaYXgTIvmUTPDEDz5Opm5YMb3io2Bj0lr XGBrSQvTfaW+tvUJvTMDfWPf2vjkuW5SXxHDyb14U0WfyPw42dSWWqQ0MkETx7l32Dv5 NlZ3emKRHRrRcM4BmIL2XGtEUfIAXrNHipjhxjOeOYWUhtlROf1rjWW3bGvIstmIrXrb ClJA== X-Gm-Message-State: AA+aEWbnUVsb1BKBtjA++XjYlM0n9uSrIgJd8F0JZK+N/X6jiHK6+G0M qLWRJntxHD6qFX4LO5W6Vm7d6gNY X-Google-Smtp-Source: AFSGD/WspFC6F+DTWcayG/WvzOveIlT63T/ktnpyF5HGm/BdKH24TCMESjN6nbBmN5S7WgIxEqa//Q== X-Received: by 2002:a5d:43d0:: with SMTP id v16mr28378078wrr.67.1543308581896; Tue, 27 Nov 2018 00:49:41 -0800 (PST) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Tue, 27 Nov 2018 09:49:34 +0100 Message-Id: <20181127084935.17898-2-pbonzini@redhat.com> In-Reply-To: <20181127084935.17898-1-pbonzini@redhat.com> References: <20181127084935.17898-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 27 Nov 2018 08:49:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 27 Nov 2018 08:49:43 +0000 (UTC) for IP:'209.85.221.47' DOMAIN:'mail-wr1-f47.google.com' HELO:'mail-wr1-f47.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.24 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.221.47 mail-wr1-f47.google.com 209.85.221.47 mail-wr1-f47.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Cc: famz@redhat.com Subject: [Patchew-devel] [PATCH 1/2] views: join messages as bytes into the 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.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 27 Nov 2018 08:49:52 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" To simplify the code, let email.message do the encoding and create the From= line for the mbox. The case where a message cannot be parsed is not handled any= more; it was not necessary because that should have resulted in a failed import in the first place. Signed-off-by: Paolo Bonzini Reviewed-by: Caio Carrara --- www/views.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/www/views.py b/www/views.py index 49357e2..45f63c8 100644 --- a/www/views.py +++ b/www/views.py @@ -286,17 +286,14 @@ def view_mbox(request, project, message_id): =20 def get_mbox_with_tags(m): mbox =3D m.get_mbox() - try: - msg =3D email.message_from_string(mbox) - except Exception: - return mbox + msg =3D email.message_from_string(mbox) container =3D msg.get_payload(0) if msg.is_multipart() else msg if container.get_content_type() !=3D "text/plain": - return mbox + return msg.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() + return msg.as_bytes(unixfrom=3DTrue) =20 s =3D api.models.Message.objects.find_message(message_id, project) if not s: @@ -310,14 +307,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