email.message_from_string can also throw LookupError when non-existent charset is set

This commit is contained in:
Son NK 2020-11-13 18:08:56 +01:00
parent b4e5e3eecb
commit f16676e921
1 changed files with 1 additions and 1 deletions

View File

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