handle UnicodeDecodeError in replace()
This commit is contained in:
parent
e62c5d1591
commit
2691fff217
|
@ -967,7 +967,11 @@ def replace(msg: Message, old, new) -> Message:
|
||||||
if encoding == EmailEncoding.QUOTED:
|
if encoding == EmailEncoding.QUOTED:
|
||||||
LOG.d("handle quoted-printable replace %s -> %s", old, new)
|
LOG.d("handle quoted-printable replace %s -> %s", old, new)
|
||||||
# first decode the payload
|
# first decode the payload
|
||||||
new_payload = quopri.decodestring(payload).decode("utf-8")
|
try:
|
||||||
|
new_payload = quopri.decodestring(payload).decode("utf-8")
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
LOG.w("cannot decode payload:%s", payload)
|
||||||
|
return msg
|
||||||
# then replace the old text
|
# then replace the old text
|
||||||
new_payload = new_payload.replace(old, new)
|
new_payload = new_payload.replace(old, new)
|
||||||
clone_msg = copy(msg)
|
clone_msg = copy(msg)
|
||||||
|
|
Loading…
Reference in New Issue