Last active
September 18, 2017 16:26
-
-
Save meskio/5e2f5946aaff53a2e79cb4df5651f695 to your computer and use it in GitHub Desktop.
alot attach keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[bindings] | |
[[envelope]] | |
G = call hooks.attach_my_key(ui) | |
'G G' = call hooks.attach_recipient_keys(ui) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from alot.settings.const import settings | |
from email.utils import parseaddr | |
from twisted.internet import defer | |
def attach_my_key(ui): | |
""" | |
Attach the senders openpgp public key | |
""" | |
frm = ui.current_buffer.envelope.get('From', "") | |
address = parseaddr(frm)[1] | |
acc = settings.get_account_by_address(address) | |
fpr = acc.gpg_key.fpr | |
return attach_key(ui, fpr, address) | |
def attach_recipient_keys(ui): | |
""" | |
Attach the openpgp public keys of all the recipients of the email | |
""" | |
to = ui.current_buffer.envelope.get('To', "") | |
cc = ui.current_buffer.envelope.get('Cc', "") | |
deferreds = [] | |
for recipient in to.split(',')+cc.split(','): | |
address = parseaddr(recipient)[1] | |
if address: | |
deferreds.append(attach_key(ui, address)) | |
return defer.gatherResults(deferreds) | |
def attach_key(ui, id, name=None): | |
""" | |
Export and attach openpgp key | |
""" | |
if not name: | |
name = id | |
path = "/tmp/%s.asc" % name | |
subprocess.call('gpg -a --export ' + id + ' > ' + path, shell=True) | |
return ui.apply_commandline('attach ' + path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment