try do this by replacing entire payload

This commit is contained in:
revsuine 2024-11-14 18:55:06 +00:00
parent b213a0ab52
commit 6590baafd1
Signed by: revsuine
GPG key ID: 3F257B68F5BC9339

View file

@ -60,8 +60,7 @@ def decode_email(message: email.message.Message) -> email.message.Message:
# this is a kinda hacky way to do this by manipulating the message as a # 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 # string but i couldn't get it to work any other way
# decoding needed: # decoding needed:
# as_string() gives us str, encode() gives us bytes decoded_bytes = message.as_bytes()
decoded_bytes = message.as_string().encode()
decoded_bytes = quopri.decodestring(decoded_bytes) decoded_bytes = quopri.decodestring(decoded_bytes)
# replace any instances of the Content-Transfer-Encoding header # replace any instances of the Content-Transfer-Encoding header
@ -82,11 +81,12 @@ def decode_email(message: email.message.Message) -> email.message.Message:
for part in quopri_decoded_message.walk(): for part in quopri_decoded_message.walk():
if not part.is_multipart(): if not part.is_multipart():
if part.get("Content-Transfer-Encoding") == "base64": if part.get("Content-Transfer-Encoding") == "base64":
b64_str = part.get_payload().encode() new_part = part
decoded_b64_str = part.get_payload(decode=True) new_part.replace_header("Content-Transfer-Encoding", "7bit")
new_part.set_payload(part.get_payload(decode=True))
decoded_bytes = decoded_bytes.replace( decoded_bytes = decoded_bytes.replace(
b64_str, part.as_bytes(),
decoded_b64_str new_part.as_bytes()
) )
else: else:
# TODO # TODO