1
0
Fork 1
mirror of https://github.com/coddingtonbear/django-mailbox.git synced 2026-07-09 22:38:19 +02:00

Set email payload's charset after all other headers.

This commit is contained in:
Adam Coddington 2013-07-26 17:40:44 -07:00
parent 2e6c23a6f0
commit 98745bcd70

View file

@ -488,13 +488,20 @@ class Message(models.Model):
new.set_payload('')
else:
payload = msg.get_payload().decode('utf-8')
charset = None
for header, value in msg.items():
if header == ORIGINAL_CHARSET_HEADER:
payload.encode(value)
new.set_charset(value)
# We do not want to preserve this header
charset = value
# We do not want to preserve this header.
continue
new[header] = value
if charset:
# If we process ORIGINAL_CHARSET_HEADER before other headers
# (in the above), due to some idiosyncrasies of python's email
# module, we'll end up with duplicated headers -- set_charset
# sets a handful of headers if they do not already exist.
new.set_charset(charset)
new.set_payload(payload)
return new