Patch for multi-response imap SELECT

Nicolas Sebrecht nicolas.s-dev at laposte.net
Wed Jan 5 18:53:28 GMT 2011


I see we have now three patches for the same issue around Zimbra (the
latter beeing sent some days ago by marvinthepa). The best patch seems
to be the one from Lars Thalmann and Knut Anders Hatlen. I've reattached
it further in this mail.

In order to merge the patch, I'd like:

  - confirmation I'm right about the best fix to apply
  - a resent of the patch with the approppriate signed-off-by

Thanks,

On Sat, Aug 28, 2010 at 12:58:39PM +0200, Knut Anders Hatlen wrote:
> Lars Thalmann <web at larsthalmann.com> writes:
> > Hi,
> >
> > It seems some servers (Zimbra?) respond to imap SELECT requests with
> > multiple EXISTS lines:
> >
> > ? SELECT INBOX
> > * 500 EXISTS
> > * 0 RECENT
> > * 1000 EXISTS
> > * 0 RECENT
> > * 1500 EXISTS
> > * 0 RECENT
> > * 1567 EXISTS
> > * 0 RECENT
> >
> > This is a rough patch to fix offlineimap so that it handles this:
> >
> [...]
> >
> > Would be great with feedback on whether you think this is the right
> > solution or not.
> 
> Hi Lars,
> 
> I came across the same issue and couldn't fetch more than 500 messages
> from each folder because of it. I needed to make one more change in
> order to get it to work properly with the latest sources from the git
> tree, see the attached patch. I've been running with those changes
> without any problems for three weeks now.
> 
> Thanks,

--- >8 --- (Patch sent)
diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index c90d0e5..8e15470 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -87,7 +87,9 @@ class IMAPFolder(BaseFolder):
             try:
                 # Some mail servers do not return an EXISTS response if
                 # the folder is empty.
-                maxmsgid = long(imapobj.untagged_responses['EXISTS'][0])
+                maxmsgid = 0
+                for msgid in imapobj.untagged_responses['EXISTS']:
+                    maxmsgid = max(long(msgid), maxmsgid)
             except KeyError:
                 return True
 
@@ -169,8 +171,9 @@ class IMAPFolder(BaseFolder):
                 try:
                     # Some mail servers do not return an EXISTS response if
                     # the folder is empty.
-
-                    maxmsgid = long(imapobj.untagged_responses['EXISTS'][0])
+                    maxmsgid = 0
+                    for msgid in imapobj.untagged_responses['EXISTS']:
+                        maxmsgid = max(long(msgid), maxmsgid)
                     messagesToFetch = '1:%d' % maxmsgid;
                 except KeyError:
                     return
-- 
Nicolas Sebrecht




More information about the OfflineIMAP-project mailing list