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.


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


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


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.


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


   /* 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.


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
Get the Best In Email: How Domenic Uses Fastmail
04 Jun 2024 Customer Stories

Fastmail makes it easy to organize and prioritize the messages that are most important to you. Domenic, a web developer, uses Fastmail personal domains, aliases, folders, labels, and more.

How Fastmail + Morgen Power Tom’s Productivity

Fastmail is happy to partner with other tools and services, like Morgen, that help our customers make better use of their valuable time.

How Ellane Uses Fastmail to Balance Business and Personal Email

Fastmail provides peace of mind by protecting your data and upgrading your email experience. Ellane supports her unique workflow using rules, folders, aliases, and more.