7or8bit-decode #5
1 changed files with 14 additions and 9 deletions
23
gpgmymail
23
gpgmymail
|
@ -71,6 +71,13 @@ def decode_email(message: email.message.Message) -> email.message.Message:
|
||||||
b'Content-Transfer-Encoding: 7bit'
|
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(
|
def decode_b64_part(
|
||||||
part: email.message.Message,
|
part: email.message.Message,
|
||||||
decoded_bytes: bytes,
|
decoded_bytes: bytes,
|
||||||
|
@ -79,7 +86,8 @@ def decode_email(message: email.message.Message) -> email.message.Message:
|
||||||
if part.get("Content-Transfer-Encoding") == "base64":
|
if part.get("Content-Transfer-Encoding") == "base64":
|
||||||
b64_str = part.get_payload()
|
b64_str = part.get_payload()
|
||||||
# remove the boundary as we don't want to change this
|
# 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:
|
# sometimes we have leftover hyphens from a boundary, so strip:
|
||||||
# hyphens not in base64 so we know not to use them
|
# hyphens not in base64 so we know not to use them
|
||||||
# strip whitespace first
|
# strip whitespace first
|
||||||
|
@ -94,12 +102,6 @@ def decode_email(message: email.message.Message) -> email.message.Message:
|
||||||
decoded_b64_str
|
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)
|
quopri_decoded_message = email.message_from_bytes(decoded_bytes)
|
||||||
if quopri_decoded_message.is_multipart():
|
if quopri_decoded_message.is_multipart():
|
||||||
most_recent_boundary = None
|
most_recent_boundary = None
|
||||||
|
@ -114,8 +116,11 @@ def decode_email(message: email.message.Message) -> email.message.Message:
|
||||||
most_recent_boundary
|
most_recent_boundary
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# TODO
|
decoded_bytes = decode_b64_part(
|
||||||
pass
|
quopri_decoded_message,
|
||||||
|
decoded_bytes,
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
decoded_bytes = decoded_bytes.replace(
|
decoded_bytes = decoded_bytes.replace(
|
||||||
b'Content-Transfer-Encoding: base64',
|
b'Content-Transfer-Encoding: base64',
|
||||||
|
|
Loading…
Reference in a new issue