Repository: Mailu/Mailu

Issue:
spam not moved to junk folder
Hi,

I'm running the `latest` images as of yesterday (probably 79adbbb).
I've enabled spam detection in the admin console, and spam is actually detected and marked by rspamd, headers are inserted like:

```
X-Spamd-Result: default: True [24.36 / 15.00]
 RBL_SPAMHAUS_XBL(4.00)[]
 RBL_SPAMHAUS_XBL_ANY(4.00)[]
 HFILTER_HOSTNAME_UNKNOWN(2.50)[]
 BAYES_SPAM(3.06)[92.67%]
 HFILTER_HELO_BAREIP(3.00)[]
 RBL_SORBS_RECENT(1.50)[]
 RBL_SPAMHAUS_CSS(2.00)[]
 RBL_MAILSPIKE_WORST(2.00)[]
 MIME_UNKNOWN(0.10)[application/x-rar-compressed]
 RBL_SORBS(0.00)[]
 R_SPF_NEUTRAL(0.00)[?all]
 ONCE_RECEIVED(0.10)[]
 RBL_UCEPROTECT_LEVEL1(1.00)[]
 MIME_HTML_ONLY(0.20)[]
 RBL_SEM(1.00)[]
 MIME_GOOD(-0.10)[multipart/mixed]
X-Rspamd-Server: antispam
X-Rspamd-Scan-Time: 0.37
X-Rspamd-Queue-ID: D24918003EE
X-Spam: yes
```

Still those messages are kept in my INBOX and not moved to Junk or marked as read.
It seems to me, that the dovecot sieve scripts are outdated or targeted at some other spamfilter (`X-Spam-Status`, spamassassin?) and not effective anymore.

How do I achieve the same result (automatically move spam to junk and mark it read) with the current images?

Thanks,
Christoph



Discussion:
Thanks for reporting this, it seems indeed that the latest Rspamd version does not add the `X-Spam-Status` header. We should spend some time matching the `X-Spamd-Result` header, which was a hassle some time ago unfortunately.

Maybe I can find some time to help out here. For starters, I'll try to figure out how to debug sieve scripts ;).

Debugging sieve scripts is painful. You can start by enabling `mail_debug` in Dovecot. Thanks for your help!


Resolving patch:
diff --git a/admin/freeposte/admin/models.py b/admin/freeposte/admin/models.py
--- a/admin/freeposte/admin/models.py
+++ b/admin/freeposte/admin/models.py
@@ -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
diff --git a/admin/migrations/versions/27ae2f102682_.py b/admin/migrations/versions/27ae2f102682_.py
new file mode 100644
--- /dev/null
+++ b/admin/migrations/versions/27ae2f102682_.py
@@ -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.)


Test patch: