Mailserver with ldap tutorial – part 6: sieve

Sometimes it is useful to have the mailserver sort mails in different folders – especially when you use different deveices to read your mail. You could have a folder spam for mails tagged as spam by spamassasin and mailinglists for mailinglist which you maybe don’t want to read on your smartphone. A nice and mighty way to do such filtering is to use sieve.

This is a post from my old blog http://tech.cbjck.de. It has been moved here and slightly edited for better readability. It's also been adjusted to the new layout.
The content however is old and might be outdated.


This is step 5 of the 8 step tutorial for setting up a mailserver with openldap, postfix and dovecot using virtual users. You can find the overview here.

Install sieve

Sieve is already installed with the debian version of dovecot.

Setup sieve

To set sieve as mail_plugin edit the section protocol_lda in /etc/dovecot/dovecot.conf to look like

protocol lda {
  postmaster_address = postmaster@cbjck.de
  auth_socket_path = /var/run/dovecot/auth-master
  log_path = /var/vmail/dovecot-deliver.log
  mail_plugins = sieve
}

Then set the properties for the plugin. I use 2 differente sieve scripts, a global one for spam filtering and a local one for each user. In my account I use a filter list to move mails from mailing lists to different folders.

plugin {
   sieve=/var/vmail/sieve/%n.%d.sieve
   sieve_global_path = /var/vmail/globalsieverc
}

In /var/vmail/gloablsieverc setup the global filtering rules, e.g.:

require ["fileinto"];
# Move spam to spam folder
if anyof ( header :contains "X-Spam-Flag" "YES",
           header :contains "Subject" "[SPAM]" ) {
  fileinto "Spam";
  stop;
}

This only works if the folder Spam does exists for each user. Otherwise the mails will be delivered to INBOX.
In /var/vmail/sieve/dummy.sieve setup up filtering rules for dummy only.
Remember that user sieve scripts overwrite the global ones. All sieve rules have to be readable by dovecot.

Finally restart dovecot

/etc/init.d/dovecot restart

and check if everything works.


Edited on Jan 9th 2015 for better readability.
Edited on Aug 25th 2017 for better readability.

1 Comment

  1. Pingback: more features for roundcube webmail | cbjck.de

Leave a Reply

Your email address will not be published. Required fields are marked *