handle UnicodeDecodeError in replace()

This commit is contained in:
Son 2021-11-01 10:11:36 +01:00
parent e62c5d1591
commit 2691fff217
1 changed files with 5 additions and 1 deletions

View File

@ -967,7 +967,11 @@ def replace(msg: Message, old, new) -> Message:
if encoding == EmailEncoding.QUOTED:
LOG.d("handle quoted-printable replace %s -> %s", old, new)
# 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
new_payload = new_payload.replace(old, new)
clone_msg = copy(msg)