mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
email: Implement spam sorting with sieve
- Sieve script detects spam headers used by Rspamd and SpamAssassin - Autosubscribe to Archive, Drafts, Junk, Sent, Trash - Autoexpunge Trash and Junk folders - INBOX.Junk -> Junk, INBOX.Trash -> Trash, Sent Messages -> Sent
This commit is contained in:
parent
41f0461ac7
commit
c31a896e81
@ -1,7 +1,9 @@
|
|||||||
"""Configures spam filters and the virus scanner"""
|
"""Configures spam filters and the virus scanner"""
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
import glob
|
||||||
import logging
|
import logging
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
|
|
||||||
@ -50,3 +52,21 @@ def fix_filter(diagnosis):
|
|||||||
def action_set_filter():
|
def action_set_filter():
|
||||||
with postconf.mutex.lock_all():
|
with postconf.mutex.lock_all():
|
||||||
fix_filter(check_filter())
|
fix_filter(check_filter())
|
||||||
|
_compile_sieve()
|
||||||
|
|
||||||
|
|
||||||
|
def _compile_sieve():
|
||||||
|
sieve_list = glob.glob('/etc/dovecot/freedombox-sieve-after/*.sieve')
|
||||||
|
for sieve_file in sieve_list:
|
||||||
|
_run_sievec(sieve_file)
|
||||||
|
|
||||||
|
|
||||||
|
def _run_sievec(sieve_file):
|
||||||
|
logger.info('Compiling sieve script %s', sieve_file)
|
||||||
|
args = ['sievec', '--', sieve_file]
|
||||||
|
completed = subprocess.run(args, capture_output=True)
|
||||||
|
if completed.returncode != 0:
|
||||||
|
logger.critical('Subprocess returned %d', completed.returncode)
|
||||||
|
logger.critical('Stdout: %r', completed.stdout)
|
||||||
|
logger.critical('Stderr: %r', completed.stderr)
|
||||||
|
raise OSError('Sieve compilation failed: ' + sieve_file)
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
# Direct edits to this file will be lost!
|
||||||
|
# Manage your settings on Plinth <https://localhost/plinth/apps/email_server>
|
||||||
|
|
||||||
|
protocol lmtp {
|
||||||
|
mail_plugins = $mail_plugins sieve
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
# Direct edits to this file will be lost!
|
||||||
|
# Manage your settings on Plinth <https://localhost/plinth/apps/email_server>
|
||||||
|
|
||||||
|
namespace inbox {
|
||||||
|
mailbox Archive {
|
||||||
|
auto = subscribe
|
||||||
|
special_use = \Archive
|
||||||
|
}
|
||||||
|
mailbox Drafts {
|
||||||
|
auto = subscribe
|
||||||
|
special_use = \Drafts
|
||||||
|
}
|
||||||
|
mailbox Junk {
|
||||||
|
auto = subscribe
|
||||||
|
autoexpunge = 30d
|
||||||
|
special_use = \Junk
|
||||||
|
}
|
||||||
|
mailbox Trash {
|
||||||
|
auto = subscribe
|
||||||
|
autoexpunge = 30d
|
||||||
|
special_use = \Trash
|
||||||
|
}
|
||||||
|
|
||||||
|
mailbox INBOX.Junk {
|
||||||
|
auto = no
|
||||||
|
autoexpunge = 30d
|
||||||
|
special_use = \Junk
|
||||||
|
}
|
||||||
|
mailbox INBOX.Trash {
|
||||||
|
auto = no
|
||||||
|
autoexpunge = 30d
|
||||||
|
special_use = \Trash
|
||||||
|
}
|
||||||
|
|
||||||
|
mailbox Sent {
|
||||||
|
auto = subscribe
|
||||||
|
special_use = \Sent
|
||||||
|
}
|
||||||
|
mailbox "Sent Messages" {
|
||||||
|
auto = no
|
||||||
|
special_use = \Sent
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
# Direct edits to this file will be lost!
|
||||||
|
# Manage your settings on Plinth <https://localhost/plinth/apps/email_server>
|
||||||
|
|
||||||
|
plugin {
|
||||||
|
sieve_after = /etc/dovecot/freedombox-sieve-after
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
require ["fileinto", "mailbox"];
|
||||||
|
|
||||||
|
if anyof(header :contains "X-Spam" "Yes",
|
||||||
|
header :contains "X-Spam-Status" "Yes",
|
||||||
|
header :matches "X-Spam-Flag" "YES") {
|
||||||
|
fileinto :create "Junk";
|
||||||
|
stop;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user