email.message_from_string can also throw KeyError when 'content-transfer-encoding' is absent

This commit is contained in:
Son NK 2020-11-10 17:26:24 +01:00
parent 632a5bbbc8
commit 4666d21f63
1 changed files with 1 additions and 1 deletions

View File

@ -636,7 +636,7 @@ def copy(msg: Message) -> Message:
try: try:
# prefer the unicode way # prefer the unicode way
return email.message_from_string(msg.as_string()) return email.message_from_string(msg.as_string())
except UnicodeEncodeError: except (UnicodeEncodeError, ValueError):
LOG.warning("as_string() fails, try to_bytes") LOG.warning("as_string() fails, try to_bytes")
return email.message_from_bytes(to_bytes(msg)) return email.message_from_bytes(to_bytes(msg))