implement really hacky way of decoding b64 parts
This commit is contained in:
parent
a21ee759c8
commit
82c5144e58
1 changed files with 25 additions and 2 deletions
27
gpgmymail
27
gpgmymail
|
@ -65,13 +65,36 @@ def decode_email(message: email.message.Message) -> email.message.Message:
|
||||||
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
|
||||||
|
# quopri version, we do base64 version down there
|
||||||
decoded_bytes = decoded_bytes.replace(
|
decoded_bytes = decoded_bytes.replace(
|
||||||
b'Content-Transfer-Encoding: quoted-printable',
|
b'Content-Transfer-Encoding: quoted-printable',
|
||||||
b'Content-Transfer-Encoding: 7bit'
|
b'Content-Transfer-Encoding: 7bit'
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: base64 decoding, which is more difficult due to the need to not
|
# REALLY hacky but i had issues with the more sensible ways to do this.
|
||||||
# treat the whole email like it's base64
|
# 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():
|
||||||
|
for part in quopri_decoded_message.walk():
|
||||||
|
if not part.is_multipart():
|
||||||
|
if part.get("Content-Transfer-Encoding") == "base64":
|
||||||
|
b64_str = part.get_payload()
|
||||||
|
decoded_b64_str = part.get_payload(decode=True)
|
||||||
|
decoded_bytes = decoded_bytes.replace(
|
||||||
|
b64_str,
|
||||||
|
decoded_b64_str
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
decoded_bytes = decoded_bytes.replace(
|
||||||
|
b'Content-Transfer-Encoding: base64',
|
||||||
|
b'Content-Transfer-Encoding: 7bit'
|
||||||
|
)
|
||||||
|
|
||||||
return email.message_from_bytes(decoded_bytes)
|
return email.message_from_bytes(decoded_bytes)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue