summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2015-02-12 17:32:40 -0200
committerDuda Dornelles <ddornell@thoughtworks.com>2015-02-13 12:47:12 -0200
commit2e88b9d9d68bae91cfde466edfc027f19f7c74b8 (patch)
treef60c873b59a86b2684683139c6ccbd88e980bfb4
parent20d3971db4611c9229262b26d973a9df1a71f9f6 (diff)
Monkey patching fetch decrypt to add encryption info
-rw-r--r--service/pixelated/adapter/model/mail.py3
-rw-r--r--service/pixelated/config/__init__.py1
-rw-r--r--service/pixelated/resources/features_resource.py2
-rw-r--r--service/pixelated/support/ext_fetch.py14
4 files changed, 18 insertions, 2 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index dfc0ea1c..dc05a4de 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -379,7 +379,8 @@ class PixelatedMail(Mail):
@property
def encrypted(self):
- return self.hdoc.content["headers"].get("OpenPGP", None) is not None
+ return self.hdoc.content["headers"].get("OpenPGP", None) is not None or \
+ self.hdoc.content["headers"].get("X-Pixelated-encryption-status", "false") is "true"
def as_dict(self):
dict_mail = {'header': {k.lower(): v for k, v in self.headers.items()},
diff --git a/service/pixelated/config/__init__.py b/service/pixelated/config/__init__.py
index 61d0fc54..f9c43153 100644
--- a/service/pixelated/config/__init__.py
+++ b/service/pixelated/config/__init__.py
@@ -35,6 +35,7 @@ from twisted.internet.threads import deferToThread
import pixelated.support.ext_protobuf
import pixelated.support.ext_sqlcipher
import pixelated.support.ext_esmtp_sender_factory
+import pixelated.support.ext_fetch
def initialize():
diff --git a/service/pixelated/resources/features_resource.py b/service/pixelated/resources/features_resource.py
index 1784e463..6a1a49ca 100644
--- a/service/pixelated/resources/features_resource.py
+++ b/service/pixelated/resources/features_resource.py
@@ -20,7 +20,7 @@ from twisted.web.resource import Resource
class FeaturesResource(Resource):
- DISABLED_FEATURES = ['draftReply', 'encryptionStatus']
+ DISABLED_FEATURES = ['draftReply']
isLeaf = True
diff --git a/service/pixelated/support/ext_fetch.py b/service/pixelated/support/ext_fetch.py
new file mode 100644
index 00000000..ab0def9f
--- /dev/null
+++ b/service/pixelated/support/ext_fetch.py
@@ -0,0 +1,14 @@
+import leap.mail.imap.fetch as fetch
+
+
+def mark_as_encrypted(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
+ 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)