Sieve (mail filtering language)

{{Short description|Programming language}}

{{About|the programming language for email filtering||Sieve (disambiguation)}}

{{Primary sources |date=May 2024}}

{{Infobox software

| name = Sieve

| collapsible =

| author = University of Washington and Carnegie Mellon University{{cite web | url=http://sieve.info/history | title=History - Sieve.Info }} and standardized by Tim Showalter

| released = {{Start date and age|1999}}

| operating system = Cross-platform

| genre = Email filtering

| website = {{URL|http://sieve.info}}

}}

Sieve is a programming language that can be used for email filtering. 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 generalizes to other systems that meet these criteria. The current version of Sieve's base specification is outlined in RFC 5228, published in January 2008.

Language

Sieve is a data-driven programming language, similar to earlier email filtering languages such as procmail and maildrop, and earlier line-oriented languages such as sed and AWK: it specifies conditions to match and actions to take on matching. This differs from general-purpose programming languages.

While Sieve has many limitations – the base standard has no variables and no loops – it does allow conditional branching, preventing runaway programs. These limitations generally confine the language to simple filtering operations. Although extensions have been devised to extend the language to include variables and, limited 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.

While Sieve was originally conceived as tool external to SMTP,That Sieve operates after message acceptance is in its defining document: {{cite IETF |title=Sieve: An Email Filtering Language |rfc=5228 |author1=P. Guenther |author2=T. Showalter |date=January 2008 |publisher=IETF |quote=it is reasonable to filter when the MTA deposits mail into the user's mailbox}}That final delivery is outside SMTP is in its defining document: {{cite IETF |title=Simple Mail Transfer Protocol |rfc=5321 |sectionname=Trace Information

|section=4.4 |author=John Klensin |date=October 2008 |publisher=IETF| quote=final delivery means the message has left the SMTP environment}} {{IETF RFC|5429|link=no}} precognitively extends it in order to allow rejection at the SMTP protocol level.{{cite IETF |title=Sieve Email Filtering: Reject and Extended Reject Extensions |rfc=5429 |sectionname=Rejecting a Message at the SMTP/LMTP Protocol Level |section=2.1.1 |author=Aaron Stone |date=March 2009 |publisher=IETF}}

Use

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 {{IETF RFC|5804|link=no}}) 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 {{Not a typo|.sieve}} file in the users' home directories.

History

The language was standardized in the (now-obsolete) {{IETF RFC|3028|link=no}} of January 2001, by Tim Showalter.

Extensions

The IETF Sieve working group[http://www.ietf.org/html.charters/sieve-charter.html Sieve working group charter] {{webarchive|url=https://web.archive.org/web/20051231152821/http://www.ietf.org/html.charters/sieve-charter.html |date=2005-12-31 }} has updated the base specification in 2008 ({{IETF RFC|5228|link=no}}), and has brought the following extensions to Proposed Standard status:

  • {{IETF RFC|3894|link=no}} – Copying without side effects; allows a script to be copied across mailboxes without halting the script.
  • {{IETF RFC|5173|link=no}} – Body; allows a script to test the body of a message, not just its header.
  • {{IETF RFC|5183|link=no}} – Environment; provides access to information about the Sieve interpreter and its system environment.
  • {{IETF RFC|5229|link=no}} – Variables; allows the script to save and retrieve values in variables.
  • {{IETF RFC|5230|link=no}} – Vacation; specifies an action to send a response informing the sender that the recipient may be away.
  • {{IETF RFC|5231|link=no}} – 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.
  • {{IETF RFC|5232|link=no}} – IMAP4flags; allows a script to test and set a message's IMAP flags.
  • {{IETF RFC|5233|link=no}} – Subaddress; allows a script to test subaddresses of the form "user+detail@domain.example".
  • {{IETF RFC|5235|link=no}} – Spamtest and Virustest; allows a script to interface with implementation
  • {{IETF RFC|5260|link=no}} – Date and Index Extensions.
  • {{IETF RFC|5293|link=no}} – Editheader; allows a script to add and delete message header fields.
  • {{IETF RFC|5429|link=no}} – Reject; allows messages to be rejected at either the LMTP/SMTP level or with an MDN or DSN.
  • {{IETF RFC|5435|link=no}} – Notifications; allows a script to trigger external notifications of email.
  • {{IETF RFC|5436|link=no}} – Notifications; allows notifications to be sent via the mailto protocol
  • {{IETF RFC|5437|link=no}} – XMPP notifications; specifies notifications via XMPP.
  • {{IETF RFC|5490|link=no}} – Checking; Mailbox status and accessing mailbox metadata.
  • {{IETF RFC|5703|link=no}} – MIME Part Tests, Iteration, Extraction, Replacement, and Enclosure
  • {{IETF RFC|5804|link=no}} – A Protocol for Remotely Managing Sieve Scripts
  • {{IETF RFC|6131|link=no}} – Vacation; adds the ability to specify seconds in a vacation time period.
  • {{IETF RFC|6558|link=no}} – MIME part conversion; allows a script to convert body parts between MIME types.
  • {{IETF RFC|6609|link=no}} – Script inclusion; allow a user to include one script inside another.
  • {{IETF RFC|7352|link=no}} - Detecting Duplicate Deliveries; allows a script to detect duplicate messages and define custom behavior in those cases.

A number of other extensions are still being developed by the Sieve working group.{{cn|date=June 2020}}

Example

This is an example sieve script:

  1. Sieve filter
  1. Declare the extensions used by this script.

require ["fileinto", "reject"];

  1. 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.";

}

  1. Mails from a mailing list will be put into the folder "mailinglist"

elsif address :is ["From", "To"] "mailinglist@blafasel.invalid" {

fileinto "INBOX.mailinglist";

}

  1. Spam Rule: Message does not contain my address in To, CC or BCC
  2. 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";

}

  1. Keep the rest.
  2. This is not necessary because there is an "implicit keep" rule

else {

keep;

}

See also

References

{{reflist}}