[PATCH 2/3] imaplibutil: Have SELECT throw an OfflineImapError when	the connection died
    Sebastian Spaeth 
    Sebastian at SSpaeth.de
       
    Thu Sep  1 08:23:46 UTC 2011
    
    
  
Imapserver.acquireconnection will succeed even whent the server connection
has been terminated and the first IMAP operation will throw an exception.
Often this is the folder SELECT operation (e.g. after an idle timeout), as
has been reported by John Wiegley. Catch this case and throw an
OfflineImapError with severity FOLDER_RETRY to notify consumers that they
are supposed to retry.
Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/imaplibutil.py |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py
index fa3a303..3ed50cd 100644
--- a/offlineimap/imaplibutil.py
+++ b/offlineimap/imaplibutil.py
@@ -49,7 +49,17 @@ class UsefulIMAPMixIn:
             return
         # Wipe out all old responses, to maintain semantics with old imaplib2
         del self.untagged_responses[:]
-        result = self.__class__.__bases__[1].select(self, mailbox, readonly)
+        try:
+            result = self.__class__.__bases__[1].select(self, mailbox, readonly)
+        except self.abort, e:
+            if e.args[0] == 'connection terminated' or \
+                    e.args[0] == 'connection closed':
+                errstr = "Server '%s' closed connection, error SELECTing "\
+                         "'%s'" % (self.host, mailbox)
+                severity = OfflineImapError.ERROR.FOLDER_RETRY
+                raise OfflineImapError(errstr, severity) 
+            else:
+                raise e
         if result[0] != 'OK':
             #in case of error, bail out with OfflineImapError
             errstr = "Error SELECTing mailbox '%s', server reply:\n%s" %\
-- 
1.7.4.1
    
    
More information about the OfflineIMAP-project
mailing list