Accidentally applied the wrong stash, OOPS

This commit is contained in:
askiiart 2024-02-29 10:22:33 -06:00
parent 6acf3b0f3e
commit 803eaad493
Signed by untrusted user who does not match committer: askiiart
GPG key ID: BC3800E55FB54D67
2 changed files with 24 additions and 21 deletions

View file

@ -33,10 +33,11 @@ Or to add it in the GUI:
With a filtering rule, Claws Mail will only run gpg-email-helper when it receives a new email (that contains a signature). To run it on all emails instead, you can add the rule to pre/post-processing instead, but can take upwards of a minute to load every time you open your inbox, can cause the POP3/IMAP connection to time out, and often just crashes Claws Mail. Instead, I'd just just running it manually if you want to import public keys from all your old emails. With a filtering rule, Claws Mail will only run gpg-email-helper when it receives a new email (that contains a signature). To run it on all emails instead, you can add the rule to pre/post-processing instead, but can take upwards of a minute to load every time you open your inbox, can cause the POP3/IMAP connection to time out, and often just crashes Claws Mail. Instead, I'd just just running it manually if you want to import public keys from all your old emails.
In bash, run this to run gpg-email-helper on all files with a signature: Run this to run gpg-email-helper on all files with a signature:
```bash ```sh
for item in $(ls $HOME/Mail/inbox/); do if [ $(grep -c -- "-----BEGIN PGP SIGNATURE-----" $HOME/Mail/inbox/$item) != 0 ]; then python3 {SCRIPT LOCATION}/gpg-email-helper.py $HOME/Mail/inbox/$item; fi; done bash -c 'for item in $(ls $HOME/Mail/inbox/); do if [ $(grep -c -- "-----BEGIN PGP SIGNATURE-----" $HOME/Mail/inbox/$item) !=
0 ]; then python3 ~/gpg-email-helper/gpg-email-helper.py $HOME/Mail/inbox/$item; fi; done'
``` ```
## Todo ## Todo

View file

@ -3,26 +3,29 @@ import hkp4py
import os import os
import sys import sys
import asyncio import asyncio
import subprocess
async def get_pubkey(server, fingerprint, log):
def do_hkp_stuff(server, fingerprint, log):
# 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.
#return hkp4py.KeyServer(f'hkp://{server}').search(f'0x{fingerprint}') try:
results = await subprocess.getstatusoutput(f'gpg --keyserver {server} --recv-key {fingerprint}') pubkey = hkp4py.KeyServer(f'hkp://{server}').search(f'0x{fingerprint}')
log.write(f'{server}: {results}\n') log.write(f'{server}: {pubkey}\n')
print(f'{server}: {results}') if pubkey != None:
return results import_result = gpg.Context().key_import(pubkey[0].key.encode())
log.write(f'Attempted to import from {server}: {import_result}\n')
else:
log.write(f'{server}: None\n')
except Exception as e:
log.write(f'{server}: [ERROR] {e}\n\n')
def get_first_real_result(results): def get_first_real_result(results):
for s in results: for s in results:
s = list(s) s = list(s)
for task in s: for task in s:
try: if task != None:
return task.result() return task.result()
except asyncio.exceptions.InvalidStateError:
pass
return None return None
@ -110,17 +113,16 @@ async def main(log):
#'pgp.mit.edu' # still in operation but very unreliable #'pgp.mit.edu' # still in operation but very unreliable
] ]
# multithreads it
# TODO: make it stop after a thread gets the key
tasks = [ tasks = [
asyncio.create_task(get_pubkey(server, fingerprint, log)) asyncio.create_task(
asyncio.to_thread(do_hkp_stuff, server, fingerprint, log)
)
for server in keyservers for server in keyservers
] ]
#tasks = set(tasks) tasks = set(tasks)
results = await asyncio.gather(tasks) await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
print(1)
print(get_first_real_result(results))
print(3)
print(get_first_real_result(results))
except Exception as e: except Exception as e:
log.write(f'[ERROR] {e}\n\n') log.write(f'[ERROR] {e}\n\n')