mirror of
https://github.com/Mailu/Mailu.git
synced 2025-01-18 03:21:36 +02:00
Merge pull request #127 from pe2mbs/master
Implement a first version of the fetchmail keep option
This commit is contained in:
commit
508a2a7516
@ -68,6 +68,8 @@ RELAYHOST=
|
|||||||
|
|
||||||
# Fetchmail delay
|
# Fetchmail delay
|
||||||
FETCHMAIL_DELAY=600
|
FETCHMAIL_DELAY=600
|
||||||
|
# Set this to True when you want to keep the mail on remote server as well.
|
||||||
|
FETCHMAIL_KEEP=False
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
# Developers
|
# Developers
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ pip-selfcheck.json
|
|||||||
/data
|
/data
|
||||||
/docker-compose.mac.yml
|
/docker-compose.mac.yml
|
||||||
/docker-compose.yml
|
/docker-compose.yml
|
||||||
|
/.idea
|
@ -36,7 +36,7 @@ def fetchmail(fetchmailrc):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def run(connection, cursor, debug):
|
def run(connection, cursor, keep, 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
|
||||||
@ -44,8 +44,9 @@ def run(connection, cursor, debug):
|
|||||||
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 fetchall antispam 501, 504, 550, 553, 554"
|
options = "options antispam 501, 504, 550, 553, 554"
|
||||||
options += " ssl" if tls else ""
|
options += " ssl" if tls else ""
|
||||||
|
options += " keep" if keep else " fetchall"
|
||||||
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,
|
||||||
@ -56,15 +57,21 @@ def run(connection, cursor, debug):
|
|||||||
options=options
|
options=options
|
||||||
)
|
)
|
||||||
if debug:
|
if debug:
|
||||||
print(fetchmailrc)
|
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"):
|
||||||
print(error_message)
|
print( error_message )
|
||||||
|
|
||||||
|
user_info = "for %s at %s" % ( user_email, host )
|
||||||
|
# Number of messages seen is not a error as well
|
||||||
|
if "messages" in error_message and "(seen " in error_message and \
|
||||||
|
user_info in error_message:
|
||||||
|
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')
|
||||||
@ -76,10 +83,12 @@ def run(connection, cursor, debug):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
debug = os.environ.get("DEBUG", None) == "True"
|
debug = os.environ.get("DEBUG", None) == "True"
|
||||||
|
keep = os.environ.get("FETCHMAIL_KEEP", 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, debug)
|
run(connection, cursor, keep, debug)
|
||||||
cursor.close()
|
cursor.close()
|
||||||
time.sleep(int(os.environ.get("FETCHMAIL_DELAY", 60)))
|
time.sleep(int(os.environ.get("FETCHMAIL_DELAY", 60)))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user