From 76e60371cd89897dd16dc09e0a84a41f146b044f Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Fri, 29 Sep 2017 03:39:25 +0200 Subject: [bug] workaround for using private parseMbox function we're doing something that shouldn't be done, that is relying on private methods of the imap server implementation. until I get to cleanup properly and submit patches for the several things we're patching in the imap server implementation, keeping up with the evolution of the imap server implementation is the only thing to do. specially when we want to get 0.10 out of the door asap. --- src/leap/bitmask/mail/imap/server.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/leap/bitmask') diff --git a/src/leap/bitmask/mail/imap/server.py b/src/leap/bitmask/mail/imap/server.py index 502db773..9ca144e6 100644 --- a/src/leap/bitmask/mail/imap/server.py +++ b/src/leap/bitmask/mail/imap/server.py @@ -27,6 +27,7 @@ from twisted.logger import Logger # imports for LITERAL+ patch from twisted.internet import defer, interfaces from twisted.mail.imap4 import IllegalClientResponse +from twisted.mail.imap4 import IllegalMailboxEncoding from twisted.mail.imap4 import LiteralString, LiteralFile from leap.common.events import emit_async, catalog @@ -61,6 +62,16 @@ def _getContentType(msg): return major, minor, attrs +def _parseMbox(name): + if isinstance(name, unicode): + return name + try: + return name.decode('imap4-utf-7') + except: + log.err() + raise IllegalMailboxEncoding(name) + + # Monkey-patch _getContentType to avoid bug that passes lower-case boundary in # BODYSTRUCTURE response. @@ -417,7 +428,7 @@ class LEAPIMAPServer(imap4.IMAP4Server): # a deferred. def _listWork(self, tag, ref, mbox, sub, cmdName): - mbox = self._parseMbox(mbox) + mbox = _parseMbox(mbox) mailboxes = maybeDeferred(self.account.listMailboxes, ref, mbox) mailboxes.addCallback(self._cbSubscribed) mailboxes.addCallback( @@ -454,7 +465,7 @@ class LEAPIMAPServer(imap4.IMAP4Server): # TODO subscribe method had also to be changed to accomodate deferred def do_SUBSCRIBE(self, tag, name): - name = self._parseMbox(name) + name = _parseMbox(name) def _subscribeCb(_): self.sendPositiveResponse(tag, 'Subscribed') @@ -479,7 +490,7 @@ class LEAPIMAPServer(imap4.IMAP4Server): def do_UNSUBSCRIBE(self, tag, name): # unsubscribe method had also to be changed to accomodate # deferred - name = self._parseMbox(name) + name = _parseMbox(name) def _unsubscribeCb(_): self.sendPositiveResponse(tag, 'Unsubscribed') @@ -503,7 +514,7 @@ class LEAPIMAPServer(imap4.IMAP4Server): select_UNSUBSCRIBE = auth_UNSUBSCRIBE def do_RENAME(self, tag, oldname, newname): - oldname, newname = [self._parseMbox(n) for n in oldname, newname] + oldname, newname = [_parseMbox(n) for n in oldname, newname] if oldname.lower() == 'inbox' or newname.lower() == 'inbox': self.sendNegativeResponse( tag, @@ -535,7 +546,7 @@ class LEAPIMAPServer(imap4.IMAP4Server): select_RENAME = auth_RENAME def do_CREATE(self, tag, name): - name = self._parseMbox(name) + name = _parseMbox(name) def _createCb(result): if result: @@ -560,7 +571,7 @@ class LEAPIMAPServer(imap4.IMAP4Server): select_CREATE = auth_CREATE def do_DELETE(self, tag, name): - name = self._parseMbox(name) + name = _parseMbox(name) if name.lower() == 'inbox': self.sendNegativeResponse(tag, 'You cannot delete the inbox') return @@ -589,7 +600,7 @@ class LEAPIMAPServer(imap4.IMAP4Server): # Patched just to allow __cbAppend to receive a deferred from messageCount # TODO format and send upstream. def do_APPEND(self, tag, mailbox, flags, date, message): - mailbox = self._parseMbox(mailbox) + mailbox = _parseMbox(mailbox) maybeDeferred(self.account.select, mailbox).addCallback( self._cbAppendGotMailbox, tag, flags, date, message).addErrback( self._ebAppendGotMailbox, tag) -- cgit v1.2.3