added sieve rule to move spam to junk folder

This commit is contained in:
Spitfireap
2024-01-12 18:08:28 +01:00
committed by Antoine Nguyen
parent 5156ad0468
commit 38eae741bf
4 changed files with 24 additions and 2 deletions

View File

@@ -372,6 +372,14 @@ ConfigDictTemplate = [
"option": "postmaster_address", "option": "postmaster_address",
"default": "postmaster@%(domain)s", "default": "postmaster@%(domain)s",
}, },
{
"option": "radicale_auth_socket_path",
"default": "/var/run/dovecot/auth-radicale",
},
{
"option": "move_spam_to_junk",
"default": "true",
},
] ]
}, },
{ {

View File

@@ -40,7 +40,13 @@ class Dovecot(base.Installer):
def get_config_files(self): def get_config_files(self):
"""Additional config files.""" """Additional config files."""
return self.config_files + [ _config_files = self.config_files
if self.app_config["move_spam_to_junk"]:
_config_files += ["conf.d/90-sieve.conf",
"conf.d/custom_after_sieve/spam-to-junk.sieve"]
return _config_files + [
"dovecot-sql-{}.conf.ext=dovecot-sql.conf.ext" "dovecot-sql-{}.conf.ext=dovecot-sql.conf.ext"
.format(self.dbengine), .format(self.dbengine),
"dovecot-sql-master-{}.conf.ext=dovecot-sql-master.conf.ext" "dovecot-sql-master-{}.conf.ext=dovecot-sql-master.conf.ext"
@@ -145,6 +151,10 @@ class Dovecot(base.Installer):
utils.exec_cmd("chmod 600 /etc/dovecot/conf.d/10-ssl-keys.try") utils.exec_cmd("chmod 600 /etc/dovecot/conf.d/10-ssl-keys.try")
# Add mailboxes user to dovecot group for modoboa mailbox commands. # Add mailboxes user to dovecot group for modoboa mailbox commands.
# See https://github.com/modoboa/modoboa/issues/2157. # See https://github.com/modoboa/modoboa/issues/2157.
if self.app_config["move_spam_to_junk"]:
# Compile sieve script
sieve_file = "/etc/dovecot/conf.d/custom_after_sieve/spam-to-junk.sieve"
utils.exec_cmd(f"/usr/bin/sievec {sieve_file}")
system.add_user_to_group(self.mailboxes_owner, 'dovecot') system.add_user_to_group(self.mailboxes_owner, 'dovecot')
def restart_daemon(self): def restart_daemon(self):

View File

@@ -38,7 +38,7 @@ plugin {
# Identical to sieve_before, only the specified scripts are executed after the # Identical to sieve_before, only the specified scripts are executed after the
# user's script (only when keep is still in effect!). Multiple script file or # user's script (only when keep is still in effect!). Multiple script file or
# directory paths can be specified by appending an increasing number. # directory paths can be specified by appending an increasing number.
#sieve_after = {%dovecot_enabled}sieve_after = /etc/dovecot/conf.d/custom_after_sieve
#sieve_after2 = #sieve_after2 =
#sieve_after2 = (etc...) #sieve_after2 = (etc...)

View File

@@ -0,0 +1,4 @@
require "fileinto";
if header :contains "X-Spam-Status" "Yes" {
fileinto "Junk";
}