Even more sieve extensions

What is Sieve?

Using rules to organise your mail as it arrives is a reasonably well understood concept. What is less well known is that the engine which runs the rules is called Sieve.

A sieve script consists of a number of tests which are applied to incoming mail: if a mail matches a test, then the actions associated with that test are performed.

Our rules system builds sieve scripts in the background.

test: "If the sender matches [email protected]"
action: "File into folder `URGENT: Mom`"

You can see your sieve script by going to your Mail Settings → Rules screen and using the "Edit custom sieve code" link.

Please be aware: Sieve is powerful and does have the ability to permanently delete and alter messages with no recourse to backup or undo your actions. If you’re not confident understanding Sieve and its extensions, using our rules and saved searches is safer.

What is a Sieve extension?

An extension provides extra mechanisms to test email or to take action on matching email. This capability has allowed the Sieve language to stay current over time, as additional headers and flags have become standard, and as people seek to use their email in more powerful ways.

While the list of possible Sieve extensions is enormous, FastMail periodically builds in support for additional extensions where we feel it benefits our users without compromising security.

Onto the good stuff: information on the new extensions you can now use!

New extensions

Variables extension

The filtering: variables extension lets you store and reference named data, allowing you to use information matched out of the test condition in the action body.

You can explicitly set variable values:

set "dollar" "$";

Variables can be filled using matching against patterns:

# Imagine the header
# Subject: [acme-users] [fwd] version 1.0 is out
if header :matches "Subject" "[*] *" {
    # ${1} will hold "acme-users",
    # ${2} will hold "[fwd] version 1.0 is out"
    fileinfo "INBOX.lists.${1}"; stop;
}

Caution: when match variables are used, strings can contain arbitrary values controlled by the sender of the mail.

Vacations seconds

The vacation seconds extension lets you specify the frequency your vacation auto-away message is sent down to the granularity of seconds. Use this in combination with the vacation extension for fine control of who receives what auto-away message, when.

Usage:

vacation [":days" number | ":seconds" number]
              [":subject" string]
              [":from" string]
              [":addresses" string-list]
              [":mime"]
              [":handle" string]
              <reason: string>

Example:

vacation :addresses ["[email protected]", "[email protected]"]
        :seconds 1800
        "I am in a meeting, and do not have access to email.";

Imap4flags

Imap4flags supercedes the imapflags extension. It allows you to set different IMAP flags on message delivery.

Example (which also demonstrates the variables extension):

    if header :contains "from" "[email protected]" {
        setflag "flagvar" "\Flagged";
        fileinto :flags "${flagvar}" "INBOX.From Boss";
    }

You can test for flags, add flags, and remove flags. Flag management can be combined with the variables extension, as above.

Editheader

The editheader extension allows you to add and delete header information from incoming mail.

Example:

   /* Don't redirect if we already redirected */
   if not header :contains "X-Sieve-Filtered"
           ["<[email protected]>", "<[email protected]>"]
   {
           addheader "X-Sieve-Filtered" "<[email protected]>";
           redirect "[email protected]";
   }

Note that changing header information can break DKIM signing if the signature includes header information.

Detecting duplicates

The detecting duplicates extension lets you test for duplicates on incoming mail. This is mostly useful when handling duplicate deliveries commonly caused by mailing list subscriptions or redirected mail addresses.

Example:

if duplicate {
     fileinto :create "Trash/Duplicate";
}

Further information

This has only been a taste of what each extension can do. The full list of options and possibilities is too large to explore in a single blog post.

Our help has more information on scripting with sieve, how to test sieve scripts, and a sieve FAQ.

Older post File storage and Dropbox
Newer post A blog post worth referring to
Why Gmail Users Are Switching to Fastmail

Looking for a way to upgrade your inbox? Fastmail’s productivity features help you simplify your workflow and save time.

Migrate to Fastmail from Skiff

Fastmail is a secure, privacy-first email service that has been serving users since 1999. If you're considering migrating from Skiff, you're in the right place!

How one customer used Fastmail’s Open API

Fastmail’s open API makes creating new and exciting tools easy for email enthusiasts.