summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2015-11-25 19:15:33 +0100
committerRuben Pollan <meskio@sindominio.net>2015-12-09 20:17:50 +0100
commitb26643ea9848869ece6ead2ba6c0991333d3c6f4 (patch)
tree646d6d6fcc50d192a5b857860eba474a55bd5537 /src
parent8fc1258ace65be2bb828bf302fc0661cdd128bd7 (diff)
[feat] use the original message for encryption
Do not reconstruct the message from the parsed one. Added test for missleading encoding. - Resolves: #7253
Diffstat (limited to 'src')
-rw-r--r--src/leap/mx/mail_receiver.py9
-rw-r--r--src/leap/mx/tests/test_mail_receiver.py16
2 files changed, 18 insertions, 7 deletions
diff --git a/src/leap/mx/mail_receiver.py b/src/leap/mx/mail_receiver.py
index ea13658..4d82849 100644
--- a/src/leap/mx/mail_receiver.py
+++ b/src/leap/mx/mail_receiver.py
@@ -166,7 +166,7 @@ class MailReceiver(Service):
:param pubkey: public key for the owner of the message
:type pubkey: str
:param message: message contents
- :type message: email.message.Message
+ :type message: str
:return: doc to sync with Soledad or None, None if something
went wrong.
@@ -177,13 +177,10 @@ class MailReceiver(Service):
"I know: %r" % (pubkey,))
return None
- # find message's encoding
- message_as_string = message.as_string()
-
doc = ServerDocument(doc_id=str(pyuuid.uuid4()))
# store plain text if pubkey is not available
- data = {'incoming': True, 'content': message_as_string}
+ data = {'incoming': True, 'content': message}
if pubkey is None or len(pubkey) == 0:
doc.content = {
self.INCOMING_KEY: True,
@@ -385,7 +382,7 @@ class MailReceiver(Service):
defer.returnValue(None)
log.msg("Encrypting message to %s's pubkey" % (uuid,))
- doc = yield self._encrypt_message(pubkey, msg)
+ doc = yield self._encrypt_message(pubkey, mail_data)
yield self._export_message(uuid, doc)
yield self._remove(filepath)
diff --git a/src/leap/mx/tests/test_mail_receiver.py b/src/leap/mx/tests/test_mail_receiver.py
index e72cb1a..33967ea 100644
--- a/src/leap/mx/tests/test_mail_receiver.py
+++ b/src/leap/mx/tests/test_mail_receiver.py
@@ -19,6 +19,7 @@
MailReceiver tests
"""
+import codecs
import json
import os
import os.path
@@ -97,14 +98,27 @@ class MailReceiverTestCase(unittest.TestCase):
yield defer_called
self.assertTrue(os.path.exists(path))
+ @defer.inlineCallbacks
+ def test_misleading_encoding(self):
+ msg, path = self.addMail(
+ "ñáûä", headers={'Content-Transfer-Encoding': '7Bit'})
+ uuid, doc = yield self.defer_put_doc
+ self.assertEqual(uuid, UUID)
+ decmsg = self.decryptDoc(doc)
+ self.assertEqual(unicode(msg, "utf-8"), decmsg)
+ self.assertFalse(os.path.exists(path))
+
def addMail(self, body="", filename="foo", to=ADDRESS,
- frm="someone@domain.org", subject="sent subject"):
+ frm="someone@domain.org", subject="sent subject",
+ headers={}):
msg = Message()
msg.add_header("To", to)
msg.add_header(
"Delivered-To", UUID + "@deliver.local")
msg.add_header("From", frm)
msg.add_header("Subject", subject)
+ for header, value in headers.iteritems():
+ msg.add_header(header, value)
msg.set_payload(body)
path = os.path.join(self.directory, "new", filename)