From 1f2e8af8aaf08db8df03e45962aa67e47297f3f5 Mon Sep 17 00:00:00 2001 From: Eygene Ryabinkin Date: Tue, 8 Jul 2014 12:23:05 +0400 Subject: [PATCH] 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 --- offlineimap/folder/IMAP.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 1029cf7..05e0a36 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -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