strip trailing hyphens from base64
This commit is contained in:
parent
10f25158bf
commit
f559fef2ed
1 changed files with 7 additions and 2 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue