Compare commits
No commits in common. "f1a07cb1e0af372b11ebc5d756aa3a22a1e1ddac" and "6590baafd19ae3ff422dc6d4daede19d60f32d0c" have entirely different histories.
f1a07cb1e0
...
6590baafd1
1 changed files with 8 additions and 22 deletions
30
gpgmymail
30
gpgmymail
|
@ -60,7 +60,6 @@ def decode_email(message: email.message.Message) -> email.message.Message:
|
||||||
# this is a kinda hacky way to do this by manipulating the message as a
|
# this is a kinda hacky way to do this by manipulating the message as a
|
||||||
# string but i couldn't get it to work any other way
|
# string but i couldn't get it to work any other way
|
||||||
# decoding needed:
|
# decoding needed:
|
||||||
# as_string() gives us str, encode() gives us bytes
|
|
||||||
decoded_bytes = message.as_bytes()
|
decoded_bytes = message.as_bytes()
|
||||||
decoded_bytes = quopri.decodestring(decoded_bytes)
|
decoded_bytes = quopri.decodestring(decoded_bytes)
|
||||||
|
|
||||||
|
@ -79,26 +78,15 @@ def decode_email(message: email.message.Message) -> email.message.Message:
|
||||||
# lol
|
# 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
|
|
||||||
for part in quopri_decoded_message.walk():
|
for part in quopri_decoded_message.walk():
|
||||||
# multipart and has boundary (not None)
|
if not part.is_multipart():
|
||||||
if part.is_multipart() and part.get_boundary():
|
|
||||||
most_recent_boundary = part.get_boundary()
|
|
||||||
else:
|
|
||||||
if part.get("Content-Transfer-Encoding") == "base64":
|
if part.get("Content-Transfer-Encoding") == "base64":
|
||||||
b64_str = part.get_payload()
|
new_part = part
|
||||||
# remove the boundary as we don't want to change this
|
new_part.replace_header("Content-Transfer-Encoding", "7bit")
|
||||||
b64_str = b64_str.replace(most_recent_boundary, "")
|
new_part.set_payload(part.get_payload(decode=True))
|
||||||
# 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,
|
part.as_bytes(),
|
||||||
decoded_b64_str
|
new_part.as_bytes()
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# TODO
|
# TODO
|
||||||
|
@ -108,10 +96,8 @@ def decode_email(message: email.message.Message) -> email.message.Message:
|
||||||
b'Content-Transfer-Encoding: base64',
|
b'Content-Transfer-Encoding: base64',
|
||||||
b'Content-Transfer-Encoding: 7bit'
|
b'Content-Transfer-Encoding: 7bit'
|
||||||
)
|
)
|
||||||
|
|
||||||
# if i do message_from_bytes it bizarrely changes it back to base64?
|
return email.message_from_bytes(decoded_bytes)
|
||||||
# utf-8 has encoding issues so do latin1
|
|
||||||
return email.message_from_string(decoded_bytes.decode("latin1"))
|
|
||||||
|
|
||||||
def encrypt(
|
def encrypt(
|
||||||
message: email.message.Message,
|
message: email.message.Message,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue