summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/mailstore/leap_mailstore.py
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-09-01 10:21:42 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-09-01 10:21:42 +0200
commit5c5500f91a520ee363c8e553718a5a0e763257e5 (patch)
treefa9cdaf26e805f222b30c18841eaf2b7cf7fcbb5 /service/pixelated/adapter/mailstore/leap_mailstore.py
parent9d2a3e2dff6c986fc0a6a066da038130db6e849b (diff)
Decode encoded mail headers to unicode
- Issue #446
Diffstat (limited to 'service/pixelated/adapter/mailstore/leap_mailstore.py')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index c18748b6..73ce543f 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -88,9 +88,19 @@ class LeapMail(Mail):
return result
+ def _decoded_header_utf_8(self, header_value):
+ if isinstance(header_value, list):
+ return [self._decoded_header_utf_8(v) for v in header_value]
+ else:
+ content, encoding = decode_header(header_value)[0]
+ if encoding:
+ return unicode(content, encoding=encoding)
+ else:
+ return unicode(content, encoding='ascii')
+
def as_dict(self):
return {
- 'header': {k.lower(): v for k, v in self.headers.items()},
+ 'header': {k.lower(): self._decoded_header_utf_8(v) for k, v in self.headers.items()},
'ident': self._mail_id,
'tags': self.tags,
'status': list(self.status),