- What is Sieve?
- Basic Sieve guide
- Modifying the Sieve script
- Sieve supported extensions
- Frequently Asked Questions
- Sieve examples
What is Sieve?
Sieve is a programming language for filtering incoming emails. Fastmail's flexible rules system provides most users with filtering functionality, but advanced users may choose to write custom Sieve scripts for complicated filtering (such as time-based rules).
A Sieve script consists of a number of tests which are applied to incoming mail; if an email matches a test, then the actions associated with that test are performed.
Sieve scripts can be used to automatically delete or forward messages; to send autoreplies; to sort emails into folders as they arrive; to mark messages as read or flagged; to test messages for spam or viruses; or to reject messages at or after delivery. Sieve.info has more information on Sieve and its uses.
To create custom Sieve scripts, go to the Settings → Filters & Rules screen and click on Edit custom Sieve code at the bottom of the screen.
The rules system creates a Sieve script behind the scenes, and the advanced rule editing functionality allows you to write additional filtering actions to supplement your existing rules.
Sieve is a powerful language. It is possible to create a rule which permanently discards mail without the protection of our backup system, so be careful.
Modifying the Sieve script
The Sieve editing screen has four unchangeable blocks with Sieve code automatically generated by us based on choices you make within the Settings screens, separated by four editable text areas in which you can place your own custom Sieve code.
A standard Sieve editing section with no custom rules applied might look like this:
Sieve code is run in order, so custom code can be placed in different sections depending on which rules you want to be run first. In most cases, you will want spam filtering to be run on your messages, so you would usually place your code under the block that is generated for spam filtering.
In some limited cases, you might want your code to take place before spam filtering, in which case you would place your code in the top section, above the Sieve code generated for spam protection.
If you want to add a note to yourself so you remember why you added a piece of code later on, you can do this by adding
# to the beginning of your line.
Sieve supported extensions
Sieve has a lot of extensions. Fastmail supports some of these, as given below:
- Sieve language reference - fileinto, reject
- Vacation extension
- Vacation seconds Extension
- Relational Tests - relational, envelope, body, comparator-i;ascii-numeric
- Filtering: Variables Extension
- Subaddress Extension
- Copying Without Side Effects
- Regular Expression Extension
- Checking mailbox status and accessing mailbox metadata
- Date and Index Extension
- IMAP4flags Extension
- Body Extension
- Editheader Extension
- Detecting duplicates Extension
This is encompassed by the line which appears at the top of your custom Sieve script:
require ["fileinto", "reject", "vacation", "imap4flags", "notify", "envelope", "body", "relational", "regex", "subaddress", "copy", "mailbox", "mboxmetadata", "servermetadata", "date", "index", "comparator-i;ascii-numeric", "variables", "editheader", "duplicate", "vacation-seconds"];