From 365cdc1137cf4746d46b988f5b51b25e131c4e73 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Mon, 27 May 2013 15:19:10 +0200 Subject: Fix detection of OpenPGP encrypted data Fix detection of OpenPGP encrypted data and also check the 'protocol' parameter. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de> --- alot/db/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/alot/db/utils.py b/alot/db/utils.py index e42deed7..00cf0e44 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -130,9 +130,9 @@ def message_from_file(handle): add_signature_headers(m, sigs, malformed) # handle OpenPGP encrypted data - elif (m.is_multipart() and + elif (m.is_multipart() and m.get_content_subtype() == 'encrypted' and m.get_payload(0).get_content_type() == 'application/pgp-encrypted' and - m.get_payload(0).get_payload() == 'Version: 1'): + 'Version: 1' in m.get_payload(0).get_payload()): # RFC 3156 is quite strict: # * exactly two messages # * the first is of type 'application/pgp-encrypted' @@ -141,6 +141,13 @@ def message_from_file(handle): # * the second contains the encrypted and possibly signed data malformed = False + p = get_params(m) + + want = 'application/pgp-encrypted' + if p.get('protocol', 'nothing') != want: + malformed = 'expected protocol={0}, got: {1}'.format( + want, p.get('protocol', 'nothing')) + want = 'application/octet-stream' ct = m.get_payload(1).get_content_type() if ct != want: -- cgit v1.2.3