[PATCH 3/3] Catch terminated connections on the IDLE SELECT operation
Sebastian Spaeth
Sebastian at SSpaeth.de
Thu Sep 1 09:23:47 BST 2011
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 at gmail.com".
Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
offlineimap/imapserver.py | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index 3ce751c..9ec1fb1 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -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,22 @@ 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:
+ 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,))
--
1.7.4.1
More information about the OfflineIMAP-project
mailing list