Sieve in the SCS Environment

Sieve, one of several Corvid mechanisms for filtering email, is a server-side mail-processing system built into the Cyrus IMAP server.

Intended to be simple, Sieve only processes mail at delivery time  mail delivered to the IMAP server will only pass through Sieve once. Sieve's command set is somewhat limited, in an attempt to reduce the possibility of mail loops (or similiar effects of "clever" behavior). While simple, Sieve is sufficiently powerful deal with most common tasks involving incoming mail at delivery time.

What Sieve Can Do

Based on an email message's specific characteristics, Sieve can perform numerous operations. Common tasks include:

Since the most common operations involve filtering spam and setting up vacation messages, Sieve provides the Websieve script editor, which can quickly generate and control appropriate scripts for these purposes.

Note: The simple editor interface generates a new script each time it runs  it does not preserve state and does not remember previous settings. For more permanent solutions, use either the advanced editor or sieveshell, as below.

Customized Sieve Scripting

While the script editor facilitates common tasks, customized Sieve scripts can exploit Sieve's full power. These simple text files reside on the IMAP server, and each user has a protected space for scripts. Users can maintain several Sieve scripts on the server, but only one can be active at a time.

There are currently two supported methods for managing scripts: a Websieve interface and a command-line one.

Custom scripts with the Websieve interface

The "Advanced Use" section of the Websieve interface allows listing scripts on the server, inspecting scripts, adding and removing scripts, editing scripts in place, and selecting the active script. The tool also checks script syntax and will prevent installing a broken script. To use this tool, select the "Advanced Mail Filtering" link from the front page of the Websieve interface. (will open in a new browser window)

The "Advanced Mail Filtering" page includes tools to list scripts on the server, activate and deactivate scripts, inspect individual scripts and edit them in place. The tool checks all edited scripts for syntax and will prevent installing a broken script.

Note: the Websieve tool does not activate scripts by default  processing will only occur if a script is activated. The currently enabled script can be determined by checking which script is designated as (ENABLED) in the list of scripts. If no script is so designated, no processing will take place, and all mail will be delivered to the default location (INBOX).

Custom scripts with sieveshell

The sieveshell Unix command-line tool, available in the SCS computing environment as part of the Corvid system:

bovik$ sieveshell imap.srv.cs.cmu.edu

sieveshell can list scripts on the server, inspect scripts, add and remove scripts from the server, and select the active script. The tool will check all new scripts for syntax and will prevent installing a broken script.

The help command will show a list of available commands, with a brief description for each. The following commands are available:

help  display the help screen

list  list available scripts on the server

put <filename>  upload filename to the server

get <scriptname> [<filename>]  Display scriptname (if a filename is given, save the script to that file)

delete <scriptname>  delete the script scriptname

activate <scriptname>  set scriptname as the active script

deactivate  deactivate all scripts

quit  quit the sieveshell utility

Note:sieveshell does not activate scripts by default  processing will only occur if a script is activated. The currently enabled script can be determined by checking which script is designated as the active script in the list of scripts. If no script is so designated, no processing will take place, and all mail will be delivered to the default location (INBOX).

A Sieve Cookbook  General notes

The Sieve processing system uses a scripting language to process mail. While each user may keep multiple scripts on the server, only one can be active at one time. Sieve scripts execute in order and will generally try to continue processing mail until told to stop (either implictly by using a command like fileinto, or explicitly). The default action delivers mail into the user's INBOX.

While we recommend keeping scripts as simple as possible, Sieve can be a powerful tool! Please exercise care when writing and testing Sieve scripts; it is possible to lose mail irretrievably with a badly formed script.

Sieve-script syntax is important; both the Websieve interface and sieveshell will check your syntax for you and prevent installing broken scripts.

Comments

Any line starting with a "#" is treated as a comment. This feature provides a useful means to document what a script does, especially if the script gets "clever."

The require line

All Sieve scripts must begin with a require statement, which defines what extensions the Sieve subsystem can use to process mail. In most cases, this line should include all available extensions, for example:

The :days keyword will set the notification timeout for sending vacation messages. Sieve keeps track of who has received vacation notification messages from a user, and can hold off on sending responses even if the sender continues to send mail. In the above example, Sieve will wait three days between sending automatic notifications. Note: this should not be used to specify the length of a vacation; turning off vacation messages is accomplished by activating another script.

The :addresses keyword is used to list mail addresses that require an automatic apply. The vacation extension works on strict matches, so if the user has multiple email addresses, they should be listed here.

The :subject keyword specifies the Subject line of the automatic response mail.

The remainder of vacation stanza is the body of the automatic response mail, enclosed in double quotes and terminated with a semicolon.

Sieve Script Examples - Putting it all together

Our good Professor Bovik wants to set up two scripts: a general-purpose one that does typical filtering duties and a travelling version that he can use on the road.