dovecot-sieve with FreeBSD

Sieve plugin for dovecot LDA (* libsieve comes from the cyrus imap server (mail/cyrus-imapd23) )

Obtain the sieve plugin from CVS:

cvs -d co dovecot-sieve

On FreeBSD change the file contents to:

# using automake19, autoconf259, and libtool15 ports.
aclocal19 -I /usr/local/share/aclocal
libtoolize –force
automake19 –add-missing

Then, run it:


Install this sieve plugin:

# NB: Before you continue, make sure you didn’t clean the dovecot
# port when you’ve build it, eg: built it using:
# cd /usr/ports/mail/dovecot/ && make install
# You can clean it after you’ve build the sieve plugin though.

./configure \
–prefix=/usr/local \
make install

Configure dovecot to use the sieve plugin:

vim /usr/local/etc/dovecot.conf
protocol lda {

mail_plugins = cmusieve # … other plugins


Make a test sieve script:

cat <<„EOF“ > /var/vmail/
require [„fileinto“, „reject“, „vacation“];
# * A sieve script is UTF-8 encoded.
# * folders are automatically created by the „fileinto“ action.
# * By default (when no :comparator argument is given) all string
# comparations are case-insensitive (in the ASCII range;
# :comparator „i;ascii-casemap“).
# See the „2.7.3. Comparators“ section at
# See sieve information at
# For „vacation“ see

# Moved SPAM marked messages to the Spam folder and stop processing.
if header „X-Spam-Flag“ „YES“ {
fileinto „Spam“

# Move all mailer-daemon@ into a subfolder
if header
[„To“, „Cc“, „Bcc“, „Reply-To“, „In-Reply-To“]
„mailer-daemon at“,
„mailer-daemon at“,
„mailer-daemon at“
] {
fileinto „mailer-daemon“

# OR, using :matches:

if header
[„To“, „Cc“, „Bcc“, „Reply-To“, „In-Reply-To“]
[„mailer-daemon@*“] {
fileinto „mailer-daemon“

# move all mail to a subfolder.
if header :matches „To“ „*“ {
fileinto „foxie“

# Some misc. tests follow.

if header :contains „subject“ [„test1“, „test3“] {
fileinto „test-odd“
} elsif header :contains „subject“ [„test2“, „test4“] {
fileinto „test-even“
} elsif header „subject“ „reject“ {
reject „reject test!“
} elsif header „subject“ „discard“ {
# discarded message are silently droped.
} elsif header „subject“ „redirect“ {
# this will redirect the message to „root“ user, without storing the
# message in our mailbox.
# NB: Because, in my case, the „postmaster“ is an alias to this same
# mailbox, so we also test the loop prevention mechanism of
# dovecot LDA.
# AND in this case we will NOT receive any message on our email
# box.
# sent emails ids are stored inside ~/.dovecot.lda-dupes
redirect „postmaster at“
} elsif header „subject“ „redirect to bob“ {
redirect „bob at“
} elsif header „subject“ „vacation“ {
# sent emails ids are stored inside ~/.dovecot.lda-dupes in order to
# detect loops.
# List of auto replied senders are also stored here in order to
# prevent multiple replies to the same sender for a given period of
# time (defaults to 7 days [see src/libsieve/sieve.y]; min is 1 day,
# max is 31 days)
vacation „I’m out! I’ll reply when I get back“

NB: Errors on the sieve script are reported on the maillog and in a
file named .dovecot.sieve.err near the normal .dovecot.sieve.

# In this little „tests“, I have several test mailboxes, like
# rgl at, alice at, etc, which are handled by
# dovecot LDA with a sieve script.

printf ‘Subject: test1\n\ntesting!\n’ | sendmail rgl at

printf ‘Subject: reject\n\ntesting!\n’ | sendmail rgl at

printf ‘Subject: discard\n\ntesting!\n’ | sendmail rgl at

printf ‘Subject: redirect\n\ntesting!\n’ \
| sendmail -f alice at rgl at

printf ‘Subject: redirect to bob\n\ntesting!\n’ \
| sendmail -f alice at rgl at

printf ‘Subject: test2\nX-Spam-Status: Yes\n\ntesting!\n’ \
| sendmail rgl at

printf ‘Subject: vacation\n\ntesting!\n’ \
| sendmail -f alice at rgl at