summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-08-22 16:24:53 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-08-23 09:09:04 -0700
commit10a339e57ccdf49a95ded1f1a3961a1cfcd65dee (patch)
treedb391568f02e0c187f725447984c6038a3a250fe
parent67301a23a14c943714ae1fd7bf6b4e21156e6ef5 (diff)
db/utils: Don't mark signature valid if there is no key to verify
-rw-r--r--alot/db/utils.py13
-rw-r--r--tests/db/utils_test.py1
2 files changed, 7 insertions, 7 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py
index 488e0ed7..a91a8fae 100644
--- a/alot/db/utils.py
+++ b/alot/db/utils.py
@@ -45,6 +45,8 @@ def add_signature_headers(mail, sigs, error_msg):
string indicating no error
'''
sig_from = u''
+ sig_known = True
+ uid_trusted = False
if isinstance(error_msg, str):
error_msg = error_msg.decode('utf-8')
@@ -60,13 +62,11 @@ def add_signature_headers(mail, sigs, error_msg):
uid_trusted = True
break
else:
- # No trusted uid found, we did not break but drop from the
- # for loop.
- uid_trusted = False
+ # No trusted uid found, since we did not break from the loop.
sig_from = key.uids[0].uid.decode('utf-8')
- except:
+ except GPGProblem:
sig_from = sigs[0].fpr.decode('utf-8')
- uid_trusted = False
+ sig_known = False
if error_msg:
msg = u'Invalid: {}'.format(error_msg)
@@ -75,7 +75,8 @@ def add_signature_headers(mail, sigs, error_msg):
else:
msg = u'Untrusted: {}'.format(sig_from)
- mail.add_header(X_SIGNATURE_VALID_HEADER, 'False' if error_msg else 'True')
+ mail.add_header(X_SIGNATURE_VALID_HEADER,
+ 'False' if (error_msg or not sig_known) else 'True')
mail.add_header(X_SIGNATURE_MESSAGE_HEADER, msg)
diff --git a/tests/db/utils_test.py b/tests/db/utils_test.py
index ddb16786..af5f2517 100644
--- a/tests/db/utils_test.py
+++ b/tests/db/utils_test.py
@@ -403,7 +403,6 @@ class TestAddSignatureHeaders(unittest.TestCase):
(utils.X_SIGNATURE_MESSAGE_HEADER, u'Invalid: error message'),
mail.headers)
- @unittest.expectedFailure
def test_get_key_fails(self):
mail = self.FakeMail()
with mock.patch('alot.db.utils.crypto.get_key',