[Patchew-devel] [PATCH 1/2] views: join messages as bytes into the mbox
Caio Carrara
ccarrara at redhat.com
Tue Nov 27 12:12:49 UTC 2018
On Tue, Nov 27, 2018 at 09:49:34AM +0100, Paolo Bonzini wrote:
> 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 anymore;
> it was not necessary because that should have resulted in a failed import in
> the first place.
>
> Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
Reviewed-by: Caio Carrara <ccarrara at redhat.com>
> ---
> 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):
>
> def get_mbox_with_tags(m):
> mbox = m.get_mbox()
> - try:
> - msg = email.message_from_string(mbox)
> - except Exception:
> - return mbox
> + msg = email.message_from_string(mbox)
> container = msg.get_payload(0) if msg.is_multipart() else msg
> if container.get_content_type() != "text/plain":
> - return mbox
> + return msg.as_bytes(unixfrom=True)
>
> payload = decode_payload(container)
> container.set_payload('\n'.join(mbox_with_tags_iter(payload, m.tags)))
> - return msg.as_string()
> + return msg.as_bytes(unixfrom=True)
>
> s = api.models.Message.objects.find_message(message_id, project)
> if not s:
> @@ -310,14 +307,8 @@ def view_mbox(request, project, message_id):
>
> mbox_list = []
> 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 = "\n".join(mbox_list)
> + mbox_list.append(get_mbox_with_tags(message))
> + mbox = b"\n".join(mbox_list)
> return HttpResponse(mbox, content_type="text/plain")
>
>
> --
> 2.19.1
>
>
> _______________________________________________
> Patchew-devel mailing list
> Patchew-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/patchew-devel
--
Caio Carrara
Software Engineer, Virt Team - Red Hat
ccarrara at redhat.com
More information about the Patchew-devel
mailing list