Overview
Sieve is a scripting language for filtering and modifying email messages. Rather than inventing a proprietary DSL, Stalwart uses Sieve because it is an established internet standard well suited to the range of filtering and transformation tasks encountered in email delivery.
A Sieve script consists of one or more rules, each combining a test and an action. The test inspects an attribute of the message, such as the sender’s address or the subject line; the action specifies what to do when the test matches. This documentation focuses on how Sieve is integrated into Stalwart (interpreters, variables, expressions, function reference, examples) rather than on Sieve syntax itself; tutorials covering the language are collected at sieve.info.
Stalwart extends the standard Sieve language with its own expression syntax and a rich set of built-in functions for DNS queries, directory lookups, SQL queries, hashing, image and MIME inspection, and more, all accessible from the eval, let, and while instructions.
Testing scripts
Section titled “Testing scripts”Sieve has no statement for printing a value or writing to a log, and a script installed on the server runs unseen at delivery time, so checking a filter has traditionally meant sending test messages and looking at where they land. Sievepad removes that round trip. It is a playground that runs the Stalwart Sieve interpreter in the browser, compiled to WebAssembly, so a script is compiled and executed by the same code the server uses, with no Stalwart installation involved. Scripts, test messages and settings are stored in the browser and are never uploaded.
The editor compiles the script as it is typed and underlines each error at the position reported by the compiler. Running the script against a test message lists the actions it takes, such as fileinto, reject or a vacation reply, and shows every message it modifies or generates. Envelope addresses, mailboxes, spam and virus scores, the current time and the other values a script can test are set per workspace, and a workspace can be shared as a link that carries its scripts inside the URL.
Sievepad supports the vnd.stalwart.expressions and vnd.stalwart.while extensions with the functions available to the untrusted interpreter. Functions restricted to the trusted interpreter, which reach external systems such as DNS, HTTP, SQL, key-value stores and LLM providers, are not available, and a script that calls them fails to compile. A system script that omits require, which the trusted interpreter accepts while noCapabilityCheck is enabled, needs the same setting in Sievepad.
Examples in this documentation that run in Sievepad are followed by a “Try this script in Sievepad” link, which opens the example in Sievepad together with the test message and settings needed to exercise it.
Supported extensions
Section titled “Supported extensions”The Sieve interpreter included in Stalwart supports the following extensions:
- RFC 5228 - Sieve: An Email Filtering Language
- RFC 3894 - Copying Without Side Effects
- RFC 5173 - Body Extension
- RFC 5183 - Environment Extension
- RFC 5229 - Variables Extension
- RFC 5230 - Vacation Extension
- RFC 5231 - Relational Extension
- RFC 5232 - Imap4flags Extension
- RFC 5233 - Subaddress Extension
- RFC 5235 - Spamtest and Virustest Extensions
- RFC 5260 - Date and Index Extensions
- RFC 5293 - Editheader Extension
- RFC 5429 - Reject and Extended Reject Extensions
- RFC 5435 - Extension for Notifications
- RFC 5463 - Ihave Extension
- RFC 5490 - Extensions for Checking Mailbox Status and Accessing Mailbox Metadata
- RFC 5703 - MIME Part Tests, Iteration, Extraction, Replacement, and Enclosure
- RFC 6009 - Delivery Status Notifications and Deliver-By Extensions
- RFC 6131 - Sieve Vacation Extension: “Seconds” Parameter
- RFC 6134 - Externally Stored Lists
- RFC 6558 - Converting Messages before Delivery
- RFC 6609 - Include Extension
- RFC 7352 - Detecting Duplicate Deliveries
- RFC 8579 - Delivering to Special-Use Mailboxes
- RFC 8580 - File Carbon Copy (FCC)
- RFC 9042 - Delivery by MAILBOXID
- REGEX-01 - Regular Expression Extension (draft-ietf-sieve-regex-01)