Add a keep option per fetch, fixes #60
This commit is contained in:
@@ -119,6 +119,7 @@ class FetchForm(flask_wtf.FlaskForm):
|
|||||||
tls = fields.BooleanField(_('Enable TLS'))
|
tls = fields.BooleanField(_('Enable TLS'))
|
||||||
username = fields.StringField(_('Username'))
|
username = fields.StringField(_('Username'))
|
||||||
password = fields.StringField(_('Password'))
|
password = fields.StringField(_('Password'))
|
||||||
|
keep = fields.BooleanField(_('Keep emails on the server'))
|
||||||
submit = fields.SubmitField(_('Submit'))
|
submit = fields.SubmitField(_('Submit'))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -222,5 +222,6 @@ class Fetch(Base):
|
|||||||
tls = db.Column(db.Boolean(), nullable=False)
|
tls = db.Column(db.Boolean(), nullable=False)
|
||||||
username = db.Column(db.String(255), nullable=False)
|
username = db.Column(db.String(255), nullable=False)
|
||||||
password = db.Column(db.String(255), nullable=False)
|
password = db.Column(db.String(255), nullable=False)
|
||||||
|
keep = db.Column(db.Boolean(), nullable=False)
|
||||||
last_check = db.Column(db.DateTime, nullable=True)
|
last_check = db.Column(db.DateTime, nullable=True)
|
||||||
error = db.Column(db.String(1023), nullable=True)
|
error = db.Column(db.String(1023), nullable=True)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
<th>{% trans %}Actions{% endtrans %}</th>
|
<th>{% trans %}Actions{% endtrans %}</th>
|
||||||
<th>{% trans %}Endpoint{% endtrans %}</th>
|
<th>{% trans %}Endpoint{% endtrans %}</th>
|
||||||
<th>{% trans %}Username{% endtrans %}</th>
|
<th>{% trans %}Username{% endtrans %}</th>
|
||||||
|
<th>{% trans %}Keep emails{% endtrans %}</th>
|
||||||
<th>{% trans %}Last check{% endtrans %}</th>
|
<th>{% trans %}Last check{% endtrans %}</th>
|
||||||
<th>{% trans %}Status{% endtrans %}</th>
|
<th>{% trans %}Status{% endtrans %}</th>
|
||||||
<th>{% trans %}Created{% endtrans %}</th>
|
<th>{% trans %}Created{% endtrans %}</th>
|
||||||
@@ -32,6 +33,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>{{ fetch.protocol }}{{ 's' if fetch.tls else '' }}://{{ fetch.host }}:{{ fetch.port }}</td>
|
<td>{{ fetch.protocol }}{{ 's' if fetch.tls else '' }}://{{ fetch.host }}:{{ fetch.port }}</td>
|
||||||
<td>{{ fetch.username }}</td>
|
<td>{{ fetch.username }}</td>
|
||||||
|
<td>{% if fetch.keep %}{% trans %}yes{% endtrans %}{% else %}{% trans %}no{% endtrans %}{% endif %}</td>
|
||||||
<td>{{ fetch.last_check or '-' }}</td>
|
<td>{{ fetch.last_check or '-' }}</td>
|
||||||
<td>{{ fetch.error or '-' }}</td>
|
<td>{{ fetch.error or '-' }}</td>
|
||||||
<td>{{ fetch.created_at }}</td>
|
<td>{{ fetch.created_at }}</td>
|
||||||
|
|||||||
32
admin/migrations/versions/3f6994568962_.py
Normal file
32
admin/migrations/versions/3f6994568962_.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
""" Add keep as an option in fetches
|
||||||
|
|
||||||
|
Revision ID: 3f6994568962
|
||||||
|
Revises: 2335c80a6bc3
|
||||||
|
Create Date: 2017-02-02 22:31:00.719703
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '3f6994568962'
|
||||||
|
down_revision = '2335c80a6bc3'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
from mailu import app, db
|
||||||
|
from mailu.admin import models
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column('fetch', sa.Column('keep', sa.Boolean(), nullable=False, server_default=sa.sql.expression.false()))
|
||||||
|
# also apply the current config value if set
|
||||||
|
if app.config.get("FETCHMAIL_KEEP", "False") == "True":
|
||||||
|
for fetch in models.Fetch.query.all():
|
||||||
|
fetch.keep = True
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
with op.batch_alter_table('fetch') as batch:
|
||||||
|
batch.drop_column('keep')
|
||||||
@@ -37,14 +37,14 @@ def fetchmail(fetchmailrc):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
def run(connection, cursor, keep, debug):
|
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, keep
|
||||||
FROM fetch
|
FROM fetch
|
||||||
""")
|
""")
|
||||||
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, keep = line
|
||||||
options = "options 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"
|
options += " keep" if keep else " fetchall"
|
||||||
@@ -83,11 +83,10 @@ def run(connection, cursor, keep, 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, keep, debug)
|
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)))
|
||||||
|
|||||||
Reference in New Issue
Block a user