summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2014-02-05 11:48:20 -0400
committerKali Kaneko <kali@leap.se>2014-02-05 14:01:35 -0400
commit423624e5f2c4d3f8cfe8f15f4d6649ed3eea11dc (patch)
treec1a052110d49018b3fa646ffab329403b5104766 /src
parent3511f7992e67bc49e9fc4771f4b2c0d9199822d7 (diff)
fix expunge deferreds so they wait
Diffstat (limited to 'src')
-rw-r--r--src/leap/mail/imap/mailbox.py7
-rw-r--r--src/leap/mail/imap/memorystore.py38
2 files changed, 26 insertions, 19 deletions
diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py
index c682578..d8af0a5 100644
--- a/src/leap/mail/imap/mailbox.py
+++ b/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/src/leap/mail/imap/memorystore.py b/src/leap/mail/imap/memorystore.py
index 195cef7..f4a4522 100644
--- a/src/leap/mail/imap/memorystore.py
+++ b/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.