7or8bit-decode #5

Manually merged
revsuine merged 17 commits from 7or8bit-decode into master 2024-11-14 19:45:52 +00:00
Showing only changes of commit 633a54e2b1 - Show all commits

View file

@ -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,6 +86,7 @@ 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
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
@ -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',