summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/requirements.pip2
-rw-r--r--src/leap/mx/mail_receiver.py16
2 files changed, 16 insertions, 2 deletions
diff --git a/pkg/requirements.pip b/pkg/requirements.pip
index d5db275..06e3b85 100644
--- a/pkg/requirements.pip
+++ b/pkg/requirements.pip
@@ -12,3 +12,5 @@ couchdb
python-gnupg>=0.3.0
leap.soledad.common>=0.3.0
leap.keymanager>=0.2.0
+
+cchardet # we fallback to chardet if this is not available, but it's preferred \ No newline at end of file
diff --git a/src/leap/mx/mail_receiver.py b/src/leap/mx/mail_receiver.py
index e263604..c7652fc 100644
--- a/src/leap/mx/mail_receiver.py
+++ b/src/leap/mx/mail_receiver.py
@@ -15,14 +15,22 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
"""
MailReceiver service definition
"""
+
import os
import uuid as pyuuid
import json
import email.utils
+import socket
+
+try:
+ import cchardet as chardet
+except ImportError:
+ import chardet
from email import message_from_string
@@ -121,13 +129,17 @@ class MailReceiver(Service):
doc = SoledadDocument(doc_id=str(pyuuid.uuid4()))
+ result = chardet.detect(message)
+
+ encoding = result["encoding"]
+
data = {'incoming': True, 'content': message}
if pubkey is None or len(pubkey) == 0:
doc.content = {
self.INCOMING_KEY: True,
ENC_SCHEME_KEY: EncryptionSchemes.NONE,
- ENC_JSON_KEY: json.dumps(data)
+ ENC_JSON_KEY: json.dumps(data, encoding=encoding)
}
return uuid, doc
@@ -141,7 +153,7 @@ class MailReceiver(Service):
self.INCOMING_KEY: True,
ENC_SCHEME_KEY: EncryptionSchemes.PUBKEY,
ENC_JSON_KEY: str(gpg.encrypt(
- json.dumps(data),
+ json.dumps(data, encoding=encoding),
openpgp_key.fingerprint,
symmetric=False))
}