[PATCH] much faster deleting of messages from LocalStatus

Michal Schmidt mschmidt at redhat.com
Sat Mar 27 15:18:25 GMT 2010

After tens of thousands of messages on the IMAP server were deleted it
takes offlineimap extremely long time (several hours of high CPU usage)
to delete them locally. It spends almost all the time modifying
LocalStatus. It processes the messages one by one, rewriting the
folder's status file in LocalStatus after each message.

It is much more efficient to save the status file only once, after
removing all the messages from the messagelist.

Deleting lots of messages now takes seconds instead of hours.

This should solve Debian bug #518093:

Signed-off-by: Michal Schmidt <mschmidt at redhat.com>

 offlineimap/folder/LocalStatus.py |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/offlineimap/folder/LocalStatus.py b/offlineimap/folder/LocalStatus.py
index 9f2cf88..157989d 100644
--- a/offlineimap/folder/LocalStatus.py
+++ b/offlineimap/folder/LocalStatus.py
@@ -141,7 +141,14 @@ class LocalStatusFolder(BaseFolder):
     def deletemessage(self, uid):
-        if not uid in self.messagelist:
+        self.deletemessages([uid])
+    def deletemessages(self, uidlist):
+        # Weed out ones not in self.messagelist
+        uidlist = [uid for uid in uidlist if uid in self.messagelist]
+        if not len(uidlist):
-        del(self.messagelist[uid])
+        for uid in uidlist:
+            del(self.messagelist[uid])

More information about the OfflineIMAP-project mailing list