summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2013-05-27 12:26:16 +0200
committerPatrick Totzke <patricktotzke@gmail.com>2013-06-16 21:17:40 +0100
commit919bba8d8e7368ffbf0710ebf9b4a31f2a7e4040 (patch)
tree1a626535709519041310f47e3b064bdc5bf9d8a4
parentc02e2f8136e6602b8500c777dd95b33b8ae642df (diff)
Handle missing parameters gracefully
OpenPGP states that the Content-Type header is annotated with parameters, namely 'protocol' and 'micalg'. Use .get() to retrieve this values with a default value to handle the case of malformed (according to RFC 3156) messages gracefully. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
-rw-r--r--alot/db/utils.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py
index 9ddd6524..9449f989 100644
--- a/alot/db/utils.py
+++ b/alot/db/utils.py
@@ -92,15 +92,16 @@ def message_from_file(handle):
want, ct)
p = {k:v for k, v in m.get_params()}
- if p['protocol'] != want:
+ if p.get('protocol', 'nothing') != want:
malformed = 'expected protocol={0}, got: {1}'.format(
- want, p['protocol'])
+ want, p.get('protocol', 'nothing'))
# TODO: RFC 3156 says the alg has to be lower case, but I've
# seen a message with 'PGP-'. maybe we should be more
# permissive here, or maybe not, this is crypto stuff...
- if not p['micalg'].startswith('pgp-'):
- malformed = 'expected micalg=pgp-..., got: {0}'.format(p['micalg'])
+ if not p.get('micalg', 'nothing').startswith('pgp-'):
+ malformed = 'expected micalg=pgp-..., got: {0}'.format(
+ p.get('micalg', 'nothing'))
sigs = []
if not malformed: