FreeBSD, Dovecot and Sieve

This outlines the things I had to do on the backend to get sieve filtering working on Dovecot 2.x on FreeBSD .

It should be portable to other platforms, but you may have to adjust paths. This won’t really discuss the details of setting up Dovecot, except where relevant to sieve. I will assume you already have Dovecot (2.x) server connected to an MTA (I use postfix, but others work just fine). I also run a virtual environment, so this will reflect some of those specifics as well.

Installation

You will need to install the pigeonhole managesieve pkg linked off the dovecot wiki. In FreeBSD , you can do

1	pkg_add dovecot2-managesieve

or

1	make install clean

from the dovecot2-managesieve directory in the ports tree.

Postfix transports

For reference, the postfix transport looks like this:

1	virtual_transport = lmtp:unix:private/dovecot-lmtp

Dovecot config bits

You will need to define some things in your dovecot.conf:

1	lmtp_save_to_detail_mailbox = yes
2	mail_home = /usr/local/virtual/%d/%n
3	mail_location = maildir:~/Maildir

This first part adds an entry in your received headers indicating the message traversed to the dovecot server over LMTP. The second part defines the virtual users homedir, and then where mail should be stored relative to the homedir.

 1	plugin {
 2	  autocreate = Trash
 3	  autocreate2 = Junk
 4	  autosubscribe = Trash
 5	  autosubscribe2 = Junk
 6	  sieve = /usr/local/virtual/%d/%n/dovecot.sieve
 7	  sieve_dir = /usr/local/virtual/%d/%n/
 8	  sieve_global_dir = /usr/local/virtual/sieve
 9	  sieve_global_path = /usr/local/virtual/sieve/globalfilter.sieve
10	}

This allows us to dynamically create Trash and Junk folders and have them appear in the mail client. We want to do this so we don’t inadvertently filter into a non-existent location when we deploy a global filter. The sieve directives define where the per-user sieve files will be, and also where the global sieve files will be.

1	protocols = imap pop3 lmtp sieve

Ensure we listen for sieve communication (you will want to disable unused protocols, and firewall sieve, from the outside world).

 1	service lmtp {
 2	  unix_listener /var/spool/postfix/private/dovecot-lmtp {
 3	    group = postfix
 4	    mode = 0660
 5	    user = postfix
 6	  }
 7	}
 8	protocol lmtp {
 9	  mail_plugins = " sieve"
10	  postmaster_address = postmaster@txt.com
11	  quota_full_tempfail = yes
12	}

This defines the location of the lmtp unix socket dovecot will listen on. It also includes the sieve plugin, which allows us to filter messages at delivery time.

 1	service managesieve-login {
 2	  inet_listener sieve {
 3	    port = 4190
 4	  }
 5	  process_min_avail = 0
 6	  service_count = 1
 7	  vsz_limit = 64 M
 8	}
 9	service managesieve {
10	  process_limit = 1024
11	}
12	protocol sieve {
13	  mail_max_userip_connections = 10
14	  managesieve_implementation_string = Dovecot Pigeonhole
15	  managesieve_logout_format = bytes=%i/%o
16	  managesieve_max_line_length = 65536
17	}

These setup the sieve communication for users. Depending on how you allow sieve communication, you could offer direct interaction with the sieve server (such as telnet sieve_server 4190), or proxied communication with the sieve server (such as through a web interface like roundcube).

Copyright

Comments