[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Getting Postfix to sort spam into different folders



On 10/2/2013 10:17 AM, Robin Kipp wrote:
> Hi all,
> I've been running my own mail server for a while (Postfix as the MTA and Dovecot for retrieving mail via IMAP).
> Yesterday, I added amavis-new for content filtering, and so far have implemented spam checking using spamassassin and virus filtering using clamav.
> All this appears to be working well - if anyone has some time to spare, feel free to check the header of this message - if there are any things that could be improved, I certainly would appreciate any feedback! :-)
> So, now that spamassassin is flagging junk mail, I really would like a way of having said junk sorted into a different folder for each user. I'm aware this can also be done on the MUA side, but on some end-user devices (such as smartphones), junkmail filtering is often not supported very unfortunately.
> So, I was just wondering… Is there any way I could do this on the server side?
> My main problem really is that I'm not sure where I'd best set this up - but I'm guessing I'd have to do it in Postfix, as I use the 'virtual' local delivery agent to drop incoming mail into the appropriate directories. Also, the mailboxes are stored in maildir format if that makes any difference…
> If anyone has anything like this working or could point me in the right direction I would greatly appreciate that!
> Many thanks :-)
> Robin

Dovecot includes the sieve language for sorting.  Per user, you'd have a
.dovecot.sieve file in the home directory, containing something like:

/home/stan/.dovecot.sieve

require "fileinto";

if false {}

elsif header :contains "X-Spam-Flag" "YES" {
        fileinto "Spam";
        stop;
}
...

This will move the flagged messages into the user's IMAP folder named
"Spam".

You must use Dovecot LDA or LMTP for delivery if you want to use sieve.
 The advantage of using sieve vs procmail, maildrop, etc, is that
Dovecot LDA/LMTP index the messages during the delivery phase.  If you
use procmail/maildrop then Dovecot doesn't index messages until you open
the mailbox, which is slower.

You can also use Managesieve which allows users to create their own
filter rules.  It is also possible to have a global sieve file for all
users, for thing such as spam sorting, and individual user defined sieve
rules simultaneously.

-- 
Stan


Reply to: