summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-10-24 13:41:49 -0300
committerTomás Touceda <chiiph@leap.se>2013-10-28 08:55:51 -0300
commit56bd5becca970c02c19d1b4b9a26cbbf5cb62d17 (patch)
treeabab054d1c8ccf454de18be7cd1a1dbeb4f8182c /src/leap
parentcd550b38686d6772aa7b1ae64c1fcdac5a22251d (diff)
Support any encoding in the emails
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/mx/mail_receiver.py16
1 files changed, 14 insertions, 2 deletions
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))
}