summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/mail/imap/server.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2017-09-29 03:39:25 +0200
committerKali Kaneko <kali@leap.se>2017-09-29 14:38:46 +0200
commit76e60371cd89897dd16dc09e0a84a41f146b044f (patch)
tree97776f2dffdd0a336704cfd2a8eb12e5ae56643c /src/leap/bitmask/mail/imap/server.py
parent461778ae25902d3046f44f8e7634a5ea95431080 (diff)
[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.
Diffstat (limited to 'src/leap/bitmask/mail/imap/server.py')
-rw-r--r--src/leap/bitmask/mail/imap/server.py25
1 files changed, 18 insertions, 7 deletions
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)