summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-07-18 11:21:19 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-07-19 11:35:09 -0700
commit2504de648dd6413625387924baaca126eac68016 (patch)
treeca10f3cb0c5cf2a2d7ce034f25c73f25a801e600 /alot
parent3995747c4efed39a74e75b5c11061574bc1e8cd8 (diff)
commands/envelope: Fall back to account for signing key
If there isn't a key provided as an argument to sign or togglesign, fall back to using the account of the sending address to determine the key, otherwise the message will be marked as "to sign", but won't actually be signed. This is the same type of logic used for sign_by_default.
Diffstat (limited to 'alot')
-rw-r--r--alot/commands/envelope.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py
index a2945fbe..0e479f87 100644
--- a/alot/commands/envelope.py
+++ b/alot/commands/envelope.py
@@ -472,7 +472,6 @@ class SignCommand(Command):
def apply(self, ui):
sign = None
- key = None
envelope = ui.current_buffer.envelope
# sign status
if self.action == 'sign':
@@ -483,17 +482,31 @@ class SignCommand(Command):
sign = not envelope.sign
envelope.sign = sign
- # try to find key if hint given as parameter
if sign:
- if len(self.keyid) > 0:
+ if self.keyid:
+ # try to find key if hint given as parameter
keyid = str(' '.join(self.keyid))
try:
- key = crypto.get_key(keyid, validate=True, sign=True)
+ envelope.sign_key = crypto.get_key(keyid, validate=True,
+ sign=True)
except GPGProblem as e:
envelope.sign = False
ui.notify(e.message, priority='error')
return
- envelope.sign_key = key
+ else:
+ _, addr = email.utils.parseaddr(envelope.headers['From'][0])
+ acc = settings.get_account_by_address(addr)
+ if not acc:
+ envelope.sign = False
+ ui.notify('Unable to find a matching account',
+ priority='error')
+ return
+ elif not acc.gpg_key:
+ envelope.sign = False
+ ui.notify('Account for {} has no gpg key'.format(acc.address),
+ priority='error')
+ return
+ envelope.sign_key = acc.gpg_key
else:
envelope.sign_key = None