Sieve (mail filtering language)

From Wikipedia, the free encyclopedia

Jump to: navigation, search

Sieve is a language that can be used to create filters for electronic mail. 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. 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.

Contents

[edit] Extensions

The IETF Sieve working group[1] has recently updated the base specification (RFC 5228), and has brought the following extensions to Proposed Standard status:

  • 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 addresses 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 5173 - Body; allows a script to test the body of a message, not just its header.
  • RFC 5429 - Reject; allows messages to be rejected at either the LMTP/SMTP level or with an MDN or DSN.
  • RFC 5490 - Checking; Mailbox status and accessing mailbox metadata

The working group has also completed work on these extensions, which are pending RFC publication:

A number of other extensions, including the ability to iterate through a message's MIME structure, are still being developed by the Sieve working group.

[edit] Example

This is an example sieve script:

# example script
# de.wikipedia.org
#
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;
}

[edit] References

[edit] External links

Personal tools