summaryrefslogtreecommitdiff
path: root/src/leap/mail/imap
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-01-14 01:09:19 -0400
committerKali Kaneko <kali@leap.se>2015-01-21 15:07:19 -0400
commit16f7099a8c7c1dd31f1b8bab78cc6554a01d63c7 (patch)
tree8e2012de48df76b336f04035b06bb9ddfc17dc43 /src/leap/mail/imap
parent68500fb15dbb7531eeb397ccee2c160d71284d97 (diff)
patch cbSelect to accept deferreds for count*
Diffstat (limited to 'src/leap/mail/imap')
-rw-r--r--src/leap/mail/imap/account.py8
-rw-r--r--src/leap/mail/imap/server.py14
-rw-r--r--src/leap/mail/imap/tests/test_imap.py20
3 files changed, 28 insertions, 14 deletions
diff --git a/src/leap/mail/imap/account.py b/src/leap/mail/imap/account.py
index dfc0d62..8a6e87e 100644
--- a/src/leap/mail/imap/account.py
+++ b/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/src/leap/mail/imap/server.py b/src/leap/mail/imap/server.py
index b4f320a..32c921d 100644
--- a/src/leap/mail/imap/server.py
+++ b/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/src/leap/mail/imap/tests/test_imap.py b/src/leap/mail/imap/tests/test_imap.py
index d7fcdce..6be41cd 100644
--- a/src/leap/mail/imap/tests/test_imap.py
+++ b/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):
"""