account for non-multipart emails

This commit is contained in:
revsuine 2024-11-14 15:19:57 +00:00
parent ed57c8f0d4
commit f895e87ec0
Signed by: revsuine
GPG key ID: 3F257B68F5BC9339

View file

@ -55,14 +55,17 @@ def decode_email(message: email.message.Message) -> email.message.Message:
:param message: email.message.Message to be decoded :param message: email.message.Message to be decoded
:return: decoded email.message.Message""" :return: decoded email.message.Message"""
payload = [] if message.is_multipart():
payload = []
for part in message.walk():
if not part.is_multipart():
payload.append(part.get_payload(decode=True))
for part in message.walk(): message.set_payload(payload)
if not part.is_multipart(): else:
payload.append(part.get_payload(decode=True)) message.set_payload(message.get_payload(decode=True))
message["Content-Transfer-Encoding"] = "7bit" message["Content-Transfer-Encoding"] = "7bit"
message.set_payload(payload)
return message return message