You've already forked Mailu
mirror of
https://github.com/Mailu/Mailu.git
synced 2025-08-10 22:31:47 +02:00
Merge pull request #73 from diresi/junk_filter
dovecot: use rspamd X-Spamd-Result percentage to evaluate spam
This commit is contained in:
@@ -143,7 +143,7 @@ class User(Email):
|
||||
# Settings
|
||||
displayed_name = db.Column(db.String(160), nullable=False, default="")
|
||||
spam_enabled = db.Column(db.Boolean(), nullable=False, default=True)
|
||||
spam_threshold = db.Column(db.Numeric(), nullable=False, default=10.0)
|
||||
spam_threshold = db.Column(db.Numeric(), nullable=False, default=80.0)
|
||||
|
||||
# Flask-login attributes
|
||||
is_authenticated = True
|
||||
|
@@ -13,8 +13,8 @@ User settings
|
||||
{{ form.hidden_tag() }}
|
||||
{{ macros.form_field(form.displayed_name) }}
|
||||
{{ macros.form_field(form.spam_enabled) }}
|
||||
{{ macros.form_field(form.spam_threshold, step=1, max=15,
|
||||
prepend='<span class="input-group-addon"><span id="threshold">'+(form.spam_threshold.data).__int__().__str__()+'</span> / 15</span>',
|
||||
{{ macros.form_field(form.spam_threshold, step=1, max=100,
|
||||
prepend='<span class="input-group-addon"><span id="threshold">'+(form.spam_threshold.data).__int__().__str__()+'</span> / 100</span>',
|
||||
oninput='$("#threshold").text(this.value);') }}
|
||||
{{ macros.form_field(form.submit) }}
|
||||
</form>
|
||||
|
37
admin/migrations/versions/27ae2f102682_.py
Normal file
37
admin/migrations/versions/27ae2f102682_.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""spam_threshold in percent
|
||||
|
||||
Revision ID: 27ae2f102682
|
||||
Revises: dc8c25cf5b98
|
||||
Create Date: 2016-09-30 08:06:15.025190
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '27ae2f102682'
|
||||
down_revision = 'dc8c25cf5b98'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
from freeposte.admin.models import User
|
||||
from freeposte import db
|
||||
|
||||
def upgrade():
|
||||
# spam_threshold is a X/15 based value, we're converting it to percent.
|
||||
for user in User.query.all():
|
||||
user.spam_threshold = int(100. * float(user.spam_threshold or 0.) / 15.)
|
||||
db.session.commit()
|
||||
|
||||
# set default to 80%
|
||||
with op.batch_alter_table('user') as batch:
|
||||
batch.alter_column('spam_threshold', default=80.)
|
||||
|
||||
def downgrade():
|
||||
# spam_threshold is a X/15 based value, we're converting it from percent.
|
||||
for user in User.query.all():
|
||||
user.spam_threshold = int(15. * float(user.spam_threshold or 0.) / 100.)
|
||||
db.session.commit()
|
||||
|
||||
# set default to 10/15
|
||||
with op.batch_alter_table('user') as batch:
|
||||
batch.alter_column('spam_threshold', default=10.)
|
@@ -149,7 +149,7 @@ service managesieve-login {
|
||||
plugin {
|
||||
sieve_dir = ~/sieve
|
||||
sieve_plugins = sieve_extdata
|
||||
sieve_extensions = +vnd.dovecot.extdata
|
||||
sieve_extensions = +vnd.dovecot.extdata +spamtest +spamtestplus
|
||||
sieve_before = /var/lib/dovecot/before.sieve
|
||||
sieve_default = /var/lib/dovecot/default.sieve
|
||||
sieve_after = /var/lib/dovecot/after.sieve
|
||||
@@ -162,8 +162,13 @@ plugin {
|
||||
antispam_mail_spam = learn_spam
|
||||
antispam_mail_notspam = learn_ham
|
||||
antispam_mail_sendmail_args = -h;antispam:11334;-P;q1
|
||||
}
|
||||
|
||||
# extract spam score from
|
||||
# X-Spam-Result: .... [<value> / <max_value] ...
|
||||
sieve_spamtest_status_type = score
|
||||
sieve_spamtest_status_header = X-Spamd-Result: .*\[(-?[[:digit:]]+\.[[:digit:]]+) .*\]
|
||||
sieve_spamtest_max_header = X-Spamd-Result: .*\[.* ([[:digit:]]+\.[[:digit:]]+)\]
|
||||
}
|
||||
###############
|
||||
# Filtering
|
||||
###############
|
||||
|
@@ -8,16 +8,14 @@ require "regex";
|
||||
require "relational";
|
||||
require "comparator-i;ascii-numeric";
|
||||
require "vnd.dovecot.extdata";
|
||||
require "spamtestplus";
|
||||
|
||||
if allof (string :is "${extdata.spam_enabled}" "1",
|
||||
not header :matches "X-Spam-Status" "* score=-*",
|
||||
header :matches "X-Spam-Status" "* score=*")
|
||||
spamtest :percent :value "gt" :comparator "i;ascii-numeric" "${extdata.spam_threshold}")
|
||||
{
|
||||
if string :value "ge" :comparator "i;ascii-numeric" "${2}" "${extdata.spam_threshold}" {
|
||||
setflag "\\seen";
|
||||
fileinto :create "Junk";
|
||||
stop;
|
||||
}
|
||||
setflag "\\seen";
|
||||
fileinto :create "Junk";
|
||||
stop;
|
||||
}
|
||||
|
||||
if string :is "${extdata.reply_enabled}" "1" {
|
||||
|
Reference in New Issue
Block a user