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 <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
bc004a911a
commit
0f45d89e34
@ -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,15 +272,28 @@ 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()
|
||||
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user