failover when ascii encoding fails
This commit is contained in:
parent
44c3ac1741
commit
b2f9479bce
|
@ -622,7 +622,11 @@ def parseaddr_unicode(addr) -> (str, str):
|
||||||
|
|
||||||
def copy(msg: Message) -> Message:
|
def copy(msg: Message) -> Message:
|
||||||
"""return a copy of message"""
|
"""return a copy of message"""
|
||||||
|
try:
|
||||||
return email.message_from_bytes(to_bytes(msg))
|
return email.message_from_bytes(to_bytes(msg))
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
LOG.warning("to_bytes() fails, try string")
|
||||||
|
return email.message_from_string(msg.as_string())
|
||||||
|
|
||||||
|
|
||||||
def to_bytes(msg: Message):
|
def to_bytes(msg: Message):
|
||||||
|
|
Loading…
Reference in a new issue