summaryrefslogtreecommitdiff
path: root/alot/commands/utils.py
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2015-04-25 02:56:36 +0200
committerPatrick Totzke <patricktotzke@gmail.com>2015-12-16 15:59:37 +0000
commitc2b7c6dc9a21a08866c08ff3cd852c7c4a497032 (patch)
tree2d61d083bb9dded42277c201ed0a87eda3fc1805 /alot/commands/utils.py
parent811dd7be873cbde3268755b46da69a6829732cca (diff)
Encrypt on reply to encrypted email and add 'encrypt_by_default' config
Diffstat (limited to 'alot/commands/utils.py')
-rw-r--r--alot/commands/utils.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/alot/commands/utils.py b/alot/commands/utils.py
new file mode 100644
index 00000000..a6290671
--- /dev/null
+++ b/alot/commands/utils.py
@@ -0,0 +1,32 @@
+# Copyright (C) 2015 Patrick Totzke <patricktotzke@gmail.com>
+# This file is released under the GNU GPL, version 3 or a later revision.
+# For further details see the COPYING file
+from twisted.internet.defer import inlineCallbacks, returnValue
+
+from alot.errors import GPGProblem, GPGCode
+from alot import crypto
+
+
+@inlineCallbacks
+def get_keys(ui, encrypt_keyids, block_error=False):
+ keys = {}
+ for keyid in encrypt_keyids:
+ try:
+ key = crypto.get_key(keyid, validate=True, encrypt=True)
+ except GPGProblem as e:
+ if e.code == GPGCode.AMBIGUOUS_NAME:
+ possible_keys = crypto.list_keys(hint=keyid)
+ tmp_choices = [k.uids[0].uid for k in possible_keys]
+ choices = {str(len(tmp_choices) - x): tmp_choices[x]
+ for x in range(0, len(tmp_choices))}
+ keyid = yield ui.choice("ambiguous keyid! Which " +
+ "key do you want to use?",
+ choices, cancel=None)
+ if keyid:
+ encrypt_keyids.append(keyid)
+ continue
+ else:
+ ui.notify(e.message, priority='error', block=block_error)
+ continue
+ keys[crypto.hash_key(key)] = key
+ returnValue(keys)