Sieve (mail filtering language)
Encyclopedia
Sieve is a programming language
that can be used to create filters for email
. It owes its creation to the CMU Cyrus Project, creators of Cyrus IMAP server.
The language is not tied to any particular operating system or mail architecture. It requires the use of RFC 2822-compliant messages, but otherwise should generalize to other systems that meet these criteria. The current version of Sieve's base specification is outlined in RFC 5228, published in January 2008.
Sieve differs from traditional programming languages in that it is highly limited - the base standard has no variables, and no loops, preventing runaway programs and limiting the language to simple filtering operations. Although extensions have been devised to extend the language to include variables and, to a limited degree, loops, the language is still highly restricted, and thus suitable for running user-devised programs as part of the mail system.
There are also a significant number of restrictions on the grammar
of the language, in order to reduce the complexity of parsing the language, but the language also supports the use of multiple methods for comparing localized strings, and is fully Unicode
-aware.
The Sieve scripts may be generated by a GUI
-based rules editor or they may be entered directly using a text editor
.
The scripts are transferred to the mail server in a server-dependent way. The ManageSieve protocol (defined in RFC 5804) allows users to manage their Sieve scripts on a remote server. Mail servers with local users may allow the scripts to be stored in e.g. a .sieve file in the users' home directories.
A number of other extensions are still being developed by the Sieve working group.
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
that can be used to create filters for email
Email
Electronic mail, commonly known as email or e-mail, is a method of exchanging digital messages from an author to one or more recipients. Modern email operates across the Internet or other computer networks. Some early email systems required that the author and the recipient both be online at the...
. It owes its creation to the CMU Cyrus Project, creators of Cyrus IMAP server.
The language is not tied to any particular operating system or mail architecture. It requires the use of RFC 2822-compliant messages, but otherwise should generalize to other systems that meet these criteria. The current version of Sieve's base specification is outlined in RFC 5228, published in January 2008.
Sieve differs from traditional programming languages in that it is highly limited - the base standard has no variables, and no loops, preventing runaway programs and limiting the language to simple filtering operations. Although extensions have been devised to extend the language to include variables and, to a limited degree, loops, the language is still highly restricted, and thus suitable for running user-devised programs as part of the mail system.
There are also a significant number of restrictions on the grammar
Grammar
In linguistics, grammar is the set of structural rules that govern the composition of clauses, phrases, and words in any given natural language. The term refers also to the study of such rules, and this field includes morphology, syntax, and phonology, often complemented by phonetics, semantics,...
of the language, in order to reduce the complexity of parsing the language, but the language also supports the use of multiple methods for comparing localized strings, and is fully Unicode
Unicode
Unicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...
-aware.
The Sieve scripts may be generated by a GUI
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...
-based rules editor or they may be entered directly using a text editor
Text editor
A text editor is a type of program used for editing plain text files.Text editors are often provided with operating systems or software development packages, and can be used to change configuration files and programming language source code....
.
The scripts are transferred to the mail server in a server-dependent way. The ManageSieve protocol (defined in RFC 5804) allows users to manage their Sieve scripts on a remote server. Mail servers with local users may allow the scripts to be stored in e.g. a .sieve file in the users' home directories.
History
The language was standardized in the (now-obsolete) RFC 3028 of January 2001, by Tim Showalter.Extensions
The IETF Sieve working group has updated the base specification in 2008 (RFC 5228), and has brought the following extensions to Proposed Standard status:- RFC 5173 - Body; allows a script to test the body of a message, not just its header.
- RFC 5229 - Variables; allows the script to save and retrieve values in variables.
- RFC 5230 - Vacation; specifies an action to send a response informing the sender that the recipient may be away.
- RFC 5231 - Relational tests; defines numeric tests, so that a script may test a field for a numeric value, and may test against the number of occurrences of a field.
- RFC 5232 - IMAP4flags; allows a script to test and set a message's IMAP flags.
- RFC 5233 - Subaddress; allows a script to test subaddresses of the form "user+detail@domain.example".
- RFC 5235 - Spamtest and Virustest; allows a script to interface with implementation-dependent message filtering.
- RFC 5293 - Editheader; allows a script to add and delete message header fields.
- RFC 5429 - Reject; allows messages to be rejected at either the LMTP/SMTPSimple Mail Transfer ProtocolSimple Mail Transfer Protocol is an Internet standard for electronic mail transmission across Internet Protocol networks. SMTP was first defined by RFC 821 , and last updated by RFC 5321 which includes the extended SMTP additions, and is the protocol in widespread use today...
level or with an MDN or DSN. - RFC 5435 - Notifications; allows a script to trigger external notifications of emailPush e-mailPush email is used to describe email systems that provide an always-on capability, in which new email is actively transferred as it arrives by the mail delivery agent to the mail user agent , also called the email client...
. - RFC 5436 - E-mail notifications; specifies notifications via e-mail.
- RFC 5437 - XMPP notifications; specifies notifications via XMPPExtensible Messaging and Presence ProtocolExtensible Messaging and Presence Protocol is an open-standard communications protocol for message-oriented middleware based on XML . The protocol was originally named Jabber, and was developed by the Jabber open-source community in 1999 for near-real-time, extensible instant messaging , presence...
. - RFC 5490 - Checking; Mailbox status and accessing mailbox metadata.
- RFC 5703 - MIME Part Tests, Iteration, Extraction, Replacement, and Enclosure
A number of other extensions are still being developed by the Sieve working group.
Example
This is an example sieve script:
- Sieve filter
- Declare the extensions used by this script.
require ["fileinto", "reject"];
- Messages bigger than 100K will be rejected with an error message
if size :over 100K {
reject "I'm sorry, I do not accept mail over 100kb in size.
Please upload larger files to a server and send me a link.
Thanks.";
}
- Mails from a mailing list will be put into the folder "mailinglist"
elsif address :is ["From", "To"] "mailinglist@blafasel.invalid" {
fileinto "INBOX.mailinglist";
}
- Spam Rule: Message does not contain my address in To, CC or Bcc
- header, or subject is something with "money" or "Viagra".
elsif anyof (not address :all :contains ["To", "Cc", "Bcc"] "me@blafasel.invalid",
header :matches "Subject" ["*money*","*Viagra*"]) {
fileinto "INBOX.spam";
}
- Keep the rest.
- This is not necessary because there is a "implicit keep" Rule
else {
keep;
}
External links
- Sieve.Info, a Wiki Site about Sieve
- The old Sieve Home Page on web.archive.org
- RFC 5228 (Base Specification about Sieve)
- Sieve IETF Working Group Charter
- Sieve tutorial with many examples