summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
authorJefferson Stachelski <jstachel@thoughtworks.com>2015-03-18 19:09:03 -0300
committerJefferson Stachelski <jstachel@thoughtworks.com>2015-03-18 19:12:05 -0300
commitd732de6df06ed8e18647e19b13534da11fdc7ff5 (patch)
treef5b6e892dc0a46b23359c6ca2096f5aa96228a71 /service/pixelated
parente9648ca996cc195fc19a8ca1ceac016a1ff0ca5b (diff)
#248 Fixed the UTF-8 decode for special characteres
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/adapter/model/mail.py8
-rw-r--r--service/pixelated/adapter/search/__init__.py6
2 files changed, 10 insertions, 4 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index 65e87f54..85f2bed4 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -16,6 +16,7 @@
import json
from uuid import uuid4
from email.mime.text import MIMEText
+from email.header import decode_header
from leap.mail.imap.fields import fields
import leap.mail.walk as walk
@@ -288,7 +289,8 @@ class PixelatedMail(Mail):
_headers[header] = [head.strip() for head in compact(_headers[header])]
for header in ['From', 'Subject']:
- _headers[header] = hdoc_headers.get(header)
+ # _headers[header] = hdoc_headers.get(header)
+ _headers[header] = self._decode_header(hdoc_headers.get(header))
_headers['Date'] = self._get_date()
@@ -302,6 +304,10 @@ class PixelatedMail(Mail):
return _headers
+ def _decode_header(self, header):
+ arr_header = decode_header(header)
+ return arr_header[0][0]
+
def _get_date(self):
date = self.hdoc.content.get('date', None)
if not date:
diff --git a/service/pixelated/adapter/search/__init__.py b/service/pixelated/adapter/search/__init__.py
index 33259e63..331ea8fe 100644
--- a/service/pixelated/adapter/search/__init__.py
+++ b/service/pixelated/adapter/search/__init__.py
@@ -128,8 +128,8 @@ class SearchEngine(object):
tags.append(mail.mailbox_name.lower())
bounced = mail.bounced if mail.bounced else ['']
index_data = {
- 'sender': unicode(header.get('from', '')),
- 'subject': unicode(header.get('subject', '')),
+ 'sender': unicode(header.get('from', '').decode('utf-8')),
+ 'subject': unicode(header.get('subject', '').decode('utf-8')),
'date': milliseconds(header.get('date', '')),
'to': u','.join(header.get('to', [''])),
'cc': u','.join(header.get('cc', [''])),
@@ -139,7 +139,7 @@ class SearchEngine(object):
'body': unicode(mdict['textPlainBody']),
'ident': unicode(mdict['ident']),
'flags': unicode(','.join(unique(mail.flags))),
- 'raw': unicode(mail.raw)
+ 'raw': unicode(mail.raw.decode('utf-8'))
}
writer.update_document(**index_data)