[PATCH 3/6] Coalesce SEARCH uid list into sequence set

Sebastian Spaeth Sebastian at SSpaeth.de
Thu Aug 18 08:08:53 BST 2011


Rather than passing in huge lists of continuous numbers which eventually
overflow the maximum command line length, we coalesce number ranges
before passing the UID sequence to SEARCH. This should do away with the
error that has been reported with busy mailing lists and 'maxage'.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/folder/IMAP.py |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 2c1d235..4581dd4 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -143,14 +143,13 @@ class IMAPFolder(BaseFolder):
                         search_condition += "SMALLER " + self.config.getdefault("Account " + self.accountname, "maxsize", -1)
 
                     search_condition += ")"
-                    searchresult = imapobj.search(None, search_condition)
 
-                    #result would come back seperated by space - to change into a fetch
-                    #statement we need to change space to comma
-                    messagesToFetch = searchresult[1][0].replace(" ", ",")
+                    res_type, res_data = imapobj.search(None, search_condition)
+                    #result UIDs come back seperated by space
+                    messagesToFetch = imaputil.uid_sequence(res_data.split())
                 except KeyError:
                     return
-                if len(messagesToFetch) < 1:
+                if not messagesToFetch:
                     # No messages; return
                     return
             else:
@@ -172,7 +171,7 @@ class IMAPFolder(BaseFolder):
             # Now, get the flags and UIDs for these.
             # We could conceivably get rid of maxmsgid and just say
             # '1:*' here.
-            response = imapobj.fetch(messagesToFetch, '(FLAGS UID)')[1]
+            response = imapobj.fetch("'%s'" % messagesToFetch, '(FLAGS UID)')[1]
         finally:
             self.imapserver.releaseconnection(imapobj)
         for messagestr in response:
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list