For my own reference, after few hours messing around with shit called mail system.
Packages:
- postfix
- dovecot-imapd (from backports)
- dovecot-managesieved (from backports)
- dovecot-sieve (from backports)
- amavisd-new
- spamassassin
Basic configuration as laid out from my previous post about mail.
And this is the continuation: spam filter and also sieve (which used to automatically filter mails based on rules).
Postfix
In /etc/postfix/master.cf:
127.0.0.1:10025 inet n - y - - smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
smtp-amavis unix - - y - 1 smtp
-o smtp_data_done_timeout=1200
-o disable_dns_lookups=yes
And then in /etc/postfix/main.cf:
content_filter=smtp-amavis:[127.0.0.1]:10024
[ Reference ]
SpamAssassin
Nothing to configure here AFAIR.
Amavis side
Uncomment following lines in /etc/amavis/conf.d/15-content_filter_mode:
@bypass_spam_checks_maps = ( %bypass_spam_checks, @bypass_spam_checks_acl, $bypass_spam_checks_re);
And add following line to /etc/amavis/conf.d/50-user:
$sa_spam_subject_tag = '';
(No reference for this one as I figured this out by myself)
Dovecot
Add sieve and autocreate plugin in /etc/dovecot/conf.d/15-lda.conf:
protocol lda {
mail_plugins = $mail_plugins sieve autocreate
}
Configure the autocreate plugin in /etc/dovecot/conf.d/90-plugin.conf:
plugin {
autocreate = Junk
autosubscribe = Junk
}
Create the spam filter in /etc/dovecot/sieve/spam.sieve:
require "fileinto";
if header :contains "X-Spam-Flag" "YES" {
fileinto "Junk";
}
…and compile it using sievec:
# sievec /etc/dovecot/sieve/spam.sieve
…and finally add it as global filter in /etc/dovecot/conf.d/90-sieve.conf:
plugin {
...
sieve_global_dir = /etc/dovecot/sieve
sieve_before = /etc/dovecot/sieve
[ Reference ]
And done (I think).