[PATCHv2 2/3] imaplibutil: Have SELECT throw an OfflineImapError when the connection died
Sebastian Spaeth
Sebastian at SSpaeth.de
Thu Sep 1 10:00:59 BST 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 | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py
index fa3a303..529af6f 100644
--- a/offlineimap/imaplibutil.py
+++ b/offlineimap/imaplibutil.py
@@ -49,7 +49,14 @@ 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:
+ # self.abort is raised when we are supposed to retry
+ errstr = "Server '%s' closed connection, error on SELECT '%s'. Ser"\
+ "ver said: %s" % (self.host, mailbox, e.args[0])
+ severity = OfflineImapError.ERROR.FOLDER_RETRY
+ raise OfflineImapError(errstr, severity)
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