From f895e87ec03e30913b04794f5d51ef2e0387e27b Mon Sep 17 00:00:00 2001 From: revsuine Date: Thu, 14 Nov 2024 15:19:57 +0000 Subject: [PATCH] account for non-multipart emails --- gpgmymail | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gpgmymail b/gpgmymail index 8b51754..21c46e6 100755 --- a/gpgmymail +++ b/gpgmymail @@ -55,14 +55,17 @@ def decode_email(message: email.message.Message) -> email.message.Message: :param message: email.message.Message to be decoded :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(): - if not part.is_multipart(): - payload.append(part.get_payload(decode=True)) + message.set_payload(payload) + else: + message.set_payload(message.get_payload(decode=True)) message["Content-Transfer-Encoding"] = "7bit" - message.set_payload(payload) return message