[PATCH 3/6] Coalesce SEARCH uid list into sequence set
Sebastian at SSpaeth.de
Mon Aug 15 13:15:56 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 8f41490..d7d1832 100644
@@ -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.replace(" ", ",")
+ res_type, res_data = imapobj.search(None, search_condition)
+ #result UIDs come back seperated by space
+ messagesToFetch = imaputil.uid_sequence(res_data.split())
- if len(messagesToFetch) < 1:
+ if not messagesToFetch:
# No messages; return
@@ -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)')
+ response = imapobj.fetch("'%s'" % messagesToFetch, '(FLAGS UID)')
for messagestr in response:
More information about the OfflineIMAP-project