Filtering spam to an IMAP folder with postfix, policyd and amavis

amavisemailpostfixspam-filter

Using amavisd-new, I'm successfully marking multiple headers and accurately reporting most spam.

However, right now I'm delivering it to the inbox and I would like to have a Junk folder instead. From time to time I will run sa-learn on these boxes (one for each account). So false negatives could be placed there and the system would learn from that.

I'm not sure if postfix, amavis or policyd is the right place to begin. As I'm using virtual domains, there would be a different folder for each user@domain, and not a general quarantine.

Any thoughts on how to set this up? I guess I want it to function like gmail or yahoo mail do today, automatically moving suspected SPAM into a junk folder.

Best Answer

There are several options to accomplish this, and they all largely depend on the delivery agent you are using to do the final delivery to a user's virtual mailbox.

  1. If you are using the stock Postfix virtual(8) delivery agent, you can't accomplish this.
  2. If you are using either the Cyrus LDA or the Dovecot LDA, you habe two more options: You can either use their builtin Sieve functionality (a quick Google search should reveal how to parse the X-Spam-Status header) and provide a global Sieve script or make use of recipient delimiters (set recipient_delimiter = + in Postfix' main.cf and have a look at the redirect documentation for amavisd-new).
  3. If you are using maildrop, see James' answer.
  4. If none of this options are applicable, you could let amavisd-new put those mails to a quarantine. OSS quarantine managers are scarce, for SQL based quarantine I do only know of MailZu and MailZu-ng for modern amavisd-new. Maia Mailguard comes with it's own amavisd-new implementation (I don't recommend using Maia for various reasons). Finally, I've lately been writing a combined quarantine/mailsettings management application, but I can't give any dates on when this one will be finished).

A wholly different approach, given that either your mail volume is low or you have access to some serious hardware, would be to run amavisd-new as a before queue filter, thereby eleminating the need for spam/junk folders or quarantine completely: If a legitimate mail is rejected as spam, the sender will be notified by it's own mail server - since you technically never accepted the mail, you won't be responsible for anything.

Related Topic