Author: Aaron Stone
Updated: December 14, 2006


Sieve (see is an Internet-standard language for sorting and filtering email. It's not a general purpose language, it's not Turing-complete, and it lacks lots of features common to most computer languages. What it does have is an innate understanding of email and a decidedly tight tying to your mail server.

Sieve and DBMail

  • Run scripts on messages as they arrive at a user's mailbox.
  • Manage stored scripts using the “Tim's Sieve Daemon” draft-protocol.
  • Compliant with RFC 3028, and its updates, related RFC's and useful drafts.

The libSieve Library

libSieve is a library that implements RFC 3028 SIEVE, several related RFC's and several useful drafts. It is based on an early snapshot of CMU Sieve from the Cyrus project, heavily reworked to be an independent library, and updated to include newer RFC's and updated versions of useful drafts.

Sieve Actions

Actions listed in bold are qualified by the keyword MUST in RFC 3028. Others are qualified by SHOULD or are extensions defined in other RFC's or draft RFC's.

  • Keep - Works.
  • Discard - Works.
  • Redirect - Works.
  • Fileinto - Works.
  • Reject - Works.
  • Vacation (ext) - Works.
  • Imapflags are supported with Fileinto and Keep. We support \\Flagged, \\Deleted, \\Seen, \\Answered, \\Draft, \\Recent. Arbitrary or user-specified flags are not supported.

We are ready for the Include draft specification on the DBMail side, but libSieve does not have the most recent version of Include prepared.

Other extensions are just wishful thinking right now. Post here if there's something you really want, though!

Sieve Script Basics

First the sieve script need to be created, before we can insert it into the sieve server. To do this we create a file called sieve.script. The script shown here tries to file DBMail mailingslist mails into a seperate mailbox. Open sieve.script with you favorit editor, and insert the folowing script:

require "fileinto";
if header :contains ["To","From","Cc"] "" {
   fileinto "dbmail";

Then using the “if header :contains” lets the sieve parser check for the To, From and Cc header in the message and see if they contain “”. If this is true, the script between the braces is parsed. With the fileinto module the mailbox is set to “dbmail”. With the stop commmand further script processing is aborted, and the message is filed into the mailbox. If the script doesn't set a mailbox it the message is inserted into the default one “INBOX”.

Now, let us insert our message into the DBMail server. We're the dbmail-sievecmd to insert the message:

dbmail-sievecmd -u USERNAME -i MYSCRIPT sieve.script

Change USERNAME and MYSCRIPT to suit your needs. MYSCRIPT is the name of the script. It is possible to have multiple scripts in the DBMail server, and activated them when needed. Keep in mind it is only possible to have one script activated simultaniously.

So now let's activated our script:

dbmail-sievecmd -u USERNAME -a MYSCRIPT

The script is now activated, and should automatically do its work everytime a message arives.

Note: If working with scripts from an existing cyrus implementation, the seperator must be changed from '.' to '/' like so

fileinto "";


fileinto "INBOX/foo";


  • dbmail-sievecmd, dbmail-timsieved are both utilities to manage Sieve scripts. They do not need to be available at message delivery time, only at script upload time. e.g. in a DBMail cluster, you don't need dbmail-timsieved to be running on every frontend node. Just one should suffice because relatively few users will be modifying their Sieve scripts at any given moment.
  • A Sieve script is checked for correct syntax when it is uploaded. Other sorts of runtime errors may occur and will result in a Sieve Error message appearing in the user's INBOX.


Using the “reject” sieve action may generate a protocol-level LMTP rejection, but that will in turn case the MTA to generate a DSN back to the envelope sender. There has been significant discussion on the IETF Sieve mailing list about the need to do protocol level rejections, and the need to do UTF-8 rejections. The two are potentially mutually exclusive, because the MTA may or may not support UTF8SMTP.

User wants MTA implements What happens
SMTP 550 w/Unicode UTF8SMTP Your Unicode message is sent as part of the 550 message.
SMTP 550 w/Unicode nothing Your Unicode message cannot be handled. Bad things happen.
SMTP 550 W/o Unicode whatever Your ASCII message is sent as part of the 550 message.
MDN w/w/o Unicode whatever Your message is sent to the envelope sender. May allow Joe Jobs.

Development Ideas

Multiple Scripts

It would be useful if the administrator could set up system-wide Sieve scripts, and create scripts that can be accessed from the “include :global” namespace when the include extension is completed.

With the possibility of there being so many scripts, access control also comes to mind. Let's say that all of the sysadmin's scripts live in the :global namespace. What if the sysadmin doesn't want some scripts to be available? What about making them available only to some users? Without going crazy on a full ACL system (or exactly going crazy and re-using the IMAP acl system and the tables we have to represent it), what are the use cases and what can we reasonably implement?

Another important consideration for ACL's comes up in connection with IMAPSieve, which may eventually replace ManageSieve as the preferred interface for managing Sieve scripts, and the only interface for connecting Sieve scripts to IMAP actions.

sieve.txt · Last modified: 2012/02/27 21:27 by bas
DBMail is developed by Paul J Stevens together with developers world-wide