Date: 2019sep25
Distro: RedHat/Fedora/CentOS
Products: dovecot, postfix
Q. SpamAssassin: put spam messages into a folder with Postfix and Dovecot
A. Use LMTP (Local Mail Transport Protocol) with a sieve
First, setup LMTP
https://wiki2.dovecot.org/HowTo/PostfixDovecotLMTP
(But don't add the "quota" plugin, unless you want it)
In file /etc/dovecot/conf.d/10-auth.conf
auth_username_format = %Ln
(Removes the @ and domain name)
Its probably a good idea to restart Dovecot and Postfix and do some tests now.
Then you need to install a "sieve" plugin for Dovecot called Pigeonhole
dnf install dovecot-pigeonhole
In file /etc/dovecot/conf.d/15-mailboxes.conf
namespace inbox {
...
mailbox Junk {
auto = subscribe
special_use = \Junk
}
}
In file /etc/dovecot/conf.d/20-lmtp.conf
protocol lmtp {
postmaster_address = postmaster@yourdomain.com
mail_plugins = $mail_plugins sieve
}
In file /etc/dovecot/conf.d/90-sieve.conf
plugin {
sieve_default = /etc/dovecot/sieve/default.sieve
}
Make a folder
mkdir /etc/dovecot/sieve
In file /etc/dovecot/sieve/default.sieve
require "fileinto";
require "imap4flags";
# Mark really spammy mail as read (optional)
if header :contains "X-Spam-Level" "**********" {
addflag "\\seen";
}
if header :contains "X-Spam-Flag" "YES" {
fileinto "Junk";
}
# For testing (optional)
if header :contains "subject" "test" {
fileinto "Junk";
}
Compile it
sievec /etc/dovecot/sieve/default.sieve
In file /etc/postfix/header_checks remove (if present)
## /^X-Spam-Flag: YES/ DISCARD SpamAssassin Confirmed Spam Content
Restart everything
systemctl restart dovecot spamassassin postfix
Test by sending a mail with Subject: test
More info
http://sieve.info