From 4670bcdafd1ed6e0da0b1e16c44d0809bc78ef77 Mon Sep 17 00:00:00 2001 From: revsuine Date: Fri, 15 Nov 2024 14:36:54 +0000 Subject: [PATCH] wrap some things in try/except blocks --- gpgmymail | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gpgmymail b/gpgmymail index c75b4f2..f9a5473 100755 --- a/gpgmymail +++ b/gpgmymail @@ -72,7 +72,12 @@ 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 # string but i couldn't get it to work any other way - decoded_bytes = message.as_bytes() + + # sometimes this raises an exception and idk why + try: + decoded_bytes = message.as_bytes() + except UnicodeEncodeError: + decoded_bytes = message.as_string().encode() # if email doesn't need decoding has_quopri = b'Content-Transfer-Encoding: quoted-printable' in decoded_bytes has_base64 = b'Content-Transfer-Encoding: base64' in decoded_bytes @@ -189,7 +194,12 @@ def encrypt( return message.as_string() # make necessary changes to message - message = decode_email(message) + # this function is quite clunky and seems to throw exceptions from time to + # time; if we can't make the necessary changes we want to just continue + try: + message = decode_email(message) + except: + pass gpg = gnupg.GPG() gpg.encoding = encoding