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
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
from offlineimap import imaplib2 as imaplib
|
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 offlineimap.ui import getglobalui
|
||||||
from threading import *
|
from threading import *
|
||||||
import thread
|
import thread
|
||||||
@ -28,6 +28,7 @@ import base64
|
|||||||
|
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
from platform import system
|
from platform import system
|
||||||
|
from socket import gaierror
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# do we have a recent pykerberos?
|
# do we have a recent pykerberos?
|
||||||
@ -271,15 +272,28 @@ class IMAPServer:
|
|||||||
self.lastowner[imapobj] = thread.get_ident()
|
self.lastowner[imapobj] = thread.get_ident()
|
||||||
self.connectionlock.release()
|
self.connectionlock.release()
|
||||||
return imapobj
|
return imapobj
|
||||||
except:
|
except Exception, e:
|
||||||
"""If we are here then we did not succeed in getting a connection -
|
"""If we are here then we did not succeed in getting a
|
||||||
we should clean up and then re-raise the error..."""
|
connection - we should clean up and then re-raise the
|
||||||
|
error..."""
|
||||||
self.semaphore.release()
|
self.semaphore.release()
|
||||||
|
|
||||||
#Make sure that this can be retried the next time...
|
#Make sure that this can be retried the next time...
|
||||||
self.passworderror = None
|
self.passworderror = None
|
||||||
if(self.connectionlock.locked()):
|
if(self.connectionlock.locked()):
|
||||||
self.connectionlock.release()
|
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
|
raise
|
||||||
|
|
||||||
def connectionwait(self):
|
def connectionwait(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user