From cdda047f9f2472ca2836d6674214c0b19035c71e Mon Sep 17 00:00:00 2001 From: Scott Stafford Date: Mon, 25 Feb 2019 22:02:14 -0500 Subject: [PATCH] Improve the workaround of https://bugs.python.org/issue27321 in coddingtonbear#136. Attempt to use patch from https://bugs.python.org/msg308362. --- django_mailbox/models.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/django_mailbox/models.py b/django_mailbox/models.py index 9f7ffc21..122f8dd5 100644 --- a/django_mailbox/models.py +++ b/django_mailbox/models.py @@ -372,8 +372,13 @@ def _process_message(self, message): except KeyError as exc: # email.message.replace_header may raise 'KeyError' if the header # 'content-transfer-encoding' is missing - logger.warning("Failed to parse message: %s", exc,) - return None + try: + # Before we give up, let's try mailman's approach: + # https://bugs.python.org/msg308362 + body = message.as_bytes(self).decode('ascii', 'replace') + except KeyError as exc: + logger.warning("Failed to parse message: %s", exc,) + return None msg.set_body(body) if message['in-reply-to']: try: