strip trailing hyphens from base64

This commit is contained in:
revsuine 2024-11-14 19:15:37 +00:00
parent 10f25158bf
commit f559fef2ed
Signed by: revsuine
GPG key ID: 3F257B68F5BC9339

View file

@ -36,7 +36,6 @@ import email.mime.message
import typing
# for decode_email:
import quopri
import base64
# see: https://gnupg.readthedocs.io/en/latest/
import gnupg
@ -90,7 +89,13 @@ def decode_email(message: email.message.Message) -> email.message.Message:
b64_str = part.get_payload()
# remove the boundary as we don't want to change this
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(
b64_str,
decoded_b64_str