From 993492bc781953621cd5fd323893396ac7bd5e24 Mon Sep 17 00:00:00 2001 From: Otto Schreibke Date: Wed, 26 Oct 2016 13:21:02 +0200 Subject: [PATCH 1/3] Update to poll command; Upgrade logging - issue #88 --- fetchmail/fetchmail.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fetchmail/fetchmail.py b/fetchmail/fetchmail.py index 8a81243c..42e7ca73 100755 --- a/fetchmail/fetchmail.py +++ b/fetchmail/fetchmail.py @@ -14,16 +14,15 @@ fetchmail -N \ -f {} """ - RC_LINE = """ -poll "{host}" proto {protocol} port {port} +poll "{host}" proto {protocol} port {port} user "{username}" password "{password}" + is "{user_email}" smtphost "smtp" - smtpname "{user_email}" {options} + sslproto 'AUTO' """ - def escape_rc_string(arg): return arg.replace("\\", "\\\\").replace('"', '\\"') @@ -45,7 +44,8 @@ def run(connection, cursor): for line in cursor.fetchall(): fetchmailrc = "" user_email, protocol, host, port, tls, username, password = line - options = "options ssl" if tls else "" + options = "options fetchall antispam 501, 504, 550, 553, 554" + options += " ssl" if tls else "" fetchmailrc += RC_LINE.format( user_email=escape_rc_string(user_email), protocol=protocol, @@ -60,7 +60,10 @@ def run(connection, cursor): error_message = "" except subprocess.CalledProcessError as error: error_message = error.output.decode("utf8") - print(error.output) + # No mail is not an error + if not (error_message.startswith("fetchmail: No mail")): + print(fetchmailrc) + print(error_message) finally: cursor.execute(""" UPDATE fetch SET error=?, last_check=datetime('now') @@ -74,7 +77,7 @@ if __name__ == "__main__": db_path = os.environ.get("DB_PATH", "/data/freeposte.db") connection = sqlite3.connect(db_path) while True: - time.sleep(int(os.environ.get("FETCHMAIL_DELAY", 10))) cursor = connection.cursor() run(connection, cursor) cursor.close() + time.sleep(int(os.environ.get("FETCHMAIL_DELAY", 60))) From 42cfc50bd87f93a56c8078c2cedd6a007f3d40f7 Mon Sep 17 00:00:00 2001 From: Otto Schreibke Date: Wed, 26 Oct 2016 13:38:19 +0200 Subject: [PATCH 2/3] run image as user fetchmail --- fetchmail/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fetchmail/Dockerfile b/fetchmail/Dockerfile index 7c7d9f3d..64b014f1 100644 --- a/fetchmail/Dockerfile +++ b/fetchmail/Dockerfile @@ -7,4 +7,6 @@ RUN apk add --update \ COPY fetchmail.py /fetchmail.py +USER fetchmail + CMD ["/fetchmail.py"] From 727a98a1e05c427ec931490938d9661b05485c5c Mon Sep 17 00:00:00 2001 From: Otto Schreibke Date: Thu, 27 Oct 2016 13:57:49 +0200 Subject: [PATCH 3/3] annotate and deactivate logging of the poll command - issue #88 --- fetchmail/fetchmail.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fetchmail/fetchmail.py b/fetchmail/fetchmail.py index 42e7ca73..ba942dc3 100755 --- a/fetchmail/fetchmail.py +++ b/fetchmail/fetchmail.py @@ -62,8 +62,11 @@ def run(connection, cursor): error_message = error.output.decode("utf8") # No mail is not an error if not (error_message.startswith("fetchmail: No mail")): + # activate the next statement to log the poll command + # Warning: the poll command contains the mailbox password + # in clear text + #print(fetchmailrc) print(fetchmailrc) - print(error_message) finally: cursor.execute(""" UPDATE fetch SET error=?, last_check=datetime('now')