summaryrefslogtreecommitdiff
path: root/alot/settings/checks.py
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-05-13 11:41:56 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2012-05-13 11:41:56 +0100
commit05812e255b0f40c4693114e26e1e57a4e3b8d5fc (patch)
tree05eb0d73d2e040f3c23c84323103f2f76344e7e2 /alot/settings/checks.py
parent8d12c4751d310d7b79bbda6f34c68ef0029873db (diff)
verify accounts gpg_key upon startup
This introduces a custom config check that tests if the given gpg_key value points to a valid private key. If so, the property Account.gpg_key is a pyme.pygpgme._gpgme_key object.
Diffstat (limited to 'alot/settings/checks.py')
-rw-r--r--alot/settings/checks.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/alot/settings/checks.py b/alot/settings/checks.py
index 4943daa3..ff1ad3a8 100644
--- a/alot/settings/checks.py
+++ b/alot/settings/checks.py
@@ -2,6 +2,10 @@ import mailbox
import re
from urlparse import urlparse
from validate import VdtTypeError
+from validate import ValidateError
+
+from alot import crypto
+from alot.errors import GPGProblem
def mail_container(value):
@@ -21,3 +25,17 @@ def mail_container(value):
else:
raise VdtTypeError(value)
return box
+
+
+def gpg_key(value):
+ """
+ test if value points to a known gpg key
+ and return that key as :class:`pyme.pygpgme._gpgme_key`.
+ """
+ try:
+ key = crypto.CryptoContext().get_key(value)
+ if key == None:
+ raise ValidateError('No key found for hint %s' % value)
+ return key
+ except GPGProblem, e:
+ raise ValidateError(e.message)