Sort your mail with Sieve under Cyrus

Posted by leto on Thu 18 Aug 2005 at 13:32

The principal advantage with an imapd server is that your mailbox is the same for all your mail clients. When you need to filter some emails this is usually a job for your mail client - and if it's not running, there's no filtering. Sieve allows you to filter mails in your Cyrus imap server even when you don't have a client open.

Configure Cyrus

Edit the file /etc/imad.conf and uncomment this line to activate the sieve admin :

sieve_admins: cyrus

Then choose the directory of the sieve scripts :

sievedir: /var/spool/sieve

It's time to active sieve daemon, uncomment :

sieve cmd="timsieved" listen="localhost:sieve" prefork=0 maxchild=100

Once all that is done restart your cyrus daemon.

You can verify that the service is activated :

linux:/home/leto# cat /etc/services | grep sieve
sieve           2000/tcp                        # Sieve mail filter daemon
Create a sieve script

Here are some simple examples (location of the script doesn't matter) :

cat script.sieve
# If subject contains [Linux] then put it on the "Linux" box.
if header :contains "Subject" "[Linux]" { fileinto "Linux"; stop; }

# If mail is from cube3 company put it on the "Cube3" box.
if address :domain :is "From" "cube3.org" { fileinto "Cube3"; stop; }

# If mail address is one of my friend bob put it on "Mybudbob" box.
if address :is "From" ["premiere@adresse.monpote", "deuxieme@adresse.monpote"] \
{ fileinto "MonpoteBob"; stop; }

# Same thing but just for one address.
if header :contains "From" "Cron Daemon" { fileinto "Reports"; stop; }

Install the script

If there's no shell use option : --user=*user*

sieveshell localhost
>put script.sieve
>activate script.sieve
>quit

Your script is ready :)

If It doesn't work

Verify your syslog, if you have the following error:

Fileinto: Invalid mailbox name

Then you can fix this by replacing in your your script : target by INBOX.target or INBOX/target depending on your cyrus version.


This article can be found online at the Debian Administration website at the following bookmarkable URL:

This article is copyright 2005 leto - please ask for permission to republish or translate.