summaryrefslogtreecommitdiff
path: root/mail/src
diff options
context:
space:
mode:
Diffstat (limited to 'mail/src')
-rw-r--r--mail/src/leap/mail/imap/messages.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/mail/src/leap/mail/imap/messages.py b/mail/src/leap/mail/imap/messages.py
index 862a9f2..5bb5f1c 100644
--- a/mail/src/leap/mail/imap/messages.py
+++ b/mail/src/leap/mail/imap/messages.py
@@ -605,18 +605,26 @@ class LeapMessage(fields, MailParser, MBoxParser):
if isinstance(headers, list):
headers = dict(headers)
+ # default to most likely standard
+ charset = find_charset(headers, "utf-8")
+
# twisted imap server expects *some* headers to be lowercase
# XXX refactor together with MessagePart method
- headers = dict(
- (str(key), str(value)) if key.lower() != "content-type"
- else (str(key.lower()), str(value))
- for (key, value) in headers.items())
+ headers2 = dict()
+ for key, value in headers.items():
+ if key.lower() == "content-type":
+ key = key.lower()
- # unpack and filter original dict by negate-condition
- filter_by_cond = [(key, val) for key, val
- in headers.items() if cond(key)]
+ if not isinstance(key, str):
+ key = key.encode(charset, 'replace')
+ if not isinstance(value, str):
+ value = value.encode(charset, 'replace')
+
+ # filter original dict by negate-condition
+ if cond(key):
+ headers2[key] = value
- return dict(filter_by_cond)
+ return headers2
def _get_headers(self):
"""