summaryrefslogtreecommitdiff
path: root/src/leap/mail/imap/messages.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/mail/imap/messages.py')
-rw-r--r--src/leap/mail/imap/messages.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/leap/mail/imap/messages.py b/src/leap/mail/imap/messages.py
index 02aac2e..4c6f10d 100644
--- a/src/leap/mail/imap/messages.py
+++ b/src/leap/mail/imap/messages.py
@@ -22,7 +22,7 @@ from twisted.mail import imap4
from twisted.internet import defer
from zope.interface import implements
-from leap.mail.utils import find_charset
+from leap.mail.utils import find_charset, CaseInsensitiveDict
logger = logging.getLogger(__name__)
@@ -228,13 +228,13 @@ def _format_headers(headers, negate, *names):
# default to most likely standard
charset = find_charset(headers, "utf-8")
- _headers = dict()
- for key, value in headers.items():
- # twisted imap server expects *some* headers to be lowercase
- # We could use a CaseInsensitiveDict here...
- if key.lower() == "content-type":
- key = key.lower()
+ # We will return a copy of the headers dictionary that
+ # will allow case-insensitive lookups. In some parts of the twisted imap
+ # server code the keys are expected to be in lower case, and in this way
+ # we avoid having to convert them.
+ _headers = CaseInsensitiveDict()
+ for key, value in headers.items():
if not isinstance(key, str):
key = key.encode(charset, 'replace')
if not isinstance(value, str):
@@ -247,4 +247,5 @@ def _format_headers(headers, negate, *names):
# filter original dict by negate-condition
if cond(key):
_headers[key] = value
+
return _headers