folder.IMAP: Improve dropped connection handling in quickchanged()
The quickchanged() function was not handling dropped connections yet. If IMAP4.select() throws a FOLDER_RETRY error, we will now discard the connection, reconnect and retry. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
5bcfbc1525
commit
fe4f385e2c
@ -89,27 +89,35 @@ class IMAPFolder(BaseFolder):
|
|||||||
# An IMAP folder has definitely changed if the number of
|
# An IMAP folder has definitely changed if the number of
|
||||||
# messages or the UID of the last message have changed. Otherwise
|
# messages or the UID of the last message have changed. Otherwise
|
||||||
# only flag changes could have occurred.
|
# only flag changes could have occurred.
|
||||||
imapobj = self.imapserver.acquireconnection()
|
retry = True # Should we attempt another round or exit?
|
||||||
try:
|
while retry:
|
||||||
# Primes untagged_responses
|
retry = False
|
||||||
imaptype, imapdata = imapobj.select(self.getfullname(), readonly = 1, force = 1)
|
imapobj = self.imapserver.acquireconnection()
|
||||||
# 1. Some mail servers do not return an EXISTS response
|
try:
|
||||||
# if the folder is empty. 2. ZIMBRA servers can return
|
# Select folder and get number of messages
|
||||||
# multiple EXISTS replies in the form 500, 1000, 1500,
|
restype, imapdata = imapobj.select(self.getfullname(), True,
|
||||||
# 1623 so check for potentially multiple replies.
|
True)
|
||||||
if imapdata == [None]:
|
except OfflineImapError, e:
|
||||||
return True
|
# retry on dropped connections, raise otherwise
|
||||||
maxmsgid = 0
|
self.imapserver.releaseconnection(imapobj, true)
|
||||||
for msgid in imapdata:
|
if e.severity == OfflineImapError.ERROR.FOLDER_RETRY:
|
||||||
maxmsgid = max(long(msgid), maxmsgid)
|
retry = True
|
||||||
|
else: raise
|
||||||
# Different number of messages than last time?
|
finally:
|
||||||
if maxmsgid != statusfolder.getmessagecount():
|
self.imapserver.releaseconnection(imapobj)
|
||||||
return True
|
# 1. Some mail servers do not return an EXISTS response
|
||||||
|
# if the folder is empty. 2. ZIMBRA servers can return
|
||||||
finally:
|
# multiple EXISTS replies in the form 500, 1000, 1500,
|
||||||
self.imapserver.releaseconnection(imapobj)
|
# 1623 so check for potentially multiple replies.
|
||||||
return False
|
if imapdata == [None]:
|
||||||
|
return True
|
||||||
|
maxmsgid = 0
|
||||||
|
for msgid in imapdata:
|
||||||
|
maxmsgid = max(long(msgid), maxmsgid)
|
||||||
|
# Different number of messages than last time?
|
||||||
|
if maxmsgid != statusfolder.getmessagecount():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def cachemessagelist(self):
|
def cachemessagelist(self):
|
||||||
maxage = self.config.getdefaultint("Account %s" % self.accountname,
|
maxage = self.config.getdefaultint("Account %s" % self.accountname,
|
||||||
|
Loading…
Reference in New Issue
Block a user