From 45f957d559940be343820c1b72674e0bfc2dbd62 Mon Sep 17 00:00:00 2001 From: drebs Date: Mon, 16 Dec 2013 11:20:14 -0200 Subject: Use CouchDocument from new backend (#4475). --- changes/VERSION_COMPAT | 1 + changes/bug_4475_use-couch-document | 1 + src/leap/mx/mail_receiver.py | 13 ++++++------- 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 changes/bug_4475_use-couch-document diff --git a/changes/VERSION_COMPAT b/changes/VERSION_COMPAT index cc00ecf..615578e 100644 --- a/changes/VERSION_COMPAT +++ b/changes/VERSION_COMPAT @@ -8,3 +8,4 @@ # # BEGIN DEPENDENCY LIST ------------------------- # leap.foo.bar>=x.y.z +leap.soledad.common>=0.5 diff --git a/changes/bug_4475_use-couch-document b/changes/bug_4475_use-couch-document new file mode 100644 index 0000000..54c6897 --- /dev/null +++ b/changes/bug_4475_use-couch-document @@ -0,0 +1 @@ + o Use CouchDocument to comply with new Soledad couch backend (#4475). diff --git a/src/leap/mx/mail_receiver.py b/src/leap/mx/mail_receiver.py index c90dda9..7836ab2 100644 --- a/src/leap/mx/mail_receiver.py +++ b/src/leap/mx/mail_receiver.py @@ -39,13 +39,12 @@ from twisted.internet import inotify, defer, task from twisted.python import filepath, log from leap.common.mail import get_email_charset -from leap.soledad.common.document import SoledadDocument from leap.soledad.common.crypto import ( EncryptionSchemes, ENC_JSON_KEY, ENC_SCHEME_KEY, ) -from leap.soledad.common.couch import CouchDatabase +from leap.soledad.common.couch import CouchDatabase, CouchDocument from leap.keymanager import openpgp @@ -109,7 +108,7 @@ class MailReceiver(Service): :return: doc to sync with Soledad or None, None if something went wrong. - :rtype: SoledadDocument + :rtype: CouchDocument """ if pubkey is None or len(pubkey) == 0: log.msg("_encrypt_message: Something went wrong, here's all " @@ -125,7 +124,7 @@ class MailReceiver(Service): result = chardet.detect(message_as_string) encoding = result["encoding"] - doc = SoledadDocument(doc_id=str(pyuuid.uuid4())) + doc = CouchDocument(doc_id=str(pyuuid.uuid4())) # store plain text if pubkey is not available data = {'incoming': True, 'content': message_as_string} @@ -167,14 +166,14 @@ class MailReceiver(Service): def _export_message(self, uuid, doc): """ - Given a UUID and a SoledadDocument, it saves it directly in the + Given a UUID and a CouchDocument, it saves it directly in the couchdb that serves as a backend for Soledad, in a db accessible to the recipient of the mail. :param uuid: the mail owner's uuid :type uuid: str - :param doc: SoledadDocument that represents the email - :type doc: SoledadDocument + :param doc: CouchDocument that represents the email + :type doc: CouchDocument :return: True if it's ok to remove the message, False otherwise -- cgit v1.2.3 From 59c65be76e4ba69c53787250dc964aea1d394514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Tue, 17 Dec 2013 14:49:50 -0300 Subject: Ignore encoding, use message.as_string directly. The message is already in str type, so we don't care about encoding. json.dumps will ignore convertion. --- changes/bug_multiple_encodings | 1 + pkg/requirements.pip | 4 +--- src/leap/mx/mail_receiver.py | 20 +++++--------------- 3 files changed, 7 insertions(+), 18 deletions(-) create mode 100644 changes/bug_multiple_encodings diff --git a/changes/bug_multiple_encodings b/changes/bug_multiple_encodings new file mode 100644 index 0000000..3113328 --- /dev/null +++ b/changes/bug_multiple_encodings @@ -0,0 +1 @@ + o Some emails are multipart and each part has its own encoding. \ No newline at end of file diff --git a/pkg/requirements.pip b/pkg/requirements.pip index 4242ad4..692f66f 100644 --- a/pkg/requirements.pip +++ b/pkg/requirements.pip @@ -10,6 +10,4 @@ couchdb leap.common>=0.3.5 leap.soledad.common>=0.3.0 -leap.keymanager>=0.3.4 - -cchardet # we fallback to chardet if this is not available, but it's preferred +leap.keymanager>=0.3.4 \ No newline at end of file diff --git a/src/leap/mx/mail_receiver.py b/src/leap/mx/mail_receiver.py index c90dda9..833c0ff 100644 --- a/src/leap/mx/mail_receiver.py +++ b/src/leap/mx/mail_receiver.py @@ -27,18 +27,12 @@ import json import email.utils import socket -try: - import cchardet as chardet -except ImportError: - import chardet - from email import message_from_string from twisted.application.service import Service from twisted.internet import inotify, defer, task from twisted.python import filepath, log -from leap.common.mail import get_email_charset from leap.soledad.common.document import SoledadDocument from leap.soledad.common.crypto import ( EncryptionSchemes, @@ -118,12 +112,6 @@ class MailReceiver(Service): # find message's encoding message_as_string = message.as_string() - encoding = get_email_charset( - message_as_string.decode("utf8", "replace"), - default=None) - if encoding is None: - result = chardet.detect(message_as_string) - encoding = result["encoding"] doc = SoledadDocument(doc_id=str(pyuuid.uuid4())) @@ -133,7 +121,8 @@ class MailReceiver(Service): doc.content = { self.INCOMING_KEY: True, ENC_SCHEME_KEY: EncryptionSchemes.NONE, - ENC_JSON_KEY: json.dumps(data, encoding=encoding) + ENC_JSON_KEY: json.dumps(data, + ensure_ascii=False) } return doc @@ -143,7 +132,8 @@ class MailReceiver(Service): key = gpg.list_keys().pop() # We don't care about the actual address, so we use a # dummy one, we just care about the import of the pubkey - openpgp_key = openpgp._build_key_from_gpg("dummy@mail.com", key, pubkey) + openpgp_key = openpgp._build_key_from_gpg("dummy@mail.com", + key, pubkey) # add X-Leap-Provenance header if message is not encrypted if message.get_content_type() != 'multipart/encrypted' and \ @@ -158,7 +148,7 @@ class MailReceiver(Service): self.INCOMING_KEY: True, ENC_SCHEME_KEY: EncryptionSchemes.PUBKEY, ENC_JSON_KEY: str(gpg.encrypt( - json.dumps(data, encoding=encoding), + json.dumps(data, ensure_ascii=False), openpgp_key.fingerprint, symmetric=False)) } -- cgit v1.2.3