Fix quoted-printable signatures too
This commit is contained in:
parent
e605917d7e
commit
3eea7435ed
1 changed files with 23 additions and 9 deletions
|
@ -17,13 +17,21 @@ if 'gpg-email-helper' not in os.listdir(f'{XDG_DATA_HOME}'):
|
||||||
with open(f'{XDG_DATA_HOME}/gpg-email-helper/log', 'a') as log:
|
with open(f'{XDG_DATA_HOME}/gpg-email-helper/log', 'a') as log:
|
||||||
log.write(f'\n\nRunning on {filename}\n')
|
log.write(f'\n\nRunning on {filename}\n')
|
||||||
|
|
||||||
if email.rfind('-----BEGIN PGP PUBLIC KEY BLOCK-----') != -1 and email.rfind('-----END PGP PUBLIC KEY BLOCK-----') != -1:
|
if (
|
||||||
public_key = email[email.rfind(
|
email.rfind('-----BEGIN PGP PUBLIC KEY BLOCK-----') != -1
|
||||||
'-----BEGIN PGP PUBLIC KEY BLOCK-----'):email.rfind('-----END PGP PUBLIC KEY BLOCK-----')+35]
|
and email.rfind('-----END PGP PUBLIC KEY BLOCK-----') != -1
|
||||||
|
):
|
||||||
|
public_key = email[
|
||||||
|
email.rfind('-----BEGIN PGP PUBLIC KEY BLOCK-----') : email.rfind(
|
||||||
|
'-----END PGP PUBLIC KEY BLOCK-----'
|
||||||
|
)
|
||||||
|
+ 35
|
||||||
|
]
|
||||||
# quoted-printable attachments have the equals sign escaped as =3D apparently
|
# quoted-printable attachments have the equals sign escaped as =3D apparently
|
||||||
public_key = public_key.replace('=3D', '=')
|
public_key = public_key.replace('=3D', '=')
|
||||||
log.write(
|
log.write(
|
||||||
f'Attempted to import key from email: {gpg.Context(armor=True).key_import(public_key.encode())}\n')
|
f'Attempted to import key from email: {gpg.Context(armor=True).key_import(public_key.encode())}\n'
|
||||||
|
)
|
||||||
|
|
||||||
elif (
|
elif (
|
||||||
email.rfind('-----BEGIN PGP SIGNATURE-----') != -1
|
email.rfind('-----BEGIN PGP SIGNATURE-----') != -1
|
||||||
|
@ -32,8 +40,10 @@ with open(f'{XDG_DATA_HOME}/gpg-email-helper/log', 'a') as log:
|
||||||
signature = email[
|
signature = email[
|
||||||
email.rfind('-----BEGIN PGP SIGNATURE-----') : email.rfind(
|
email.rfind('-----BEGIN PGP SIGNATURE-----') : email.rfind(
|
||||||
'-----END PGP SIGNATURE-----'
|
'-----END PGP SIGNATURE-----'
|
||||||
)+27
|
)
|
||||||
|
+ 27
|
||||||
]
|
]
|
||||||
|
signature.replace('=3D', '=')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Needed to skip geting the key if it already exists.
|
# Needed to skip geting the key if it already exists.
|
||||||
|
@ -82,11 +92,15 @@ with open(f'{XDG_DATA_HOME}/gpg-email-helper/log', 'a') as log:
|
||||||
pubkey = hkp4py.KeyServer(
|
pubkey = hkp4py.KeyServer(
|
||||||
# This isn't perfect, it's a loose search
|
# This isn't perfect, it's a loose search
|
||||||
# for example searching for 7C79FCBB8372E5DE5B17E09A90D4B9641E092971 on keyserver.ubuntu.com returns the wrong key. But it works 99% of the time.
|
# for example searching for 7C79FCBB8372E5DE5B17E09A90D4B9641E092971 on keyserver.ubuntu.com returns the wrong key. But it works 99% of the time.
|
||||||
f'hkp://{server}').search(f'0x{fingerprint}')
|
f'hkp://{server}'
|
||||||
|
).search(f'0x{fingerprint}')
|
||||||
if pubkey != None:
|
if pubkey != None:
|
||||||
import_result = gpg.Context().key_import(pubkey[0].key.encode())
|
import_result = gpg.Context().key_import(
|
||||||
|
pubkey[0].key.encode()
|
||||||
|
)
|
||||||
log.write(
|
log.write(
|
||||||
f'Attempted to import from {server}: {import_result}\n')
|
f'Attempted to import from {server}: {import_result}\n'
|
||||||
|
)
|
||||||
if type(import_result) == gpg.results.ImportResult:
|
if type(import_result) == gpg.results.ImportResult:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue