From 0f45d89e34f85d02d46b06235acdb007b47de579 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Wed, 4 May 2011 16:45:25 +0200 Subject: [PATCH] Throw OfflineImapError on DNS error In case we misconfigured a server name or are otherwise offline, a socket.gaierror will be raised when attempting to connect. We catch that case and raise an OfflineImapError with severity ERROR.REPO, meaning we should stop syncing this account and continue with the next one. Signed-off-by: Sebastian Spaeth Signed-off-by: Nicolas Sebrecht --- offlineimap/imapserver.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index c474a01..6e58949 100644 --- a/offlineimap/imapserver.py +++ b/offlineimap/imapserver.py @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA from offlineimap import imaplib2 as imaplib -from offlineimap import imaplibutil, imaputil, threadutil +from offlineimap import imaplibutil, imaputil, threadutil, OfflineImapError from offlineimap.ui import getglobalui from threading import * import thread @@ -28,6 +28,7 @@ import base64 from StringIO import StringIO from platform import system +from socket import gaierror try: # do we have a recent pykerberos? @@ -271,16 +272,29 @@ class IMAPServer: self.lastowner[imapobj] = thread.get_ident() self.connectionlock.release() return imapobj - except: - """If we are here then we did not succeed in getting a connection - - we should clean up and then re-raise the error...""" + except Exception, e: + """If we are here then we did not succeed in getting a + connection - we should clean up and then re-raise the + error...""" self.semaphore.release() #Make sure that this can be retried the next time... self.passworderror = None if(self.connectionlock.locked()): self.connectionlock.release() - raise + + if type(e) == gaierror: + #DNS related errors. Abort Repo sync + severity = OfflineImapError.ERROR.REPO + #TODO: special error msg for e.errno == 2 "Name or service not known"? + reason = "Could not resolve name '%s' for repository "\ + "'%s'. Make sure you have configured the ser"\ + "ver name correctly and that you are online."\ + % (self.hostname, self.reposname) + raise OfflineImapError(reason, severity) + else: + # re-raise all other errors + raise def connectionwait(self): """Waits until there is a connection available. Note that between