From 756e8080ab3a369303766d662b5be799773a88ef Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sun, 1 Nov 2020 18:38:21 +0100 Subject: [PATCH] handle case msg.get_payload(decode=True) is None --- email_handler.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/email_handler.py b/email_handler.py index 2b50e32d..e260a935 100644 --- a/email_handler.py +++ b/email_handler.py @@ -338,7 +338,12 @@ def replace_header_when_reply(msg: Message, alias: Alias, header: str): def replace_str_in_msg(msg: Message, fr: str, to: str): if msg.get_content_maintype() != "text": return msg - new_body = msg.get_payload(decode=True).replace(fr.encode(), to.encode()) + + msg_payload = msg.get_payload(decode=True) + if not msg_payload: + return msg + + new_body = msg_payload.replace(fr.encode(), to.encode()) # If utf-8 decoding fails, do not touch message part try: