From 06bfff7c04ce74892368a7bda229ad397aa5b921 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 18 Aug 2011 09:08:53 +0200 Subject: [PATCH] Coalesce SEARCH uid list into sequence set 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 Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/IMAP.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 20940a2..f930bc5 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: