Trade recursion by plain old cycle

We can do a simpler and more stack-friendly hack for IMAP
servers with limited line lenghts.

Reported-by: Josh Berry, https://github.com/josh-berry
GH: https://github.com/OfflineIMAP/offlineimap/pull/100
Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
This commit is contained in:
Eygene Ryabinkin 2014-07-08 12:23:05 +04:00
parent ffd1b1d691
commit 1f2e8af8aa

View File

@ -755,14 +755,7 @@ class IMAPFolder(BaseFolder):
def deletemessagesflags(self, uidlist, flags):
self.__processmessagesflags('-', uidlist, flags)
def __processmessagesflags(self, operation, uidlist, flags):
# XXX: should really iterate over batches of 100 UIDs
if len(uidlist) > 101:
# Hack for those IMAP servers with a limited line length
self.__processmessagesflags(operation, uidlist[:100], flags)
self.__processmessagesflags(operation, uidlist[100:], flags)
return
def __processmessagesflags_real(self, operation, uidlist, flags):
imapobj = self.imapserver.acquireconnection()
try:
try:
@ -804,6 +797,16 @@ class IMAPFolder(BaseFolder):
elif operation == '-':
self.messagelist[uid]['flags'] -= flags
def __processmessagesflags(self, operation, uidlist, flags):
# Hack for those IMAP servers with a limited line length
batch_size = 100
while len(uidlist):
self.__processmessagesflags_real(operation, uidlist[:batch_size], flags)
uidlist = uidlist[batch_size:]
return
# Interface from BaseFolder
def change_message_uid(self, uid, new_uid):
"""Change the message from existing uid to new_uid