Dovecot imap send spam to junk

dovecotimapspam

I am using

  • Ubuntu 18.04 64 bit
  • dovecot 2.2.33.2
  • spamassassin 3.4.1
  • amavisd

The goal is to run an e-mail server, which I achieved already. I can access the e-mails at the server using Thunderbird and the imap protocol.

For the postfix configuration I followed this tutorial: https://help.ubuntu.com/community/PostfixBasicSetupHowto but using Maildir instead.

Dovecot got configured following:

https://www.linuxbabe.com/mail-server/secure-email-server-ubuntu-16-04-postfix-dovecot https://help.ubuntu.com/community/Dovecot

In addition I installed fail2ban, which got tested successfully.

The next step is e-mail filtering. Following https://help.ubuntu.com/lts/serverguide/mail-filtering.html.en worked out nicely. Spamassassin is blocking all spam. But acutally I do not want to block it, I just want that spamassassin marks it as spam and that the spam gets redirected into my spam-folder. This is just in case something gets filtered out that was not a spam.

For that I set /etc/amavis/conf.d/21-ubuntu_defaults:

$final_spam_destiny       = D_PASS;

and the subject gets added ****SPAM****

The next step is that dovecot automatically moves this mail to my junk folder. And there I get stuck. I followed this tutorial: https://workaround.org/ispmail/stretch/filtering-out-spam-with-rspamd

and there the part "Sending spam to the Junk folder". But it doesn't work. I have seen that sieve is not working for imap. But I cannot find any tutorial or manual on imap_sieve, that would solve my problem. Does anyone of you has an idea? I also do not find any log entry where I could see that sieve is working (or not)?

Best Answer

I got a bit further in my problem:

By setting conf.d/10-logging.conf

mail_debug = yes

and conf.d/90-sieve.conf

sieve_plugins = sieve_imapsieve
sieve_global_dir = /etc/dovecot/sieve/`

as well as in:

conf.d/90-plugin.conf `

  plugin {
   sieve_plugins = sieve_imapsieve sieve_extprograms
   imapsieve_mailbox1_name = INBOX
   imapsieve_mailbox1_after = file:/etc/dovecot/sieve/default.sieve
  sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
}

and sieve/default.sieve: `

 require ["fileinto", "mailbox", "imap4flags"];
 if header :contains "subject" ["*SPAM*"] {
    setflag "\\Seen";
    #setflag "\\Deleted";
    fileinto :create "Junk";
    stop;
}

as well as compiling by sievec sieve/default.sieve I made it that junk mail gets copied into the junk folder. But unfortunately the mail stays as well in the Inbox. It seems it is just copied?