diff options
author | Kali Kaneko <kali@leap.se> | 2015-03-23 12:59:12 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2015-03-30 14:48:07 -0400 |
commit | f97104e25fe504993615f194825a757d4c381a24 (patch) | |
tree | ff4a91777a7d385e5b986a2c1412e11939b76b4b /src/leap/mail/mail.py | |
parent | efb6028e8d4096d113c565a3953919a5e30d0947 (diff) |
[bug] re-add fix for multiple headers
This fix stores as multi-line headers that are repeated, and that were
being discarded when storing them in a regular dict.
It had been removed during the last refactor.
I also store headers now as a case-insensitive dict, which solves other
problems with the implementation of the twisted imap.
Releases: 0.4.0
Diffstat (limited to 'src/leap/mail/mail.py')
-rw-r--r-- | src/leap/mail/mail.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/leap/mail/mail.py b/src/leap/mail/mail.py index fd2f39a..99c3873 100644 --- a/src/leap/mail/mail.py +++ b/src/leap/mail/mail.py @@ -17,6 +17,7 @@ """ Generic Access to Mail objects: Public LEAP Mail API. """ +import itertools import uuid import logging import StringIO @@ -98,6 +99,23 @@ def _encode_payload(payload, ctype=""): return payload +def _unpack_headers(headers_dict): + """ + Take a "packed" dict containing headers (with repeated keys represented as + line breaks inside each value, preceded by the header key) and return a + list of tuples in which each repeated key has a different tuple. + """ + headers_l = headers_dict.items() + for i, (k, v) in enumerate(headers_l): + splitted = v.split(k.lower() + ": ") + if len(splitted) != 1: + inner = zip( + itertools.cycle([k]), + map(lambda l: l.rstrip('\n'), splitted)) + headers_l = headers_l[:i] + inner + headers_l[i+1:] + return headers_l + + class MessagePart(object): # TODO This class should be better abstracted from the data model. # TODO support arbitrarily nested multiparts (right now we only support @@ -242,7 +260,7 @@ class Message(object): """ Get the raw headers document. """ - return [tuple(item) for item in self._wrapper.hdoc.headers] + return self._wrapper.hdoc.headers def get_body_file(self, store): """ |