Spamassassin,Dovecot和Postfix:将垃圾邮件移至文件夹

我正尝试将spamassassin检测到的垃圾邮件自动移动到Debian Jessie上的Junk文件夹中。

我安装了Spamassassin并编辑了configuration:

local.cf (spamassassin文件夹)

 rewrite_header Subject *****SPAM***** 

main.cf

 spamassassin_destination_recipient_limit = 1 

master.cf

 smtp inet n - - - - smtpd -o content_filter=spamassassin spamassassin unix - nn - - pipe flags=DROhu user=vmail:vmail argv=/usr/bin/spamc -f -e /usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop} 

90-plugins.conf (dovecot)

 plugin { #setting_name = value sieve = /etc/dovecot/sieve/default.sieve } 

default.sieve

 require "fileinto"; if header :contains "X-Spam-Flag" "YES" { fileinto "Junk"; } 

15-mailboxes.conf后缀

 mailbox Junk { auto = subscribe special_use = \Junk } 

垃圾邮件被正确标记为*****SPAM***** ,但没有被移动到垃圾邮件文件夹(我使用roundcube作为邮件客户端,Junk文件夹甚至没有显示出来。 mail.info中没有错误mail.infologging:

 Mar 18 17:22:29 *************** postfix/smtpd[6184]: connect from mail-io0-f173.google.com[209.85.223.173] Mar 18 17:22:29 *************** postfix/smtpd[6184]: DD759241A7B: client=mail-io0-f173.google.com[209.85.223.173] Mar 18 17:22:30 *************** postfix/cleanup[6189]: DD759241A7B: message-id=<CALvS7dGxMQDAVn7WaVe4xhqyejU_1MBu20QMu__mVyLjggHi9w@mail.gmail.com> Mar 18 17:22:30 *************** postfix/qmgr[4489]: DD759241A7B: from=<***************m>, size=2492, nrcpt=1 (queue active) Mar 18 17:22:30 *************** spamd[4506]: spamd: connection from ip6-localhost [::1]:46206 to port 783, fd 6 Mar 18 17:22:30 *************** spamd[4506]: spamd: processing message <CALvS7dGxMQDAVn7WaVe4xhqyejU_1MBu20QMu__mVyLjggHi9w@mail.gmail.com> for vmail:5555 Mar 18 17:22:30 *************** postfix/smtpd[6184]: disconnect from mail-io0-f173.google.com[209.85.223.173] Mar 18 17:22:30 *************** spamd[4506]: spamd: identified spam (1000.3/2.0) for vmail:5555 in 0.2 seconds, 2547 bytes. Mar 18 17:22:30 *************** spamd[4506]: spamd: result: Y 1000 - FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GTUBE,HTML_MESSAGE,RCVD_IN_MSPIKE_H2,SPF_PASS,TVD_SPACE_RATIO,T_DKIM_INVALID scantime=0.2,size=2547,user=vmail,uid=5555,required_score=2.0,rhost=ip6-localhost,raddr=::1,rport=46206,mid=<CALvS7dGxMQDAVn7WaVe4xhqyejU_1MBu20QMu__mVyLjggHi9w@mail.gmail.com>,autolearn=no autolearn_force=no Mar 18 17:22:30 *************** spamd[4505]: prefork: child states: II Mar 18 17:22:30 *************** dovecot: lda(***************): msgid=<CALvS7dGxMQDAVn7WaVe4xhqyejU_1MBu20QMu__mVyLjggHi9w@mail.gmail.com>: saved mail to INBOX Mar 18 17:22:30 *************** postfix/pipe[6192]: DD759241A7B: to=<***************>, relay=spamassassin, delay=0.63, delays=0.32/0/0/0.3, dsn=2.0.0, status=sent (delivered via spamassassin service) Mar 18 17:22:30 *************** postfix/qmgr[4489]: DD759241A7B: removed 

在我的情况下,我缺lessinclude conf.d/*.conf dovecot.conf include conf.d/*.conf dovecot.conf行,dovecot没有从这些文件(包括90-plugins.conf读取configuration。

但是我没有包含这一行,因为我的configuration文件已经在dovecot.confconf.d/*.conf dovecot.conf文件中,它们会使用默认设置覆盖它,所以我只是将这些行包含在dovecot.conf

 plugin { sieve = /etc/dovecot/sieve/default.sieve } protocol lda { mail_plugins = $mail_plugins sieve } 

所有你的其他configuration是好的,应该工作(似乎你从这个答案得到他们)。

要pipe理filter规则,您可以在dovecot上使用筛子。 你可以把它作为全球筛或每个用户筛。

对于/etc/dovecot/dovecot.conf中的全局筛选使用configuration:

 sieve_global_path = /home/vmail/sieve/dovecot.sieve 

对于每个用户的筛选使用configuration:

 sieve = /%Lh/sieve/dovecot.sieve 

其中%Lh === dovecot会将其更改为用户邮箱目录

这是sieve文件内容的例子:

 if header :contains "*****SPAM*****" "YES" { fileinto "Junk"; stop; }