summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-03-23 14:39:39 -0400
committerKali Kaneko <kali@leap.se>2015-03-23 14:45:45 -0400
commite139fb997c4c482e70cea3dec10b9a2365165772 (patch)
tree440d4a0bc0f9b38ef33452b8a1e3b884478b71c0
parent57ec516fe350787d2b6e99a401c96520de1a43b3 (diff)
[bug] fix wrong case in the boundary passed in BODYSTRUCTURE
By removing this call to lower(), we avoid a bug in which the BODYSTRUCTURE response returns a boundary all in lower case. Should send patch upstream to twisted. Related: #6773
-rw-r--r--src/leap/mail/imap/server.py40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/leap/mail/imap/server.py b/src/leap/mail/imap/server.py
index 26d2001..3aeca54 100644
--- a/src/leap/mail/imap/server.py
+++ b/src/leap/mail/imap/server.py
@@ -36,6 +36,38 @@ from twisted.mail.imap4 import IllegalClientResponse
from twisted.mail.imap4 import LiteralString, LiteralFile
+def _getContentType(msg):
+ """
+ Return a two-tuple of the main and subtype of the given message.
+ """
+ attrs = None
+ mm = msg.getHeaders(False, 'content-type').get('content-type', None)
+ if mm:
+ mm = ''.join(mm.splitlines())
+ mimetype = mm.split(';')
+ if mimetype:
+ type = mimetype[0].split('/', 1)
+ if len(type) == 1:
+ major = type[0]
+ minor = None
+ elif len(type) == 2:
+ major, minor = type
+ else:
+ major = minor = None
+ # XXX patched ---------------------------------------------
+ attrs = dict(x.strip().split('=', 1) for x in mimetype[1:])
+ # XXX patched ---------------------------------------------
+ else:
+ major = minor = None
+ else:
+ major = minor = None
+ return major, minor, attrs
+
+# Monkey-patch _getContentType to avoid bug that passes lower-case boundary in
+# BODYSTRUCTURE response.
+imap4._getContentType = _getContentType
+
+
class LEAPIMAPServer(imap4.IMAP4Server):
"""
An IMAP4 Server with a LEAP Storage Backend.
@@ -84,7 +116,9 @@ class LEAPIMAPServer(imap4.IMAP4Server):
if part.header:
hdrs = msg.getHeaders(part.header.negate, *part.header.fields)
hdrs = imap4._formatHeaders(hdrs)
- _w(str(part) + ' ' + imap4._literal(hdrs))
+ # PATCHED ##########################################
+ _w(str(part) + ' ' + imap4._literal(hdrs + "\r\n"))
+ # PATCHED ##########################################
elif part.text:
_w(str(part) + ' ')
_f()
@@ -94,9 +128,9 @@ class LEAPIMAPServer(imap4.IMAP4Server):
elif part.mime:
hdrs = imap4._formatHeaders(msg.getHeaders(True))
- ###### PATCHED #####################################
+ # PATCHED ##########################################
_w(str(part) + ' ' + imap4._literal(hdrs + "\r\n"))
- ###### END PATCHED #################################
+ # END PATCHED ######################################
elif part.empty:
_w(str(part) + ' ')