7

I am trying to move Spam detected by spamassassin automatically to the Junk folder on Debian Jessie.

I installed Spamassassin and edited the configs:

local.cf (spamassassin folder)

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

main.cf

spamassassin_destination_recipient_limit = 1

master.cf

smtp      inet  n       -       -       -       -       smtpd
        -o content_filter=spamassassin

spamassassin unix -     n   n   -   -   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 (postfix)

mailbox Junk {
   auto = subscribe
   special_use = \Junk
}

The Spam gets marked as *****SPAM***** correctly, but is not moved into the Junk folder (i use roundcube as mail client, the Junkfolder does not even show up. There are no errors in the mail.info log either:

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
Nidhoegger
  • 231
  • 1
  • 5
  • 14
  • 1
    For everyone searching for a simple solution: don't use Postfix or Dovecot/Sieve for mail filtering. Try [Procmail + Crontab](https://wiki.apache.org/spamassassin/UsedViaProcmail). – Maciek Łoziński Dec 06 '18 at 04:09
  • Much better answer on SO https://stackoverflow.com/questions/24256008/how-to-move-spam-to-spam-folder – slf Sep 06 '21 at 03:59

2 Answers2

4

In my case I was missing include conf.d/*.conf line in dovecot.conf and dovecot did not read configuration from these files including 90-plugins.conf.

But I did not include that line because all my config is already in dovecot.conf and conf.d/*.conf files will override it with default settings so I simply included these lines in dovecot.conf:

plugin {
    sieve = /etc/dovecot/sieve/default.sieve
}

protocol lda {
    mail_plugins = $mail_plugins sieve
}

All your other configuration is fine and should work (it seems that you get them from this answer).

mixel
  • 416
  • 6
  • 10
3

To manage filter rule you can use sieve on dovecot. You can put it as global sieve or per user sieve.

For global sieve use configuration in /etc/dovecot/dovecot.conf :

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

For sieve per user use configuration :

sieve = /%Lh/sieve/dovecot.sieve

which %Lh===dovecot will change it to user mailbox dir

This is example for sieve files content:

if header :contains "*****SPAM*****" "YES"
{
    fileinto "Junk";
    stop;
}
dek.tiram
  • 91
  • 3