email mirror: use a message part's specific charset rather than the message charset.

The overall message charset may be null or not match the part's
charset. Even though it's unclear from the documentation,
experimentally using the charset for a message part seems to give you
the charset even for non-multipart emails.

(imported from commit 0e1d23073f4c53041f9760e66a6635f8a94893d1)
This commit is contained in:
Jessica McKellar 2013-09-23 10:25:59 -04:00 committed by Zev Benjamin
parent 7bb75e3acb
commit d434bf4bb4

View File

@ -132,13 +132,13 @@ def valid_stream(stream_name, token):
return False
def get_message_part_by_type(message, content_type):
charset = message.get_content_charset()
charsets = message.get_charsets()
for part in message.walk():
for idx, part in enumerate(message.walk()):
if part.get_content_type() == content_type:
content = part.get_payload(decode=True)
if charset:
content = content.decode(charset)
if charsets[idx]:
content = content.decode(charsets[idx])
return content
def extract_body(message):