mirror of
https://github.com/zulip/zulip.git
synced 2026-07-12 21:04:41 +08:00
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:
parent
7bb75e3acb
commit
d434bf4bb4
@ -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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user