我已经成功配置了 Postfix + Dovecot + IMAP 。我还刚刚安装了spamassassin
、、,并配置了插件来对抗垃圾邮件。spamc
spamass-milter
imap_sieve
输出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"
}
内容/var/lib/dovecot/sieve.d/default.sieve
:
require "fileinto";
if header :contains "X-Spam-Flag" "YES" {
fileinto "Spam";
stop;
}
我使用以下方法测试了我的设置:
# Executed from outside my network
wget https://spamassassin.apache.org/gtube/gtube.txt
swaks --to [email protected] --body gtube.txt
并且它起作用了。电子邮件被成功标记为垃圾邮件(X-Spam-Flag: YES
在标题中很明显)。但是 Sieve 过滤器没有按预期工作。它应该将邮件移动到我的“垃圾邮件”文件夹,但它却将邮件复制到“垃圾邮件”文件夹,但只有在我打开邮件后才会发生这种情况。邮件仍留在收件箱内。
我如何才能让邮件移至“垃圾邮件”文件夹(而不是复制)?为什么 Sieve 过滤器仅在我使用电子邮件客户端打开邮件后才起作用?
您的用例听起来像是您打算使用
sieve_before
:在将收到的邮件发送到用户邮箱时调用;无论是通过 dovecot-lda 还是LMTP进行;而是配置imapsieve_mailbox1_before
:当邮件用户代理通过 IMAP 协议创建消息或更改其属性时进行的操作。