understand multiple EXISTS replies from servers like Zimbra

Lars Thalmann <web@larsthalmann.com> writes:

> 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

Signed-off-by: Knut Anders Hatlen <kahatlen@gmail.com>
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Knut Anders Hatlen 2011-01-20 20:02:38 +01:00 committed by Nicolas Sebrecht
parent 068df7d026
commit 9ad1810e43

View File

@ -85,9 +85,13 @@ class IMAPFolder(BaseFolder):
# Primes untagged_responses
imapobj.select(self.getfullname(), readonly = 1, force = 1)
try:
# Some mail servers do not return an EXISTS response if
# the folder is empty.
maxmsgid = long(imapobj.untagged_responses['EXISTS'][0])
# 1. Some mail servers do not return an EXISTS response
# if the folder is empty. 2. ZIMBRA servers can return
# multiple EXISTS replies in the form 500, 1000, 1500,
# 1623 so check for potentially multiple replies.
maxmsgid = 0
for msgid in imapobj.untagged_responses['EXISTS']:
maxmsgid = max(long(msgid), maxmsgid)
except KeyError:
return True
@ -167,10 +171,13 @@ class IMAPFolder(BaseFolder):
return
else:
try:
# Some mail servers do not return an EXISTS response if
# the folder is empty.
maxmsgid = long(imapobj.untagged_responses['EXISTS'][0])
# 1. Some mail servers do not return an EXISTS response
# if the folder is empty. 2. ZIMBRA servers can return
# multiple EXISTS replies in the form 500, 1000, 1500,
# 1623 so check for potentially multiple replies.
maxmsgid = 0
for msgid in imapobj.untagged_responses['EXISTS']:
maxmsgid = max(long(msgid), maxmsgid)
messagesToFetch = '1:%d' % maxmsgid;
except KeyError:
return