account control center

Roller Network Help - Sieve

You can edit Sieve rules with a user-friend interface in our Webmail client: https://www.rollernet.us/webmail/

Sieve can be used with any managesieve client by connecting to the hosted mail server on port TCP/4190. These interfaces may also be used as an alternative to writing rules directly even if you don't use webmail.

Advanced users can use our web-based ManageSieve is at: https://acc.rollernet.us/mail/sieve/

What is Sieve?

Sieve is an email filtering language (RFC 5528). When you create and upload a Sieve script to your mail box account, it is executed every time your mail box receives a message. The most common task performed using Sieve is sorting/filing messages into folders. To take full advantage of what Sieve can offer, you will need to use IMAP to access your hosted mail box.

Supported Extensions

We use Dovecot with the Dovecot Sieve plugin.

Sieve scripts must now use / as the separator (instead of .) for folder paths when using the fileinto action due to back end changes required to enable shared folder namespaces.

  Status Purpose
fileinto yes Allows storing messages in folders other than INBOX
envelope yes Allows evaluating envelope parts, i.e. sender and recipient
encoded-character yes Allows encoding special characters numerically
copy yes Allows storing and forwarding messages without canceling the implicit keep
body yes Allows evaluating the body of a message
variables yes Adds variables support to the language
vacation yes Provides auto-responder functionality, e.g. for when the user is on vacation
relational yes Provides relational match support
imap4flags yes Allows adding IMAP flags to stored messages
subaddress yes Allows testing against delimited elements of the local part of addresses
reject yes Allows rejecting messages with a rejection bounce message
enotify yes Provides the ability to send notifications by various means (currently only mailto)
mailbox yes Provides a mailbox existence check and allows creating mailboxes upon fileinto
environment basic Allows testing against various labeled values from the execution environment
date yes Adds the ability to test date and time values in various ways
regex yes Provides regular expression match support
spamtest and virustest experimental Implements a uniform way to test against headers added by spam and virus scanners
include yes Allows including other Sieve scripts
imapflags(old draft) yes (compatability) Old version of imap4flags
notify (old draft) yes (compatability) Old version of enotify

Source: http://wiki.dovecot.org/LDA/Sieve

Why use Sieve?

Sieve is a uniform way to manage email. Keep in mind that it is not an anti-spam tool. By using Sieve as a replacement for message rules in your email client, you don't have to duplicate rules everywhere you access your email. Our server performs the task of running message rules. Sieve works even when you aren't checking your email or your computer is turned off.

All of this may seem confusing if this is the first time you've heard of Sieve, so we'll start with a quick example script:

require ["fileinto", "imapflags"];

if exists "X-Spam-Flag" {
  addflag "\\Seen";
  fileinto "Junk";
  stop;
}

This simple script will look for the "X-Spam-Flag" header from SpamAssassin. If it's found, it will move the message into a folder called "Junk" and mark it as read. SpamAssassin only adds this header if the messages scores as spam.

Expanding on that example, let's say you are on some mailing lists and you want to keep those messages in their own folders.

require ["fileinto", "imapflags"];

if header :contains "subject" "[c-nsp]" {
  fileinto "Mailing Lists/cisco-nsp";
}
elsif address :is ["to","cc"] "list@inet-access.net" {
  fileinto "Mailing Lists/inet-access";
}
elsif exists "X-Spam-Flag" {
  addflag "\\Seen";
  fileinto "Junk";
}
else {
  keep;
}

This example combines several more concepts and adds an explicit "keep" to the end. You can also see we used two different ways of identifying different mailing lists; one with a subject tag and the other with its list address.

Since Sieve is a language, you can design rules (from simple to extremely complex) that suit your needs.

Managing your Sieve Scripts

Our ManageSieve interface is very simple: you can view, add, edit, and delete Sieve scripts. When adding a script for the first time it is not automatically activated. To activate a script simply select it from the "Active" column in the script display table. You can also deactivate a script without deleting it by clicking on its "Active" selector (requires JavaScript). The Sieve specification only allows one script to be active at a time.

Sieve Basics

A Sieve script is a series of conditions and actions in an if/elsif/else structure. (Note the spelling of "elsif".) The "if" statement must always come first, optionally followed by any number of "elsif" statement, and optionally ending with an "else" statement. The "else" statement does not have a condition; it essentially means if none of the above conditions matches, then do this. (See the example above.)

