Sieve knows a total of 6 comparisons, including 3 string comparisons (text) and 3 integer comparisons (numbers).
String comparisons:To make case distinctions Sieve understands the usual if, else, elsif structures:
* :if means that the actions specified in the following block will be executed if the specified condition is met. * :else can be preceded by an "if" structure and the actions specified in the following block are executed if the condition of the preceding if structure is not met. * :elsif combines an "else" - with an "if" structure and is like an "if" structure in an "else" block to understand. * :allof ( … ) represents a combination of several conditions and is satisfied when all "subconditions" are met (AND operation). These are given as a comma-separated list in brackets. * :anyof(...) represents a combination of several conditions and is fulfilled if at least one "sub-condition" is fulfilled (OR operation). These are given as a comma-separated list in brackets. * :not... negates the following condition. * :[ … ] serves to list elements, e.g. a string list: ["Max", "Martin", "Manuel"].* *:{ … }*serves to delimit an action block.
The following fields are available for comparisons:
* : header This field is probably the most diverse, since it allows access to all header fields . Requires no "require" statement. * : address This field gives direct access to all address fields of the header. It supports at least the From, To, Cc, Bcc, Sender, Resent-From, Resent-To fields and implementation-dependent ones. Requires no "require" statement. * : size This field allows comparing the size of the e-mail. Requires no "require" statement.Some functions have to be explicitly included at the beginning of the script. This is possible with a * require * statement.
Example:require ["fileinto", "reject"];
The following example sorts all e-mails from one of the 3 specified addresses into the "friends" folder:
if address :is :all "From" ["bob@example.com", "alice@example2.com", "bff@somewhere.de"] { fileinto "INBOX.freunde"; }
This example shows the use of an "if" structure, the "address" field, an exact comparison using ": is" and a list in "[...]", as well as the "fileinto" action.
It is also possible to search for keywords in the subject line:
if header :contains "subject" "Facebook" { discard; }
As a result of this rule, all emails whose subject contains the keyword "Facebook" are simply deleted because they are definitely spam.
The following example rejects emails larger than 1MB:if size :over 1M { reject "Please refrain from sending me emails with large attachments because my mailbox is limited."; }
if header :contains "X-Spam-Level" "*******" { # If the spam is to be marked as read: # addflag "\\Seen"; fileinto "INBOX.Junk"; }
if address "From" "virusalert@informatik.tu-muenchen.de" { discard; }
if header :contains "subject" "my_project" { # To move to a folder # fileinto "INBOX.project"; # To forward with a local copy redirect :copy "me@example.com"; # To forward without a local copy # redirect "me@example.com"; }For more information about redirects, please read here.
require ["mailbox"]; if envelope :matches "to" "*+abc@*" { # the corresponding folder is created automatically , if he does not exist yet and shifts, the e-mail that comes to *+abc@* there. fileinto :create "INBOX.abc"; }