Filtering Rules
Rules run when mail arrives
Section titled “Rules run when mail arrives”Each mailbox account can hold Sieve scripts (RFC 5228) and have one of them active. When a message is delivered to the account, the active script runs on it and decides where the message is filed, which flags it carries, or whether it is dropped. A script runs once per account per message, however many of the account’s addresses the message was sent to.
Scripts are stored and managed over JMAP with the Sieve extension (RFC 9661). An account without an active script is unaffected: mail goes where spam and phishing protection puts it, to the Inbox or to Junk.
Editing rules
Section titled “Editing rules”- In webmail. Open Mail Rules under Settings, or choose Manage Mail Rules in the account menu of the folder tree. Webmail lists, creates, edits, activates and deletes the rules it generates.
- With any Sieve-capable JMAP client. Connect the client to your JMAP endpoint and sign in with a user or token that holds the Sieve permissions. The server advertises the Sieve capability in the JMAP session, together with the limits and extensions below. Scripts are uploaded through the standard JMAP upload endpoint and saved with
SieveScript/set;SieveScript/validatechecks a script without saving it.
A script that uses anything outside the supported features is refused when it is saved, with the line it failed on, so a saved script never contains something the server cannot run.
Supported features
Section titled “Supported features”| Feature | Supported |
|---|---|
| Actions | keep, discard, stop, fileinto |
| Extensions | fileinto, copy (fileinto :copy), imap4flags, body, envelope |
| Comparators | i;ascii-casemap (the default) and i;octet |
The envelope test reads the sender address (from) and the address the message was delivered to (to), as opposed to the addresses shown in the message headers.
Forwarding (redirect) and automatic replies (vacation) are not offered; see the roadmap. A script that executes a redirect fails (see When a script fails): the message is kept and a notice is sent.
A test that reads message headers fails the script when the headers are larger than 256 KiB, and a test that reads a body part fails it when the part is larger than 512 KiB. The message is kept in both cases.
Limits per account: 16 scripts of up to 32 KiB each, with names of up to 512 bytes. SieveScript/query sorts scripts by name with the i;unicode-casemap collation unless the client asks for another one.
Where fileinto puts a message
Section titled “Where fileinto puts a message”- A folder is named by its full path from the top, joined with
/, for exampleInbox/InvoicesorWork/Clients/Acme. Names are matched without regard to case. INBOXandJunkalways mean the account’s Inbox and Junk folders.- A name that matches no folder, or matches more than one folder, does not file the message. The script is treated as failed, and the message is delivered to its default location (see below).
Folders are never created by a script. Create the folder first.
imap4flags flags become JMAP keywords on the stored message. \Seen, \Flagged, \Answered and \Draft become $seen, $flagged, $answered and $draft; other \ flags are ignored; any other flag is stored as a lowercase keyword. When a script files a message under different flags, each distinct set of flags produces its own message: fileinto :flags "\\Seen" "A"; fileinto :flags "\\Flagged" "B"; stores one seen message in A and one flagged message in B. Filing a message into the same folder under different flags stores it once, with the flags of the last action.
Junk and virus handling
Section titled “Junk and virus handling”- A message that spam or phishing protection placed in Junk still runs through your script. The script can move it out with
fileinto, and the junk flag is removed from a message that leaves Junk. - A message in which a virus was detected is never run through a script. It goes to Junk and stays there.
discardis final: a discarded message is not stored in any folder, and the mail log records it as discarded.
When a script fails
Section titled “When a script fails”If a script cannot complete on a message, none of its filing actions are applied. The message is delivered to its default location, the Inbox or Junk, and the mail log marks the delivery as a script error. Mail is never lost to a failing script.
A script fails on a message when:
- a
fileintofolder name matches no folder or several folders, - the script executes a
redirect, - a header or body part that a test reads is over the size limits above,
- the script runs longer than two seconds,
- the script stops with an error while running,
- the script cannot be loaded,
- the script fails unexpectedly.
When too little processing time is left to run the script, the message is not delivered without it: the delivery is tried again with a fresh time allowance.
Every one of these ends the same way: the message goes to its default location and the delivery is marked as a script error.
Alongside the message, a notice is delivered to the account’s Inbox. It names the script, states the problem and identifies the affected message. At most one notice is sent per script per 24 hours, not one per error, so a script that fails on every message does not flood the Inbox. A notice is skipped when the delivery has too little time left to store it; the next failing message sends it.