From f559fef2ed11e69f766e928bbc3a927135ea5eed Mon Sep 17 00:00:00 2001 From: revsuine Date: Thu, 14 Nov 2024 19:15:37 +0000 Subject: [PATCH] strip trailing hyphens from base64 --- gpgmymail | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gpgmymail b/gpgmymail index d5e3033..4329858 100755 --- a/gpgmymail +++ b/gpgmymail @@ -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