diff options
author | Kali Kaneko <kali@leap.se> | 2014-02-05 11:48:20 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2014-02-05 14:01:35 -0400 |
commit | f1c9711c4d77aa514798709687540fcb8da82e05 (patch) | |
tree | b0830fc8d7eaa7ba6c2cc51e3920655870fab568 /mail | |
parent | 51c14b9d00e96c2ed929cca24f1222a2b6b9532e (diff) |
fix expunge deferreds so they wait
Diffstat (limited to 'mail')
-rw-r--r-- | mail/src/leap/mail/imap/mailbox.py | 7 | ||||
-rw-r--r-- | mail/src/leap/mail/imap/memorystore.py | 38 |
2 files changed, 26 insertions, 19 deletions
diff --git a/mail/src/leap/mail/imap/mailbox.py b/mail/src/leap/mail/imap/mailbox.py index c6825786..d8af0a50 100644 --- a/mail/src/leap/mail/imap/mailbox.py +++ b/mail/src/leap/mail/imap/mailbox.py @@ -484,9 +484,6 @@ class SoledadMailbox(WithMsgFields, MBoxParser): d.addCallback(self._close_cb) return d - def _expunge_cb(self, result): - return result - def expunge(self): """ Remove all messages flagged \\Deleted @@ -494,9 +491,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser): if not self.isWriteable(): raise imap4.ReadOnlyMailbox d = defer.Deferred() - return self._memstore.expunge(self.mbox, d) - self._memstore.expunge(self.mbox) - d.addCallback(self._expunge_cb, d) + self._memstore.expunge(self.mbox, d) return d def _bound_seq(self, messages_asked): diff --git a/mail/src/leap/mail/imap/memorystore.py b/mail/src/leap/mail/imap/memorystore.py index 195cef79..f4a4522b 100644 --- a/mail/src/leap/mail/imap/memorystore.py +++ b/mail/src/leap/mail/imap/memorystore.py @@ -879,30 +879,43 @@ class MemoryStore(object): Remove all messages flagged \\Deleted, from the Memory Store and from the permanent store also. + It first queues up a last write, and wait for the deferreds to be done + before continuing. + :param mbox: the mailbox :type mbox: str or unicode :param observer: a deferred that will be fired when expunge is done :type observer: Deferred - :return: a list of UIDs - :rtype: list """ - # TODO expunge should add itself as a callback to the ongoing - # writes. soledad_store = self._permanent_store - all_deleted = [] - try: # 1. Stop the writing call self._stop_write_loop() # 2. Enqueue a last write. - #self.write_messages(soledad_store) - # 3. Should wait on the writebacks to finish ??? - # FIXME wait for this, and add all the rest of the method - # as a callback!!! + self.write_messages(soledad_store) + # 3. Wait on the writebacks to finish + + pending_deferreds = (self._new_deferreds.get(mbox, []) + + self._dirty_deferreds.get(mbox, [])) + d1 = defer.gatherResults(pending_deferreds, consumeErrors=True) + d1.addCallback( + self._delete_from_soledad_and_memory, mbox, observer) except Exception as exc: logger.exception(exc) - # Now, we...: + def _delete_from_soledad_and_memory(self, result, mbox, observer): + """ + Remove all messages marked as deleted from soledad and memory. + + :param result: ignored. the result of the deferredList that triggers + this as a callback from `expunge`. + :param mbox: the mailbox + :type mbox: str or unicode + :param observer: a deferred that will be fired when expunge is done + :type observer: Deferred + """ + all_deleted = [] + soledad_store = self._permanent_store try: # 1. Delete all messages marked as deleted in soledad. @@ -927,8 +940,7 @@ class MemoryStore(object): logger.exception(exc) finally: self._start_write_loop() - observer.callback(True) - return all_deleted + observer.callback(all_deleted) # Dump-to-disk controls. |