Display the fetchmailrc only when debug is enabled, related to #10

master
Pierre Jaury 8 years ago
parent bacc3b85d0
commit 0bde4fe05a

@ -36,7 +36,7 @@ def fetchmail(fetchmailrc):
return output return output
def run(connection, cursor): def run(connection, cursor, debug):
cursor.execute(""" cursor.execute("""
SELECT user_email, protocol, host, port, tls, username, password SELECT user_email, protocol, host, port, tls, username, password
FROM fetch FROM fetch
@ -55,17 +55,16 @@ def run(connection, cursor):
password=escape_rc_string(password), password=escape_rc_string(password),
options=options options=options
) )
if debug:
print(fetchmailrc)
try: try:
print(fetchmail(fetchmailrc)) print(fetchmail(fetchmailrc))
error_message = "" error_message = ""
except subprocess.CalledProcessError as error: except subprocess.CalledProcessError as error:
error_message = error.output.decode("utf8") error_message = error.output.decode("utf8")
# No mail is not an error # No mail is not an error
if not (error_message.startswith("fetchmail: No mail")): if not error_message.startswith("fetchmail: No mail"):
# activate the next statement to log the poll command print(error_message)
# Warning: the poll command contains the mailbox password
# in clear text
# print(fetchmailrc)
finally: finally:
cursor.execute(""" cursor.execute("""
UPDATE fetch SET error=?, last_check=datetime('now') UPDATE fetch SET error=?, last_check=datetime('now')
@ -76,10 +75,11 @@ def run(connection, cursor):
if __name__ == "__main__": if __name__ == "__main__":
debug = os.environ.get("DEBUG", None) == "True"
db_path = os.environ.get("DB_PATH", "/data/main.db") db_path = os.environ.get("DB_PATH", "/data/main.db")
connection = sqlite3.connect(db_path) connection = sqlite3.connect(db_path)
while True: while True:
cursor = connection.cursor() cursor = connection.cursor()
run(connection, cursor) run(connection, cursor, debug)
cursor.close() cursor.close()
time.sleep(int(os.environ.get("FETCHMAIL_DELAY", 60))) time.sleep(int(os.environ.get("FETCHMAIL_DELAY", 60)))

Loading…
Cancel
Save