Condition  
header Any header in the message.
address Compares a header's email address.
allof (condition1, condition2, ...) List of conditions, all of which must be true.
Identical to a logical AND.
anyof (condition1, condition2, ...) List of conditions, any of which may be true.
Identical to a logical OR.

To use a condition, you need a comparator with it:

Comparator  
:is True if the value matches the specified string exactly.
:contains True if the value contains the specified string.
:over
:under
For numeric value comparisons: greater than and less than.

Finally, you need an action to perform if your condition is matched. Actions always go between the curly braces, and you can have more than one action for a condition. Action statements must end with a semicolon.

Action  
fileinto "folder" Moves the message into a folder or subfolder.
discard Deletes the message.
keep Keeps the message; cancels a discard.
stop Stop here and exit the script.
reject "message" Rejects with an optional message.

Sieve "require" Statement

Some extensions of Sieve require optional modules to be loaded. This is performed by listing them in a "require" statement at the beginning of your sieve script.

Please note: Some extensions are capable of sending email, such as "reject" and "vacation". While we currently allow these, we reserve the right to disable Sieve's ability to originate messages in the future if it becomes an issue with spam or backscatter.

Putting It Together

Now that you know the basics of Sieve we can put them together and make a script. Statements are assembled in the format "if condition comparator where what { action }":

# this is a comment line
require "reject";

# reject messages from people we don't like
if address :contains ["sender","from"] "example.org" {
  reject "Sorry, your location is not authorized.";
  stop;
}

If you have a keen eye, you'll notice we used ["sender","from"] in the "where" part of the conditional statement. Sieve uses [ and ] to form lists. List items are quoted and separated by commas. These lists let us search for more than one thing in more than one location. We could expand the above example to reject all messages from two different domains by using ["example.org", "example.net"] instead.

In this next example, we'll show how to use the anyof() condition.

require "fileinto";

# this example files arin.net email and mailing lists to a single folder
if anyof (
  header :contains "subject" ["[arin-ppml]","[arin-announce]"],
  address :contains "from" "arin.net"
) {
  fileinto "ARIN";
}

This next one is an interesting example. What if you want to be alerted when a message from a certain email address arrives? You can do this with the "notify" extension.

require "notify";

if address :contains "from" "important@example.net" {
  notify
    :method "mailto"
    :options "notifyme@example.com"
    :message "Message from important@example.net";
}

Executing actions based on whether or not a certain header is present uses a slightly different format as shown in this example:

require "fileinto";

# SpamAssassin will add X-Spam-Flag header if it scores as spam
if exists "X-Spam-Flag" {
  fileinto "Junk";
  stop;
}

Of course, you can mix and match all of these examples into a single Sieve script, and write your own conditions. The ManageSieve web interface will validate your script before it uploads and it will notify you of any errors.

Sieve.Info

For more information on Sieve, see the sieve.info website.

Sieve is still in draft status, and is therefore continuing to expand and evolve.

Sample Scripts

This script will redirect anything sent from the domain "example.com" or from email address "user@example.net" to email address "copy@example.org".

if address :contains
  ["sender","from"]
  ["example.com","user@example.net"]
{
  redirect "other@example.org";
}

Or, you can mirror messages to another address by using "copy" as such:

require ["copy"];
if address :contains
  ["sender","from"]
  ["example.com","user@example.net"]
{
  redirect :copy "other@example.org";
}

This script will place messages into a subfolder by date:

require ["date", "variables", "fileinto"];
if currentdate :matches "date"  "*" { set "date"  "${1}"; }
if currentdate :matches "year"  "*" { set "year"  "${1}"; }
fileinto "${year}/${date}";
Please note: Messages sent using the "redirect" action must never be rejected by the destination address. While we currently allow this action, we reserve the right to disable Sieve's ability to originate messages or apply strict filters to outgoing messages in the future if it becomes an issue with spam or backscatter.

Sieve Forwarding and SPF

The mechanisim that Sieve used to send messages (i.e. the "redirect" action) is not SPF safe. We do not recommend using Sieve for forwarding.

Home | Account Control Center | Status | Help | Contact | Policy

© Roller Network LLC