From a21ee759c87e4419ec0bb34f5d05af8f482ee953 Mon Sep 17 00:00:00 2001 From: revsuine Date: Thu, 14 Nov 2024 18:26:22 +0000 Subject: [PATCH] temp remove base64 decoding and unconditionally quopri decode --- gpgmymail | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/gpgmymail b/gpgmymail index 0164660..d7575d9 100755 --- a/gpgmymail +++ b/gpgmymail @@ -36,14 +36,12 @@ import email.mime.message import typing # for decode_email: import quopri -import base64 # see: https://gnupg.readthedocs.io/en/latest/ import gnupg # constants DEFAULT_ENCODING='utf-8' # default is latin-1 which fails w some unicode chars -CTES_TO_BE_DECODED = ("quoted-printable", "base64") def is_message_encrypted(message: email.message.Message) -> bool: """Determines whether or not an email message is encrypted. @@ -61,39 +59,19 @@ def decode_email(message: email.message.Message) -> email.message.Message: :return: decoded email.message.Message""" # this is a kinda hacky way to do this by manipulating the message as a # string but i couldn't get it to work any other way - - msg_ctes = message.get_all("Content-Transfer-Encoding") - - # this list will be populated with any encoding that needs to be decoded, - # e.g. base64 - # empty if no decoding needed - # set used to avoid dupes - decodes_needed = set() - # check if any of the parts of the message need decoding - for cte in CTES_TO_BE_DECODED: - if cte in msg_ctes: - decodes_needed.add(cte) - # no decoding needed, go ahead with message - if not decodes_needed: - return message - # decoding needed: # as_string() gives us str, encode() gives us bytes decoded_bytes = message.as_string().encode() - if "quoted-printable" in decodes_needed: - decoded_bytes = quopri.decodestring(decoded_bytes) - if "base64" in decodes_needed: - decoded_bytes = base64.b64decode(decoded_bytes) + decoded_bytes = quopri.decodestring(decoded_bytes) # replace any instances of the Content-Transfer-Encoding header decoded_bytes = decoded_bytes.replace( b'Content-Transfer-Encoding: quoted-printable', b'Content-Transfer-Encoding: 7bit' ) - decoded_bytes = decoded_bytes.replace( - b'Content-Transfer-Encoding: base64', - b'Content-Transfer-Encoding: 7bit' - ) + + # TODO: base64 decoding, which is more difficult due to the need to not + # treat the whole email like it's base64 return email.message_from_bytes(decoded_bytes)