I have successfully configured Postfix + Dovecot + IMAP. And I just also installed spamassassin
, spamc
, spamass-milter
, and configured imap_sieve
plugin to combat spam.
Output of doveconf -n
:
# 2.3.13 (89f716dc2): /etc/dovecot/dovecot.conf
# Pigeonhole version 0.5.13 (cdd19fe3)
# OS: Linux 5.10.0-33-amd64 x86_64 Debian 11.11
# Hostname: mail.example.com
mail_debug = yes
mail_location = maildir:~/Maildir
mail_privileged_group = mail
managesieve_notify_capability = mailto
managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date index ihave duplicate mime foreverypart extracttext imapsieve vnd.dovecot.imapsieve
namespace inbox {
inbox = yes
location =
mailbox Drafts {
auto = no
special_use = \Drafts
}
mailbox Sent {
auto = subscribe
special_use = \Sent
}
mailbox Spam {
auto = subscribe
special_use = \Junk
}
mailbox Trash {
auto = subscribe
special_use = \Trash
}
prefix =
}
passdb {
args = %s
driver = pam
}
plugin {
imapsieve_mailbox1_before = file:/var/lib/dovecot/sieve.d/default.sieve
imapsieve_mailbox1_name = INBOX
sieve_plugins = sieve_imapsieve
}
protocols = imap sieve
service auth {
unix_listener /var/spool/postfix/private/auth {
group = postfix
mode = 0660
user = postfix
}
}
service imap-login {
inet_listener imap {
port = 143
}
inet_listener imaps {
port = 993
ssl = yes
}
}
ssl = required
ssl_cert = </etc/ssl/mail/domain.crt
ssl_key = # hidden, use -P to show it
userdb {
driver = passwd
}
protocol imap {
mail_max_userip_connections = 20
mail_plugins = " imap_sieve"
}
Contents of /var/lib/dovecot/sieve.d/default.sieve
:
require "fileinto";
if header :contains "X-Spam-Flag" "YES" {
fileinto "Spam";
stop;
}
And I tested my setup with:
# Executed from outside my network
wget https://spamassassin.apache.org/gtube/gtube.txt
swaks --to [email protected] --body gtube.txt
And it works. The email is successfully marked as spam (evident by X-Spam-Flag: YES
in the headers). But the Sieve filter does not work as expected. It should move the message to my "Spam" folder, but instead it copies the message to the "Spam" folder, but only after I opened the message. The message remains inside the INBOX.
How can I make it so that the message gets moved to the "Spam" folder (not copied)? And why does the Sieve filter only work after I open the message in my email client?