Catch terminated connections on the IDLE SELECT operation

Handle the case gracefully where a server has closed an IMAP connection
that we want to use for IDLEing. Simply have it dropped and get a new one
in this case. THis should get rid of the errors reported by John Wiegley
in mail id:"m2sjohd16t.fsf@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:
Sebastian Spaeth 2011-09-01 11:01:00 +02:00 committed by Nicolas Sebrecht
parent 61fffd5c5f
commit f1555ec893

View File

@ -26,7 +26,7 @@ import socket
import base64
import time
import errno
from sys import exc_info
from socket import gaierror
try:
from ssl import SSLError, cert_time_to_seconds
@ -456,6 +456,7 @@ class IdleThread(object):
self.parent = parent
self.folder = folder
self.event = Event()
self.ui = getglobalui()
if folder is None:
self.thread = Thread(target=self.noop)
else:
@ -505,13 +506,24 @@ class IdleThread(object):
self.imapaborted = True
self.stop()
imapobj = self.parent.acquireconnection()
imapobj.select(self.folder)
success = False # successfully selected FOLDER?
while not success:
imapobj = self.parent.acquireconnection()
try:
imapobj.select(self.folder)
except OfflineImapError, e:
if e.severity == OfflineImapError.ERROR.FOLDER_RETRY:
# Connection closed, release connection and retry
self.ui.error(e, exc_info()[2])
self.parent.releaseconnection(imapobj)
else:
raise e
else:
success = True
if "IDLE" in imapobj.capabilities:
imapobj.idle(callback=callback)
else:
ui = getglobalui()
ui.warn("IMAP IDLE not supported on connection to %s."
self.ui.warn("IMAP IDLE not supported on connection to %s."
"Falling back to old behavior: sleeping until next"
"refresh cycle."
%(imapobj.identifier,))