Don't suppress exceptions occuring in Account.get_connection()

This commit is contained in:
Patrick Ulbrich
2015-04-18 16:44:23 +02:00
parent a0371a0ee2
commit d7ee148912
3 changed files with 18 additions and 23 deletions

View File

@@ -123,13 +123,12 @@ class Account:
self._conn = conn
except:
logging.error("Cannot connect to IMAP account '%s'." % self.server)
try:
if conn != None:
# conn.close() # allowed in SELECTED state only
conn.logout()
except:
pass
except: pass
raise # re-throw exception
return self._conn
@@ -164,12 +163,11 @@ class Account:
self._conn = conn
except:
logging.error("Cannot connect to POP account: '%s'." % self.server)
try:
if conn != None:
conn.quit()
except:
pass
except: pass
raise # re-throw exception
return self._conn

View File

@@ -29,9 +29,6 @@ from Mailnag.common.imaplib2 import AUTH
from Mailnag.common.exceptions import InvalidOperationException
class ConnectionException(Exception):
def __init__(self, message):
Exception.__init__(self, message)
#
# Idler class
#
@@ -49,10 +46,6 @@ class Idler(object):
self._conn = account.get_connection(use_existing = True)
self._disposed = False
if self._conn == None:
raise ConnectionException(
"Failed to establish a connection for account '%s'" % account.name)
# Need to get out of AUTH mode of fresh connections.
if self._conn.state == AUTH:
self._select(self._conn, account)
@@ -136,15 +129,15 @@ class Idler(object):
while (self._conn == None) and (not self._event.isSet()):
logging.info("Trying to reconnect Idler thread for account '%s'." % self._account.name)
self._conn = self._account.get_connection(use_existing = False)
if self._conn == None:
logging.error("Failed to reconnect Idler thread for account '%s'." % self._account.name)
try:
self._conn = self._account.get_connection(use_existing = False)
logging.info("Successfully reconnected Idler thread for account '%s'." % self._account.name)
except Exception as ex:
logging.error("Failed to reconnect Idler thread for account '%s' (%s)." % (self._account.name, ex))
logging.info("Trying to reconnect Idler thread for account '%s' in %s minutes" %
(self._account.name, str(self.RECONNECT_RETRY_INTERVAL)))
self._wait(60 * self.RECONNECT_RETRY_INTERVAL) # don't hammer the server
else:
logging.info("Successfully reconnected Idler thread for account '%s'." % self._account.name)
if self._conn != None:
self._select(self._conn, self._account)
@@ -181,7 +174,7 @@ class IdlerRunner:
idler.start()
self._idlerlist.append(idler)
except Exception as ex:
logging.error("Error: Failed to create an idler thread for account '%s'" % acc.name)
logging.error("Error: Failed to create an idler thread for account '%s' (%s)" % (acc.name, ex))
def dispose(self):

View File

@@ -61,10 +61,14 @@ class MailCollector:
for acc in self._accounts:
# get server connection for this account
conn = acc.get_connection(use_existing = True)
if conn == None:
conn = None
try:
conn = acc.get_connection(use_existing = True)
except Exception as ex:
logging.error("Failed to connect to account '%s' (%s)." % (acc.name, ex))
continue
elif acc.imap: # IMAP
if acc.imap: # IMAP
if len(acc.folders) == 0:
folder_list = [ 'INBOX' ]
else: