summaryrefslogtreecommitdiff
path: root/mail
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
commit62a02b3b1e14afcbec82d3fca2f906ca6dd38715 (patch)
tree6775029b6a797974106ebd88bad59925ddeac00f /mail
parentedc1d23ef520871b9585ed5d8fdced9ee8b98594 (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
Diffstat (limited to 'mail')
-rw-r--r--mail/src/leap/mail/imap/server.py40
1 files changed, 37 insertions, 3 deletions
diff --git a/mail/src/leap/mail/imap/server.py b/mail/src/leap/mail/imap/server.py
index 26d20017..3aeca54f 100644
--- a/mail/src/leap/mail/imap/server.py
+++ b/mail/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) + ' ')