Howto sort mail into different folders using sieve

A collection of tips on howto tweak your Bubba.
Post Reply
DanielM
Posts: 637
Joined: 28 Mar 2008, 06:37
Location: Sweden

Howto sort mail into different folders using sieve

Post by DanielM » 11 Apr 2008, 03:40

I installed spamassassin using another (excellent) howto on this forum. After the installation I came to the conclusion that spamassassin wasn't of much use if I got the spam in my inbox anyway. So I've played around a bit with sieve, which lets users set up their own rules of how mail should be sorted automatically within their mailboxes. Guess this could be of good use to others as well.

Bubbas mime server, Dovecot, comes with sieve included, there is only some settings to do to activate it. Firstly we've got to tell postfix to let dovecots lda (deliver) handle the delivery of mails. We do this by adding the line

Code: Select all

mailbox_command = /usr/lib/dovecot/deliver
into our /etc/postfix/main.cf. Second thing is to tell deliver to activate sieve, this is done by uncommenting the following lines in /etc/dovecot/dovecot.conf:

Code: Select all

protocol lda{
postmaster_address = put_some_good_working_address_here
mail_plugins = cmusieve
}
...and we also have to make dovecot.conf world readable (so that the lda can read it (if I'm understanding things correctly)), by running a chmod a+r on it. What I can understand this is no problem since the file doesn't contain any secrets. Anyone correct me if I'm wrong.

Now do a /etc/init.d/dovecot restart and the users should be able to start sorting their mail. They do this by making a file named .dovecot.sieve in their home directories. In my .dovecot.sieve I currently have the following

Code: Select all

require "fileinto";
if exists "X-Spam-Flag" {
        fileinto "Spam";
}
malmgren@bubba:~$ nano .dovecot.sieve
malmgren@bubba:~$ cat .dovecot.sieve
require "fileinto";
if exists "X-Spam-Flag" {
        fileinto "Spam";
}

elsif header :contains "to" "daniel" {
        fileinto "Daniel";
}
...which copies my spam into "Spam" and mail with the work "daniel" as recipient to the folder "Daniel". I guess the folders has to exist, in my case I created them in beforehand using ilohamail (which I by the way upgraded to the latest (very old) 0.9 beta, if anyone needs a howto on that please tell me).

I don't guarantee that anything of the above works for anyone else. I'm a complete newbie at configuring dovecot, postfix etc. And I'm sure I did a lot of stuff that I forgot in this howto. Please tell me if that's the case :-)

/Daniel

Post Reply