diff --git a/gpgmymail b/gpgmymail index b2f539f..4d78d91 100755 --- a/gpgmymail +++ b/gpgmymail @@ -71,6 +71,13 @@ def decode_email(message: email.message.Message) -> email.message.Message: b'Content-Transfer-Encoding: 7bit' ) + # REALLY hacky but i had issues with the more sensible ways to do this. + # iterates through a Message object to find CTEs of base64 + # gets the b64 payload and the decoded payload + # then find and replaces in decoded_bytes the b64 payload + # with the decoded payload + # lol + def decode_b64_part( part: email.message.Message, decoded_bytes: bytes, @@ -79,7 +86,8 @@ def decode_email(message: email.message.Message) -> email.message.Message: if part.get("Content-Transfer-Encoding") == "base64": b64_str = part.get_payload() # remove the boundary as we don't want to change this - b64_str = b64_str.replace(most_recent_boundary, "") + if most_recent_boundary: + b64_str = b64_str.replace(most_recent_boundary, "") # sometimes we have leftover hyphens from a boundary, so strip: # hyphens not in base64 so we know not to use them # strip whitespace first @@ -94,12 +102,6 @@ def decode_email(message: email.message.Message) -> email.message.Message: decoded_b64_str ) - # REALLY hacky but i had issues with the more sensible ways to do this. - # iterates through a Message object to find CTEs of base64 - # gets the b64 payload and the decoded payload - # then find and replaces in decoded_bytes the b64 payload - # with the decoded payload - # lol quopri_decoded_message = email.message_from_bytes(decoded_bytes) if quopri_decoded_message.is_multipart(): most_recent_boundary = None @@ -114,8 +116,11 @@ def decode_email(message: email.message.Message) -> email.message.Message: most_recent_boundary ) else: - # TODO - pass + decoded_bytes = decode_b64_part( + quopri_decoded_message, + decoded_bytes, + None + ) decoded_bytes = decoded_bytes.replace( b'Content-Transfer-Encoding: base64',