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 f559fef2ed - Show all commits

View file

@ -36,7 +36,6 @@ import email.mime.message
import typing import typing
# for decode_email: # for decode_email:
import quopri import quopri
import base64
# see: https://gnupg.readthedocs.io/en/latest/ # see: https://gnupg.readthedocs.io/en/latest/
import gnupg import gnupg
@ -90,7 +89,13 @@ def decode_email(message: email.message.Message) -> email.message.Message:
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, "") b64_str = b64_str.replace(most_recent_boundary, "")
decoded_b64_str = base64.b64decode(b64_str) # 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( decoded_bytes = decoded_bytes.replace(
b64_str, b64_str,
decoded_b64_str decoded_b64_str