From 51c7b29c2f2ae154cd85b6f4109ada7b04687ce7 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Sat, 9 Jul 2022 23:04:10 +0200 Subject: Do not use implicit debugging --- ayatanawebmail/application.py | 50 +++++++++++++++++++++++++++++-------------- ayatanawebmail/idler.py | 13 ++++++++--- ayatanawebmail/imaplib2.py | 2 +- 3 files changed, 45 insertions(+), 20 deletions(-) (limited to 'ayatanawebmail') diff --git a/ayatanawebmail/application.py b/ayatanawebmail/application.py index ea30d4a..eb9ad33 100755 --- a/ayatanawebmail/application.py +++ b/ayatanawebmail/application.py @@ -370,9 +370,9 @@ class SessionBus(dbus.service.Object): class Connection(object): - def __init__(self, bDebug, host, port, login, passwd, folder, fnIdle, strInbox): + def __init__(self, sDebug, host, port, login, passwd, folder, fnIdle, strInbox): - self.bDebug = bDebug + self.sDebug = sDebug self.strHost = host self.nPort = port self.strLogin = login @@ -407,19 +407,21 @@ class Connection(object): self.oImap = None - logger.info('"{0}:{1}" has been cleaned up.'.format(self.strLogin, self.strFolder)) + if self.sDebug == 'info': + + logger.info('"{0}:{1}" has been cleaned up.'.format(self.strLogin, self.strFolder)) def connect(self): try: - self.oImap = imaplib.IMAP4_SSL(self.strHost, self.nPort, debug=int(self.bDebug)*5) + self.oImap = imaplib.IMAP4_SSL(self.strHost, self.nPort, debug=int(self.sDebug == 'debug')*5) except Exception as e: logger.warning('"{0}:{1}" IMAP4_SSL failed, trying IMAP4.'.format(self.strLogin, self.strFolder)) - self.oImap = imaplib.IMAP4(self.strHost, self.nPort, debug=int(self.bDebug)*5) + self.oImap = imaplib.IMAP4(self.strHost, self.nPort, debug=int(self.sDebug)*5) if 'STARTTLS' in self.oImap.capabilities: self.oImap.starttls() @@ -443,9 +445,12 @@ class Connection(object): else: - logger.info('"{0}:{1}" is now connected.'.format(self.strLogin, self.strFolder)) + if self.sDebug == 'info': + + logger.info('"{0}:{1}" is now connected.'.format(self.strLogin, self.strFolder)) + self.fnIdle(self, False) - self.oIdler = Idler(self, self.fnIdle, logger) + self.oIdler = Idler(self, self.fnIdle, logger, self.sDebug) self.oIdler.start() def isOpen(self): @@ -466,9 +471,9 @@ class Message(object): class AyatanaWebmail(object): - def __init__(self, bDebug): + def __init__(self, sDebug): - self.bDebug = bDebug + self.sDebug = sDebug self.dlgSettings = None self.nLastMailTimestamp = 0 self.first_run = True @@ -506,7 +511,9 @@ class AyatanaWebmail(object): if not bGoing: - logger.info('The System has resumed from sleep, reconnecting accounts.') + if self.sDebug == 'info': + + logger.info('The System has resumed from sleep, reconnecting accounts.') for oConnection in self.lstConnections: @@ -519,7 +526,10 @@ class AyatanaWebmail(object): if not checkNetwork(): - logger.info('No network connection, checking in 1 minute.') + if self.sDebug == 'info': + + logger.info('No network connection, checking in 1 minute.') + self.bNoNetwork = True self.bIdlerRunning = False @@ -710,7 +720,7 @@ class AyatanaWebmail(object): g_lstAccounts.append({'Host': strHost, 'Port': nPort, 'Login': strLogin, 'Passwd': strPasswd, 'Folders': strFolders, 'Home': strHome, 'Compose': strCompose, 'Inbox': strInbox, 'Sent': strSent, 'InboxAppend': strInboxAppend}) for strFolder in strFolders.split('\t'): - self.lstConnections.append(Connection(self.bDebug, strHost, nPort, strLogin, strPasswd, strFolder, self.onIdle, strInbox + strInboxAppend)) + self.lstConnections.append(Connection(self.sDebug, strHost, nPort, strLogin, strPasswd, strFolder, self.onIdle, strInbox + strInboxAppend)) def createKeyringItem(self, ind, update=False): @@ -805,7 +815,7 @@ class AyatanaWebmail(object): pass for strFolder in strFolders.split('\t'): - self.lstConnections.append(Connection(self.bDebug, dct['Host'], nPort, dct['Login'], dct['Passwd'], strFolder, self.onIdle, dct['Inbox'] + dct['InboxAppend'])) + self.lstConnections.append(Connection(self.sDebug, dct['Host'], nPort, dct['Login'], dct['Passwd'], strFolder, self.onIdle, dct['Inbox'] + dct['InboxAppend'])) def appendToIndicator(self, message): @@ -831,7 +841,11 @@ class AyatanaWebmail(object): oConnection.bConnecting = True GLib.timeout_add_seconds(1, oConnection.close) - logger.info('"{0}:{1}" will try to reconnect in 1 minute.'.format(oConnection.strLogin, oConnection.strFolder)) + + if self.sDebug == 'info': + + logger.info('"{0}:{1}" will try to reconnect in 1 minute.'.format(oConnection.strLogin, oConnection.strFolder)) + GLib.timeout_add_seconds(60, self.connect, [oConnection]) return @@ -1057,7 +1071,9 @@ class AyatanaWebmail(object): def connect(self, lstConnections): - logger.info('Checking network...') + if self.sDebug == 'info': + + logger.info('Checking network...') if not checkNetwork(): @@ -1065,7 +1081,9 @@ class AyatanaWebmail(object): if (lstConnections): - logger.info('Network connection active, connecting...') + if self.sDebug == 'info': + + logger.info('Network connection active, connecting...') for oConnection in lstConnections: diff --git a/ayatanawebmail/idler.py b/ayatanawebmail/idler.py index b6b63b4..33b4313 100755 --- a/ayatanawebmail/idler.py +++ b/ayatanawebmail/idler.py @@ -6,7 +6,7 @@ from threading import * class Idler(object): - def __init__(self, oConnection, fnCallback, oLogger): + def __init__(self, oConnection, fnCallback, oLogger, sDebug): self.oThread = Thread(target=self.idle) self.oConnection = oConnection @@ -15,6 +15,7 @@ class Idler(object): self.bNeedSync = False self.oLogger = oLogger self.bAborted = False + self.sDebug = sDebug def start(self): @@ -48,7 +49,10 @@ class Idler(object): if (lstArgs[2] != None) and (lstArgs[2][0] is self.oConnection.oImap.abort): - self.oLogger.info('"{0}:{1}" has been closed by the server.'.format(self.oConnection.strLogin, self.oConnection.strFolder)) + if self.sDebug == 'info': + + self.oLogger.info('"{0}:{1}" has been closed by the server.'.format(self.oConnection.strLogin, self.oConnection.strFolder)) + self.bAborted = True else: @@ -61,7 +65,10 @@ class Idler(object): while not self.oConnection.isOpen(): - self.oLogger.info('"{0}:{1}" IDLE is waiting for a connection.'.format(self.oConnection.strLogin, self.oConnection.strFolder)) + if self.sDebug == 'info': + + self.oLogger.info('"{0}:{1}" IDLE is waiting for a connection.'.format(self.oConnection.strLogin, self.oConnection.strFolder)) + time.sleep(10) self.oConnection.oImap.idle(callback=callback, timeout=600) diff --git a/ayatanawebmail/imaplib2.py b/ayatanawebmail/imaplib2.py index c915b7a..aa4a1d4 100755 --- a/ayatanawebmail/imaplib2.py +++ b/ayatanawebmail/imaplib2.py @@ -6,7 +6,7 @@ try: from ayatanawebmail.appdata import APPDEBUG - if APPDEBUG: + if len(APPDEBUG) == 1 and APPDEBUG[0] == 'debug': m_bDebug = True -- cgit v1.2.3