wrap some things in try/except blocks
This commit is contained in:
parent
272842162d
commit
4670bcdafd
1 changed files with 12 additions and 2 deletions
14
gpgmymail
14
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
|
# 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
|
||||||
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
|
# if email doesn't need decoding
|
||||||
has_quopri = b'Content-Transfer-Encoding: quoted-printable' in decoded_bytes
|
has_quopri = b'Content-Transfer-Encoding: quoted-printable' in decoded_bytes
|
||||||
has_base64 = b'Content-Transfer-Encoding: base64' in decoded_bytes
|
has_base64 = b'Content-Transfer-Encoding: base64' in decoded_bytes
|
||||||
|
@ -189,7 +194,12 @@ def encrypt(
|
||||||
return message.as_string()
|
return message.as_string()
|
||||||
|
|
||||||
# make necessary changes to message
|
# 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 = gnupg.GPG()
|
||||||
gpg.encoding = encoding
|
gpg.encoding = encoding
|
||||||
|
|
Loading…
Reference in a new issue