Compare commits
2 commits
f1a07cb1e0
...
633a54e2b1
Author | SHA1 | Date | |
---|---|---|---|
633a54e2b1 | |||
218ee51ac2 |
1 changed files with 35 additions and 17 deletions
50
gpgmymail
50
gpgmymail
|
@ -77,6 +77,31 @@ def decode_email(message: email.message.Message) -> email.message.Message:
|
||||||
# then find and replaces in decoded_bytes the b64 payload
|
# then find and replaces in decoded_bytes the b64 payload
|
||||||
# with the decoded payload
|
# with the decoded payload
|
||||||
# lol
|
# lol
|
||||||
|
|
||||||
|
def decode_b64_part(
|
||||||
|
part: email.message.Message,
|
||||||
|
decoded_bytes: bytes,
|
||||||
|
most_recent_boundary: str = None
|
||||||
|
) -> bytes:
|
||||||
|
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
|
||||||
|
# strip whitespace first
|
||||||
|
b64_str = b64_str.strip()
|
||||||
|
b64_str = b64_str.strip('-')
|
||||||
|
b64_str = b64_str.encode() # turn into bytes-like object
|
||||||
|
# this will also decode the boundary so there'll be some nonsese
|
||||||
|
# chars at end of email but it's nbd
|
||||||
|
decoded_b64_str = part.get_payload(decode=True)
|
||||||
|
return decoded_bytes.replace(
|
||||||
|
b64_str,
|
||||||
|
decoded_b64_str
|
||||||
|
)
|
||||||
|
|
||||||
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
|
||||||
|
@ -85,24 +110,17 @@ def decode_email(message: email.message.Message) -> email.message.Message:
|
||||||
if part.is_multipart() and part.get_boundary():
|
if part.is_multipart() and part.get_boundary():
|
||||||
most_recent_boundary = part.get_boundary()
|
most_recent_boundary = part.get_boundary()
|
||||||
else:
|
else:
|
||||||
if part.get("Content-Transfer-Encoding") == "base64":
|
decoded_bytes = decode_b64_part(
|
||||||
b64_str = part.get_payload()
|
part,
|
||||||
# remove the boundary as we don't want to change this
|
decoded_bytes,
|
||||||
b64_str = b64_str.replace(most_recent_boundary, "")
|
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
|
|
||||||
b64_str = b64_str.strip()
|
|
||||||
b64_str = b64_str.strip('-')
|
|
||||||
b64_str = b64_str.encode() # turn into bytes-like object
|
|
||||||
decoded_b64_str = part.get_payload(decode=True)
|
|
||||||
decoded_bytes = decoded_bytes.replace(
|
|
||||||
b64_str,
|
|
||||||
decoded_b64_str
|
|
||||||
)
|
)
|
||||||
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…
Add table
Add a link
Reference in a new issue