Sieve

from Wikipedia, the free encyclopedia
QS IT
This article was due to content flaws on the quality assurance side of the computer science editorial added. This is done in order to bring the quality of the articles from the subject area of ​​computer science to an acceptable level. Help to eliminate the shortcomings in this article and take part in the discussion !  ( + )


Reason: mainly how-to

Sieve is a domain-specific language designed for users to configure mail filters on mail servers . The exact specification can be found in RFC 5228 . Sieve has been specified to give users the ability to easily define their own rules for filtering e-mails. However, it is not possible to use more complex program structures that work with loops or variables, for example, or to start external programs.

Sieve's main focus is on expandability, simplicity and independence from the type of access and architecture used and the operating system used.

Sieve scripts are already executed while the e-mail is being delivered to the incoming mail server.

distribution

Sieve scripts are nowadays supported by a large number of mail servers such as Dovecot or Exim as well as e-mail clients such as Thunderbird or Open-Xchange Server directly or via plugins. There are also libraries for parsing Sieve scripts for the programming languages C , Ruby , Java , PHP , Perl and Python .

syntax

Instructions are terminated with a semicolon.

Comments

Comments are introduced by the "#" character. These comments always apply to the end of the line. Multi-line comments are introduced as in C with the string "/ *" and ended with the string "* /".

numbers

Only positive integers are allowed. There is the option of specifying the size using information such as " K " ( KiB , 2 ^ 10), " M " ( MiB , 2 ^ 20) and " G " ( GiB , 2 ^ 30). Example: 100K stands for a size of 100 Kibibytes .

Strings

Strings are introduced by the quotation mark " . A backslash (" \ ") is used to identify further quotation marks or backslashes that still belong to the current character string (so-called" escaping "). String lists are marked with" [" introduced and ended with "]".

Control structures

The main use of filtering email is to test for certain properties. There are also the well-known IF-THEN options in Sieve:

  • if
  • elsif
  • else

A introduces ifa conditional statement. The following code block is only executed if the condition to be tested is met. If not, further conditions can be elsifqueried using. If none of the conditions from the "if" and "elsif" blocks apply, the statements of the "else" block are processed, if one exists.

Comparisons of strings

There are several ways to test a string. The comparison operators used here are:

:contains
checks whether a certain character string is contained in another string.
:is
performs an exact comparison, i. H. the contents of the compared strings must match exactly.
:matches
includes the option of leaving parts of a character string unchecked when comparing. The symbol *can have multiple, with the symbol of ?a sign be released exactly. For example, it will G?nfind all three-letter words with a capital G at the beginning and a small n at the end, while G*nit will address all words from Gin to Gasmann to Health Card Evaluation Commission and beyond.

Address matching

E-mail addresses are checked with the keyword address. Of course it is possible to check the sender or recipient address. In general, only the actual address is compared, i.e. everything that is written between the angle brackets. To compare the complete string, one should check for name "<" address ">". The quotation marks indicate strings. To check addresses for the part before the @ or after the @, the optional arguments :localpartor :domaincan be used. The complete address is checked by default (corresponds to :all).

Size comparisons

The size of a mail is checked with the keyword size. You can compare numbers with the operators :overor :under.

Header fields

E-mail headers can be headerchecked with the keyword . Header fields can be searched in the normal way using the string comparisons described above. It is important to ensure that the colon is not used.

blocks

Block instructions are {introduced with and }ended with . Blocks are used to execute several instructions after a test.

instructions

The following instructions are specified according to the RFC:

stop
Ends the execution. If no rule applies, the message is left in the INBOX (implied keep)
keep
Stores the message in the INBOX
redirect
Forward a message. An e-mail address is given as an argument.
discard
Deletes the message. The sender does not receive any notice of this.
reject
This instruction ensures that the message is rejected. Optionally, you can give a reason for the rejection. A so-called "Message Delivery Notification" is created. If you want to use "reject", you have to request this via the "require reject" at the beginning of the script.
fileinto
The message can be moved to a specific folder. To do this, the folder in the form specific to the server must be specified as an argument. If you want to use "fileinto", you must first request it using the "require".

Extensions

Sieve also allows additional extensions that have to be declared at the beginning of the script with the require keyword .

example

The following example takes some of the examples described above and defines an example script:

# Beispielskript
#
require ["fileinto", "reject"];

# Nachrichten größer 100K werden abgewiesen mit einer Fehlermeldung
#

if size :over 100K {
   reject "Bitte senden Sie mir das nächste Mal eine kleinere Mail. Bei großen Anhängen laden Sie bitte die Dateien auf einen Server und schicken Sie mir eine URL. Danke.";
}

# Eine Mailingliste soll in einen Ordner "mailinglist" verschoben werden
#

elsif address :is ["From", "To"] "mailinglist@example.com" {
   fileinto "INBOX.mailinglist";
# Bei einigen Mailserver-Konfigurationen muss statt eines Punktes hierbei ein Schrägstrich verwendet werden.
}

# Spamregel: Nachricht enthält meine Adresse nicht im To, CC oder Bcc
# header, oder Subject ist irgendwas mit "money" bzw. "Viagra".
#

elsif anyof (not address :all :contains ["To", "Cc", "Bcc"] "me@example.com",
header :matches "Subject" ["*money*","*Viagra*"]) {
      fileinto "INBOX.spam";
}


# Alle anderen Mails behalten wir.
# Diese Regel wäre nicht nötig, da durch das "implicit keep"
# bereits abgedeckt.

else {
     keep;
}

Web links

Individual evidence

  1. Sieve.info - servers. Retrieved February 21, 2017 .
  2. Sieve.info - clients. Retrieved February 21, 2017 .
  3. Sieve.info - libraries. Retrieved February 21, 2017 .