diff options
author | Ivan Alejandro <ivanalejandro0@gmail.com> | 2014-01-22 11:03:58 -0300 |
---|---|---|
committer | Ivan Alejandro <ivanalejandro0@gmail.com> | 2014-01-22 11:03:58 -0300 |
commit | 3017b9665438ddaf2ece1dd3cdfe81f0f0965146 (patch) | |
tree | df7730c29ee1bb47b1d0c72c6baa38f7294439a2 /mail/src/leap | |
parent | 884ca20097f5c14d4b00553522292f051e3c097c (diff) |
Handle non-ascii headers. Closes #5021.
Diffstat (limited to 'mail/src/leap')
-rw-r--r-- | mail/src/leap/mail/imap/messages.py | 24 |
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 862a9f21..5bb5f1cc 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): """ |