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 <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2011-08-18 09:08:53 +02:00 committed by Nicolas Sebrecht
parent 373e7cdbc1
commit 06bfff7c04

View File

@ -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: