wiki.in.tum.de
Technische Universität München


1 Syntax

1.1 Compaire

Sieve knows a total of 6 comparisons, including 3 string comparisons (text) and 3 integer comparisons (numbers).

String comparisons:
  • :is means that the content of the compared field must be exactly equal to the specified value.
  • :contains contains causes the condition to be met if the keyword is included in the compared field.
  • :matches means that the compared field must match the specified wildcard expression, ie with '?' (exactly one character) and '*' (0 to infinitely many characters). To normal '?' and '*' do you need "\\?" and write.
Integer comparisons:
  • :over means that the value of the field must be above the specified value.
  • :under means that the value of the field must be less than the specified value.
  • :count counts the number of values ​​in the specified field.
In addition, it is still possible to check whether a specific field exists in the header: : exists checks whether a field is set in the header and is particularly useful in combination with the "not" operator e.g. to test if a subject is set.

1.2 Control structures and blocks

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.

1.3 Fields

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.

1.4 Actions

* Stop; is used to * finish* the execution of the script. Requires * no "require"* statement.

* Reject "... "; * causes the e-mail * to be sent back to the sender. Between the quotation marks a message can be entered, which gets this, e.g. the reason for the refusal. Requires * no "require"* statement, but * recommended*.

* Discard; causes the email to be irrevocably deleted without informing the sender. Requires no "require" statement, but * recommended*.

* Keep; causes the e-mail to be saved in the default folder. Overrides any preceding discard action. Requires no "require" statement.

* Fileinto "... "; causes the email to be saved in the specified folder. The folder name is entered between the quotation marks. If the folder does not exist, the message is stored in the default folder and no further action is taken. Requires a "require" statement.

* Redirect "... "; causes the email * to be redirected . The destination address is in quotation marks. Requires * no "require" statement, but * recommended*.

1.5 Diverses

One-line comments are initiated with a '#'. Multi-line comments are started with "/ " and ended with " / ".

Some functions have to be explicitly included at the beginning of the script. This is possible with a * require * statement.

Example:
require ["fileinto", "reject"];

2 Examples:

2.1 Simple examples

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

2.2 Move spam emails to a separate folder

if header :contains "X-Spam-Level" "*******" {
     # If the spam is to be marked as read:
     # addflag "\\Seen";

     fileinto "INBOX.Junk";
}

2.3 Ignore certain emails

if address "From" "virusalert@informatik.tu-muenchen.de" {
     discard;
}

2.4 Forward or move by subject

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.

2.5 Sort by Address Additions

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";
}
Topic revision: r10 - 11 Dec 2019, AyseguelOmusNe63guq
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback