From f65e2fc469a08996c79864efef9fb227568218c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0brahim=20Akyel?= Date: Fri, 11 Mar 2022 16:58:50 +0300 Subject: [PATCH] Feature: Marking "Read" spam mails --- .../mailu/internal/templates/default.sieve | 2 ++ core/admin/mailu/manage.py | 2 +- core/admin/mailu/models.py | 1 + core/admin/mailu/ui/forms.py | 1 + .../mailu/ui/templates/user/settings.html | 1 + .../migrations/versions/8f9ea78776f4_.py | 21 +++++++++++++++++++ docs/cli.rst | 2 ++ 7 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 core/admin/migrations/versions/8f9ea78776f4_.py diff --git a/core/admin/mailu/internal/templates/default.sieve b/core/admin/mailu/internal/templates/default.sieve index a29e7aba..f08c19bb 100644 --- a/core/admin/mailu/internal/templates/default.sieve +++ b/core/admin/mailu/internal/templates/default.sieve @@ -21,7 +21,9 @@ if header :index 2 :matches "Received" "from * by * for <*>; *" {% if user.spam_enabled %} if spamtest :percent :value "gt" :comparator "i;ascii-numeric" "{{ user.spam_threshold }}" { + {% if user.spam_mark_as_read %} setflag "\\seen"; + {% endif %} fileinto :create "Junk"; stop; } diff --git a/core/admin/mailu/manage.py b/core/admin/mailu/manage.py index 937c9f49..098f1283 100644 --- a/core/admin/mailu/manage.py +++ b/core/admin/mailu/manage.py @@ -207,7 +207,7 @@ def config_update(verbose=False, delete_objects=False): 'enable_imap', 'enable_pop', 'forward_enabled', 'forward_destination', 'reply_enabled', 'reply_subject', 'reply_body', 'displayed_name', - 'spam_enabled', 'email', 'spam_threshold') + 'spam_enabled', 'spam_mark_as_read', 'email', 'spam_threshold') for user_config in users: if verbose: print(str(user_config)) diff --git a/core/admin/mailu/models.py b/core/admin/mailu/models.py index 48b47ea5..bf897d79 100644 --- a/core/admin/mailu/models.py +++ b/core/admin/mailu/models.py @@ -505,6 +505,7 @@ class User(Base, Email): # Settings displayed_name = db.Column(db.String(160), nullable=False, default='') spam_enabled = db.Column(db.Boolean, nullable=False, default=True) + spam_mark_as_read = db.Column(db.Boolean, nullable=False, default=True) spam_threshold = db.Column(db.Integer, nullable=False, default=80) # Flask-login attributes diff --git a/core/admin/mailu/ui/forms.py b/core/admin/mailu/ui/forms.py index 24d6f899..34436a29 100644 --- a/core/admin/mailu/ui/forms.py +++ b/core/admin/mailu/ui/forms.py @@ -100,6 +100,7 @@ class UserSignupFormCaptcha(UserSignupForm): class UserSettingsForm(flask_wtf.FlaskForm): displayed_name = fields.StringField(_('Displayed name')) spam_enabled = fields.BooleanField(_('Enable spam filter')) + spam_mark_as_read = fields.BooleanField(_('Enable marking spam mails as read')) spam_threshold = fields_.IntegerSliderField(_('Spam filter tolerance')) forward_enabled = fields.BooleanField(_('Enable forwarding')) forward_keep = fields.BooleanField(_('Keep a copy of the emails')) diff --git a/core/admin/mailu/ui/templates/user/settings.html b/core/admin/mailu/ui/templates/user/settings.html index c1eb47f3..438f3b88 100644 --- a/core/admin/mailu/ui/templates/user/settings.html +++ b/core/admin/mailu/ui/templates/user/settings.html @@ -18,6 +18,7 @@ {%- call macros.card(title=_("Antispam")) %} {%- call macros.fieldset(field=form.spam_enabled, enabled=user.spam_enabled) %} + {{ macros.form_field(form.spam_mark_as_read) }} {{ macros.form_field(form.spam_threshold, step=1, max=100, prepend=' / 100') }} {%- endcall %} diff --git a/core/admin/migrations/versions/8f9ea78776f4_.py b/core/admin/migrations/versions/8f9ea78776f4_.py new file mode 100644 index 00000000..779853d8 --- /dev/null +++ b/core/admin/migrations/versions/8f9ea78776f4_.py @@ -0,0 +1,21 @@ +"""empty message + +Revision ID: 8f9ea78776f4 +Revises: 3b7eee912b41 +Create Date: 2022-03-11 13:53:08.996055 + +""" + +# revision identifiers, used by Alembic. +revision = '8f9ea78776f4' +down_revision = '3b7eee912b41' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('user', sa.Column('spam_mark_as_read', sa.Boolean(), nullable=False)) + +def downgrade(): + op.drop_column('user', 'spam_mark_as_read') diff --git a/docs/cli.rst b/docs/cli.rst index b407c6a3..cc596947 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -112,6 +112,7 @@ following are additional parameters that could be defined for users: * reply_body * displayed_name * spam_enabled +* spam_mark_as_read * spam_threshold Alias @@ -293,6 +294,7 @@ This is a complete YAML template with all additional parameters that can be defi reply_startdate: '1900-01-01' reply_subject: '' spam_enabled: true + spam_mark_as_read: true spam_threshold: 80 tokens: - id: 1