summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-01-14 01:09:19 -0400
committerKali Kaneko <kali@leap.se>2015-02-11 14:05:43 -0400
commita794d60f9985f5dc7507ada1d5dab65e9fe6874e (patch)
tree7dee8a4e4aeac11cc1b4b10f25ed60ecc0fee643
parent4c2dbc38bda73401d8a401c3a7b449f59c7564e6 (diff)
patch cbSelect to accept deferreds for count*
-rw-r--r--mail/src/leap/mail/imap/account.py8
-rw-r--r--mail/src/leap/mail/imap/server.py14
-rw-r--r--mail/src/leap/mail/imap/tests/test_imap.py20
3 files changed, 28 insertions, 14 deletions
diff --git a/mail/src/leap/mail/imap/account.py b/mail/src/leap/mail/imap/account.py
index dfc0d626..8a6e87eb 100644
--- a/mail/src/leap/mail/imap/account.py
+++ b/mail/src/leap/mail/imap/account.py
@@ -330,8 +330,7 @@ class IMAPAccount(object):
oldname = normalize_mailbox(oldname)
newname = normalize_mailbox(newname)
- def rename_inferiors(inferiors_result):
- inferiors, mailboxes = inferiors_result
+ def rename_inferiors((inferiors, mailboxes)):
rename_deferreds = []
inferiors = [
(o, o.replace(oldname, newname, 1)) for o in inferiors]
@@ -347,7 +346,10 @@ class IMAPAccount(object):
d1 = defer.gatherResults(rename_deferreds, consumeErrors=True)
return d1
- d = self._inferiorNames(oldname)
+ d1 = self._inferiorNames(oldname)
+ d2 = self.account.list_all_mailbox_names()
+
+ d = defer.gatherResults([d1, d2])
d.addCallback(rename_inferiors)
return d
diff --git a/mail/src/leap/mail/imap/server.py b/mail/src/leap/mail/imap/server.py
index b4f320a6..32c921d3 100644
--- a/mail/src/leap/mail/imap/server.py
+++ b/mail/src/leap/mail/imap/server.py
@@ -162,10 +162,20 @@ class LEAPIMAPServer(imap4.IMAP4Server):
self.sendNegativeResponse(tag, 'Mailbox cannot be selected')
return
+ d1 = defer.maybeDeferred(mbox.getMessageCount)
+ d2 = defer.maybeDeferred(mbox.getRecentCount)
+ return defer.gatherResults([d1, d2]).addCallback(
+ self.__cbSelectWork, mbox, cmdName, tag)
+
+ def __cbSelectWork(self, ((msg_count, recent_count)), mbox, cmdName, tag):
flags = mbox.getFlags()
self.sendUntaggedResponse('FLAGS (%s)' % ' '.join(flags))
- self.sendUntaggedResponse(str(mbox.getMessageCount()) + ' EXISTS')
- self.sendUntaggedResponse(str(mbox.getRecentCount()) + ' RECENT')
+
+ # Patched -------------------------------------------------------
+ # accept deferreds for the count
+ self.sendUntaggedResponse(str(msg_count) + ' EXISTS')
+ self.sendUntaggedResponse(str(recent_count) + ' RECENT')
+ # ----------------------------------------------------------------
# Patched -------------------------------------------------------
# imaptest was complaining about the incomplete line, we're adding
diff --git a/mail/src/leap/mail/imap/tests/test_imap.py b/mail/src/leap/mail/imap/tests/test_imap.py
index d7fcdce1..6be41cd6 100644
--- a/mail/src/leap/mail/imap/tests/test_imap.py
+++ b/mail/src/leap/mail/imap/tests/test_imap.py
@@ -447,9 +447,12 @@ class LEAPIMAP4ServerTestCase(IMAP4HelperMixin):
"""
Try to rename hierarchical mailboxes
"""
- acc = LEAPIMAPServer.theAccount
- dc1 = lambda: acc.create('oldmbox/m1')
- dc2 = lambda: acc.create('oldmbox/m2')
+ acc = self.server.theAccount
+
+ def add_mailboxes():
+ return defer.gatherResults([
+ acc.addMailbox('oldmbox/m1'),
+ acc.addMailbox('oldmbox/m2')])
def login():
return self.client.login(TEST_USER, TEST_PASSWD)
@@ -457,19 +460,18 @@ class LEAPIMAP4ServerTestCase(IMAP4HelperMixin):
def rename():
return self.client.rename('oldmbox', 'newname')
- d1 = self.connected.addCallback(strip(login))
- d1.addCallback(strip(dc1))
- d1.addCallback(strip(dc2))
+ d1 = self.connected.addCallback(strip(add_mailboxes))
+ d1.addCallback(strip(login))
d1.addCallbacks(strip(rename), self._ebGeneral)
d1.addCallbacks(self._cbStopClient, self._ebGeneral)
d2 = self.loopback()
d = defer.gatherResults([d1, d2])
+ d.addCallback(lambda _: acc.account.list_all_mailbox_names())
return d.addCallback(self._cbTestHierarchicalRename)
- def _cbTestHierarchicalRename(self, ignored):
- mboxes = LEAPIMAPServer.theAccount.mailboxes
+ def _cbTestHierarchicalRename(self, mailboxes):
expected = ['INBOX', 'newname', 'newname/m1', 'newname/m2']
- self.assertEqual(sorted(mboxes), sorted([s for s in expected]))
+ self.assertEqual(sorted(mailboxes), sorted([s for s in expected]))
def testSubscribe(self):
"""