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.
Settings
3 items
Variables
Sieve scripts have access to a number of variables that can be used to obtain information about the current SMTP session, the message being processed and the environment in which the script is executed.
Expressions
The expression extension introduces the ability to evaluate arithmetic, logical, and comparison operations within Sieve scripts. This is useful for computing values from the current message and environment, and for controlling the flow of a script based on conditions that the base Sieve language cannot express.
LLM Integration
Stalwart extends the Sieve scripting language with the llm_prompt function, which lets scripts run AI analysis as part of email processing rules. This function allows administrators and users to access any of the LLM AI models configured in Stalwart directly from a Sieve script.
ManageSieve
ManageSieve is a protocol for remotely managing Sieve scripts on a mail server. Sieve scripts filter and sort incoming email based on rules defined by the user or the administrator. ManageSieve provides a standard way to upload, download, edit, and delete those scripts from a remote client, typically a supported email client or a web interface.
JMAP for Sieve
JMAP for Sieve (RFC9661) is an extension to the JMAP protocol that allows users to manage their Sieve scripts using the JMAP API. This extension provides a way for users to upload, delete, and list their Sieve scripts, as well as to set a default script for their account.
Reference
Stalwart extends Sieve with a set of built-in functions that can be called from expressions inside eval, let, and while instructions. The functions operate on Sieve values (strings, integers, floats, arrays) and on the message being processed: headers, MIME parts, envelope, and environment.
Examples
This section collects example Sieve scripts that can serve as a starting point for custom rules. Each example is stored as a SieveSystemScript record (found in the WebUI under Settings › Sieve › System Scripts) and invoked from the relevant SMTP stage by setting the stage's script expression to the script's name.