The sieve language

Internally, FastMail uses the powerful sieve filtering language to apply rules to your incoming mail. The Settings → Rules screen just provides an easier way to build this sieve script. You can directly edit this script to create more complex rule sets. To do this, go to the Advanced → Rules screen and click the "View filter source" link at the bottom of the screen.

For more details on sieve, see:

Note that the final RFCs of these last sieve extensions have signification changes that are not currently supported.

The notify extension

This is a custom command available for FastMail sieve scripts, used for forwarding a small portion of a message. The notify command has the following syntax:

notify :method <method> :options [<destination>, <options>] :message <text>;

The parameters are as follows:


notify :method "sms"
   :options ["1-555-555-5555", "Squeeze", "High", "Length", "50"]
   :message "$from$ / $subject$ / $text$";

Notification loop checking

If you set up a notification to generate an email back to the same account (or even one that will eventually forward back to it), you may end up creating an infinite loop of notifications. This may even cause all of your SMS credits to be depleted by the large number of notifications that are generated.

To help prevent this, we try to detect loops. This works by looking for a [Notify …] section in the message subject and replacing it with [Notify*2 ...], and so on, until it reaches *5, at which point an error is generated and the notification is cancelled.

However, since this depends on the subject of the notification message, you still run the risk of loops if you use a custom <text> string. You should exercise caution if you use a custom <text> string to avoid this possibility.

Effects of sieve

Many (but not all) of the choices you make in the Settings screens change the default sieve script, not just the Rules screen. If you have not manually edited your sieve script, then this default script is used by your account to process incoming messages. But if you edit anything in the script and save it, then the default sieve script is automatically commented out and copied to the end of your manually created script. Any Settings screen changes will modify the commented out code. Choosing revert sieve script will send to your Inbox an email containing as an attachment a copy of your old script (including the commented out default automatically generated default script), then discard your edited script and use the previously commented-out default script.

This combination of internally coded features, automatically generated default sieve code, and manually edited sieve code has allowed FastMail to add additional features and gives you the ability to modify some (but not all) behaviour. But sieve is a standard, and formal extensions need to be officially proposed and implemented before we will have access to them. The behaviour which is internally coded (independent of sieve) can't be changed by the user unless an Option menu is available for that feature.

Sieve scripts on our beta server

We currently have new system on our beta server that allows you to combine the default sieve script, built from your Settings, with custom sieve code. Many FastMail features rely on adding to your sieve script. At the moment, these features break if you start writing a custom sieve script and do not add the required code yourself.

Under the new system, rather than having a "custom script" option, there's now a new "Advanced" tab on the AdvancedRules screen. Under that tab, there's a single text area. The content of that area is treated specially as "blocks". Each block has a special format, and it allows you to insert the content of the block into various parts of the sieve generation process.

Block format

The format of each block is as follows:

### BlockName {{{

... sieve code in here ...

### }}}

You can have multiple blocks defined. The order of blocks isn't important, but the name of each block (e.g. BlockName) is. You can only have blocks as defined above, or commented out text (i.e. lines that start with #) in the text area. Any other text will cause an error.

Block names

The following block names are currently available:

Each block is inserted into the generated sieve as shown below.

Generated sieve

The following is the current overall form of the final generated sieve:

require [ ... ];



if not *secret-word-match* {

if *inbox-rules* { keep; } elsif
*folder-rules (order <1000)*
*folder-rules (order >=1000)*




Some blocks may be empty if nothing is defined for them in the settings.

There's also one other special block, ReplaceAll. If that block exists, then all the rules will be replaced solely with the content of the ReplaceAll block. This is NOT recommended, and is only currently there as a migration solution from the old full custom rules situation. We highly discourage it, and may find a way to get rid of it.