From f7030295a936cc5da33f50411b5ff60ae0eec7cc Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 12 Jan 2015 20:47:29 -0400 Subject: Use mailbox uuids The previous implementation is naive, since it imposes a burden when renaming mailboxes. We're using uuids in the local uid tables instead, which is more cryptic but way more efficient. * receive mbox uuid instead of name * use mailbox uuid in identifiers --- src/leap/mail/imap/mailbox.py | 12 +++++++----- src/leap/mail/imap/tests/test_imap.py | 26 +++++++++++++++++--------- 2 files changed, 24 insertions(+), 14 deletions(-) (limited to 'src/leap/mail/imap') diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py index faeba9d..f2cbf75 100644 --- a/src/leap/mail/imap/mailbox.py +++ b/src/leap/mail/imap/mailbox.py @@ -236,6 +236,7 @@ class IMAPMailbox(object): :rtype: int """ + # TODO --- return the uid if it has it!!! d = self.collection.get_msg_by_uid(message) d.addCallback(lambda m: m.getUID()) return d @@ -357,7 +358,7 @@ class IMAPMailbox(object): reactor.callLater(0, self.notify_new) return x - d = self.collection.add_message(flags=flags, date=date) + d = self.collection.add_msg(message, flags=flags, date=date) d.addCallback(notifyCallback) d.addErrback(lambda f: log.msg(f.getTraceback())) return d @@ -389,14 +390,15 @@ class IMAPMailbox(object): messages and number of recent messages. :rtype: Deferred """ - d_exists = self.getMessageCount() - d_recent = self.getRecentCount() + d_exists = defer.maybeDeferred(self.getMessageCount) + d_recent = defer.maybeDeferred(self.getRecentCount) d_list = [d_exists, d_recent] def log_num_msg(result): - exists, recent = result + exists, recent = tuple(result) logger.debug("NOTIFY (%r): there are %s messages, %s recent" % ( self.mbox_name, exists, recent)) + return result d = defer.gatherResults(d_list) d.addCallback(log_num_msg) @@ -654,7 +656,7 @@ class IMAPMailbox(object): return result def _get_unseen_deferred(self): - return self.getUnseenCount() + return defer.maybeDeferred(self.getUnseenCount) def __cb_signal_unread_to_ui(self, unseen): """ diff --git a/src/leap/mail/imap/tests/test_imap.py b/src/leap/mail/imap/tests/test_imap.py index 5af499f..dbb823f 100644 --- a/src/leap/mail/imap/tests/test_imap.py +++ b/src/leap/mail/imap/tests/test_imap.py @@ -926,31 +926,39 @@ class LeapIMAP4ServerTestCase(IMAP4HelperMixin, unittest.TestCase): """ infile = util.sibpath(__file__, 'rfc822.message') message = open(infile) - LeapIMAPServer.theAccount.addMailbox('root/subthing') + acc = self.server.theAccount + mailbox_name = "root_subthing" + + def add_mailbox(): + return acc.addMailbox(mailbox_name) def login(): return self.client.login(TEST_USER, TEST_PASSWD) def append(): return self.client.append( - 'root/subthing', - message, + mailbox_name, message, ('\\SEEN', '\\DELETED'), 'Tue, 17 Jun 2003 11:22:16 -0600 (MDT)', ) - d1 = self.connected.addCallback(strip(login)) + d1 = self.connected.addCallback(strip(add_mailbox)) + d1.addCallback(strip(login)) d1.addCallbacks(strip(append), self._ebGeneral) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) - return d.addCallback(self._cbTestFullAppend, infile) + d.addCallback(lambda _: acc.getMailbox(mailbox_name)) - def _cbTestFullAppend(self, ignored, infile): - mb = LeapIMAPServer.theAccount.getMailbox('root/subthing') - self.assertEqual(1, len(mb.messages)) + def print_mb(mb): + print "MB ----", mb + return mb + d.addCallback(print_mb) + d.addCallback(lambda mb: mb.collection.get_message_by_uid(1)) + return d.addCallback(self._cbTestFullAppend, infile) - msg = mb.messages.get_msg_by_uid(1) + def _cbTestFullAppend(self, msg, infile): + # TODO --- move to deferreds self.assertEqual( set(('\\Recent', '\\SEEN', '\\DELETED')), set(msg.getFlags())) -- cgit v1.2.3