From ed57c8f0d46a4369d9bf30dc7c711e45fd7d57a8 Mon Sep 17 00:00:00 2001 From: revsuine Date: Wed, 13 Nov 2024 17:22:21 +0000 Subject: [PATCH] first attempt to implement decoding as 7or8bit (non-working) --- gpgmymail | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gpgmymail b/gpgmymail index a3c230f..8b51754 100755 --- a/gpgmymail +++ b/gpgmymail @@ -49,6 +49,23 @@ def is_message_encrypted(message: email.message.Message) -> bool: return message.get_content_subtype() == "encrypted" +def decode_email(message: email.message.Message) -> email.message.Message: + """Turn a quoted-printable or base64 encoded email into a 7or8bit encoded + email + + :param message: email.message.Message to be decoded + :return: decoded email.message.Message""" + payload = [] + + for part in message.walk(): + if not part.is_multipart(): + payload.append(part.get_payload(decode=True)) + + message["Content-Transfer-Encoding"] = "7bit" + message.set_payload(payload) + + return message + def encrypt( message: email.message.Message, recipients: typing.List[str], @@ -67,10 +84,14 @@ def encrypt( :return: The encrypted email as a string""" + # exclusion criteria: # some mail clients like Thunderbird don't like twice-encrypted emails, # so we return the message as-is if it's already encrypted if is_message_encrypted(message) and not unconditionally_encrypt: return message.as_string() + + # make necessary changes to message + message = decode_email(message) gpg = gnupg.GPG() gpg.encoding = encoding