Use as_bytes() instead of as_string() to generate mbox
authorMagnus Hagander <magnus@hagander.net>
Fri, 15 Jul 2022 19:04:03 +0000 (21:04 +0200)
committerMagnus Hagander <magnus@hagander.net>
Fri, 15 Jul 2022 19:04:03 +0000 (21:04 +0200)
We're supposed to feed django bytes, and by feeding it a string it got
converted bytes->string by the mail end and then string->bytes by
django. Which promptly blew up on bad encodings. By keeping it as bytes
all the way, the problem is ignored.

django/archives/mailarchives/views.py

index 41c9fa5842936bf1eebfe456c553ae361d76e95e..f408243a374d8bc5242e9d471558e51cc1131892 100644 (file)
@@ -587,7 +587,7 @@ def _build_mbox(query, params, msgid=None):
         s = BytesIO(raw)
         parser = email.parser.BytesParser(policy=email.policy.compat32)
         msg = parser.parse(s)
-        return msg.as_string(unixfrom=True)
+        return msg.as_bytes(unixfrom=True)
 
     def _message_stream(first):
         yield _one_message(first[1])