Skip to content

Commit

Permalink
Improve the workaround of https://bugs.python.org/issue27321 in coddi…
Browse files Browse the repository at this point in the history
  • Loading branch information
ses4j committed Feb 26, 2019
1 parent 26786a0 commit cdda047
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions django_mailbox/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit cdda047

Please sign in to comment.