diff options
Diffstat (limited to 'service/pixelated/support/ext_fetch.py')
-rw-r--r-- | service/pixelated/support/ext_fetch.py | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/service/pixelated/support/ext_fetch.py b/service/pixelated/support/ext_fetch.py index ab0def9f..2db5dd1d 100644 --- a/service/pixelated/support/ext_fetch.py +++ b/service/pixelated/support/ext_fetch.py @@ -1,14 +1,35 @@ import leap.mail.imap.fetch as fetch -def mark_as_encrypted(f): +def mark_as_encrypted_inline(f): def w(*args, **kwargs): - msg, was_decrypted = f(*args) - msg.add_header('X-Pixelated-encryption-status', 'true' if was_decrypted else 'false') - return msg, was_decrypted + msg, valid_sign = f(*args) + is_encrypted = fetch.PGP_BEGIN in args[1].as_string() and fetch.PGP_END in args[1].as_string() + decrypted_successfully = fetch.PGP_BEGIN not in msg.as_string() and fetch.PGP_END not in msg.as_string() + + if not is_encrypted: + encrypted = 'false' + else: + if decrypted_successfully: + encrypted = 'true' + else: + encrypted = 'fail' + + msg.add_header('X-Pixelated-encryption-status', encrypted) + return msg, valid_sign + + return w + + +def mark_as_encrypted_multipart(f): + + def w(*args, **kwargs): + msg, valid_sign = f(*args) + msg.add_header('X-Pixelated-encryption-status', 'true') + return msg, valid_sign return w -fetch.LeapIncomingMail._maybe_decrypt_inline_encrypted_msg = mark_as_encrypted(fetch.LeapIncomingMail._maybe_decrypt_inline_encrypted_msg) -fetch.LeapIncomingMail._decrypt_multipart_encrypted_msg = mark_as_encrypted(fetch.LeapIncomingMail._decrypt_multipart_encrypted_msg) +fetch.LeapIncomingMail._maybe_decrypt_inline_encrypted_msg = mark_as_encrypted_inline(fetch.LeapIncomingMail._maybe_decrypt_inline_encrypted_msg) +fetch.LeapIncomingMail._decrypt_multipart_encrypted_msg = mark_as_encrypted_multipart(fetch.LeapIncomingMail._decrypt_multipart_encrypted_msg) |