Update to poll command; Upgrade logging - issue #88
This commit is contained in:
@@ -14,16 +14,15 @@ fetchmail -N \
|
|||||||
-f {}
|
-f {}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
RC_LINE = """
|
RC_LINE = """
|
||||||
poll "{host}" proto {protocol} port {port}
|
poll "{host}" proto {protocol} port {port}
|
||||||
user "{username}" password "{password}"
|
user "{username}" password "{password}"
|
||||||
|
is "{user_email}"
|
||||||
smtphost "smtp"
|
smtphost "smtp"
|
||||||
smtpname "{user_email}"
|
|
||||||
{options}
|
{options}
|
||||||
|
sslproto 'AUTO'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def escape_rc_string(arg):
|
def escape_rc_string(arg):
|
||||||
return arg.replace("\\", "\\\\").replace('"', '\\"')
|
return arg.replace("\\", "\\\\").replace('"', '\\"')
|
||||||
|
|
||||||
@@ -45,7 +44,8 @@ def run(connection, cursor):
|
|||||||
for line in cursor.fetchall():
|
for line in cursor.fetchall():
|
||||||
fetchmailrc = ""
|
fetchmailrc = ""
|
||||||
user_email, protocol, host, port, tls, username, password = line
|
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(
|
fetchmailrc += RC_LINE.format(
|
||||||
user_email=escape_rc_string(user_email),
|
user_email=escape_rc_string(user_email),
|
||||||
protocol=protocol,
|
protocol=protocol,
|
||||||
@@ -60,7 +60,10 @@ def run(connection, cursor):
|
|||||||
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")
|
||||||
print(error.output)
|
# No mail is not an error
|
||||||
|
if not (error_message.startswith("fetchmail: No mail")):
|
||||||
|
print(fetchmailrc)
|
||||||
|
print(error_message)
|
||||||
finally:
|
finally:
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
UPDATE fetch SET error=?, last_check=datetime('now')
|
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")
|
db_path = os.environ.get("DB_PATH", "/data/freeposte.db")
|
||||||
connection = sqlite3.connect(db_path)
|
connection = sqlite3.connect(db_path)
|
||||||
while True:
|
while True:
|
||||||
time.sleep(int(os.environ.get("FETCHMAIL_DELAY", 10)))
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
run(connection, cursor)
|
run(connection, cursor)
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
time.sleep(int(os.environ.get("FETCHMAIL_DELAY", 60)))
|
||||||
|
|||||||
Reference in New Issue
Block a user