Wiki source code of Sieve Filterregeln

Last modified by Aysegül Omus on 2024/04/05 12:56

Hide last authors
wikibot 1.1 1 {{toc/}}
2
Aysegül Omus 8.1 3 == 1. Syntax ==
Xhulia Jasimi 2.1 4
Aysegül Omus 8.2 5 === 1.1. Compare ===
wikibot 1.1 6
Aysegül Omus 8.2 7 Sieve contains a total of 6 comparisons, including 3 string comparisons (text) and 3 integer comparisons (numbers).
wikibot 1.1 8
Aysegül Omus 8.2 9 String comparisons:
Xhulia Jasimi 2.1 10
Aysegül Omus 8.2 11 * **:is** means that the content of the compared field must be exactly equal to the specified value.
12 * **:contains** causes the condition to be met if the **keyword** is **included** in the compared field.
13 * **:matches** means that the compared field must match the specified wildcard expression, i.e with '?' (exactly one character) and '*'** **(0 to infinitely many characters). To get a normal '?' and '*' you need to write '~\~\?' and '~\~\*'.
Xhulia Jasimi 2.1 14
Aysegül Omus 8.2 15 Integer comparisons:
Xhulia Jasimi 2.1 16
Aysegül Omus 8.2 17 * **:over** means that the value of the field must be above the specified value.
18 * **:under** means that the value of the field must be less than the specified value.
19 * **:count** counts the number of values ​​in the specified field.
Xhulia Jasimi 2.1 20
Aysegül Omus 8.2 21 In addition, it is still possible to check whether a specific field exists in the header:
wikibot 1.1 22
Aysegül Omus 8.2 23 * **: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.
Xhulia Jasimi 2.1 24
Aysegül Omus 8.2 25 === 1.2. Control structures and blocks ===
wikibot 1.1 26
Aysegül Omus 8.2 27 To make case distinctions Sieve uses the usual if, else, elsif structures:
Xhulia Jasimi 2.1 28
Aysegül Omus 8.2 29 * **:if** means that the actions specified in the following block will be executed if the specified condition is met.
30 * **:else** can be used after an "if" structure and the actions specified in the following block are executed if the condition of the preceding if structure is not met.
31 * **:elsif** combines together an "else" with an "if" structure and can be understood like an "if" structure inside an "else" block.
32 * **: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.
33 * **: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.
34 * **:not...** negates the following condition.
35 * **:[ … ]** serves to list elements, e.g. a string list: ["Max", "Martin", "Manuel"].
36 * **:{ … }**serves to delimit an action block.
wikibot 1.1 37
Aysegül Omus 8.2 38 === 1.3. Fields ===
wikibot 1.1 39
Aysegül Omus 8.2 40 The following fields are available for comparisons:
Xhulia Jasimi 2.1 41
Aysegül Omus 8.2 42 * **:header **This field is probably the most diverse, since it allows access to all header fields . It requires no **"require"** statement.
43 * **: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. Does not require a **"require"** statement.
44 * **:size **This field allows the comparison of the size of the email. Requires no **"require"** statement.
wikibot 1.1 45
Aysegül Omus 8.2 46 === 1.4. Actions ===
wikibot 1.1 47
Aysegül Omus 8.2 48 **stop;** is used to **end** the execution of the script. Does not require a** "require"** statement.
Xhulia Jasimi 2.1 49
Aysegül Omus 8.2 50 * **reject "... "; ** causes the email** to be sent back to the sender**. Between the quotation marks a message can be entered, which the initial sender gets, e.g. the reason for the refusal. Requires ** no "require"** statement, but ** recommended**.
51 * **discard;** causes the email **to be irrevocably deleted** without informing the sender. Requires **no "require"** statement, but ** recommended**.
52 * **keep;** causes the email **to be saved in the default folder**. Overrides any preceding //discard// action. Requires **no "require"** statement.
53 * **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.
54 * **redirect "... ";** causes the email ** to be redirected **. The destination address is in quotation marks. Requires ** no "require"** statement, but ** recommended**.
wikibot 1.1 55
Aysegül Omus 8.1 56 === 1.5. Diverses ===
wikibot 1.1 57
Aysegül Omus 8.2 58 **One-line comments** are started with a **'#'**. **Multi-line comments** are started with **"/* "** and ended with **" */"**.
wikibot 1.1 59
Aysegül Omus 8.2 60 Some functions have to be explicitly included at the beginning of the script. This is possible with a **require **statement.
wikibot 1.1 61
Aysegül Omus 8.2 62 Example:
wikibot 1.1 63
64 {{html wiki="true"}}
Xhulia Jasimi 3.1 65 {{code}}require ["fileinto", "reject"];
wikibot 1.1 66 {{/code}}
67 {{/html}}
68
69
Aysegül Omus 8.2 70 == 2. Examples: ==
wikibot 1.1 71
Aysegül Omus 8.2 72 === 2.1. Simple examples ===
wikibot 1.1 73
Aysegül Omus 8.2 74 The following example sorts all emails from one of the 3 specified addresses into the "friends" folder:
wikibot 1.1 75
Aysegül Omus 8.2 76
wikibot 1.1 77 {{html wiki="true"}}
Aysegül Omus 8.2 78 {{code}}if address :is :all "From" ["bob@example.com", "alice@example2.com", "bff@somewhere.de"] {
79 fileinto "INBOX.friends";
wikibot 1.1 80 }
81 {{/code}}
82 {{/html}}
83
Aysegül Omus 8.2 84 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.
wikibot 1.1 85
Aysegül Omus 8.2 86 It is also possible to search for keywords in the subject line:
wikibot 1.1 87
88 {{html wiki="true"}}
Xhulia Jasimi 6.1 89 {{code}}if header :contains "subject" "Facebook" {
wikibot 1.1 90 discard;
91 }
92 {{/code}}
93 {{/html}}
94
Aysegül Omus 8.2 95 As a result of this rule, all emails whose subject contains the keyword "Facebook" are simply deleted because they are definitely spam.
wikibot 1.1 96
Aysegül Omus 8.2 97 The following example rejects emails larger than **1MB**:
wikibot 1.1 98
99
100 {{html wiki="true"}}
Xhulia Jasimi 6.1 101 {{code}}if size :over 1M {
Aysegül Omus 8.2 102 reject "Please do not send me emails with large attachments, since my email storage is limited";
wikibot 1.1 103 }
104 {{/code}}
105 {{/html}}
106
107
Aysegül Omus 8.2 108 === 2.2. Move spam emails to a separate folder ===
wikibot 1.1 109
110
111 {{html wiki="true"}}
Xhulia Jasimi 4.1 112 {{code}}if header :contains "X-Spam-Level" "*******" {
Xhulia Jasimi 6.1 113 # Wenn der Spam als gelesen markiert werden soll:
114 # addflag "\\Seen";
wikibot 1.1 115
Xhulia Jasimi 4.1 116 fileinto "INBOX.Junk";
wikibot 1.1 117 }
118 {{/code}}
119 {{/html}}
120
121
Aysegül Omus 8.2 122 === 2.3. Ignore certain emails ===
wikibot 1.1 123
Aysegül Omus 8.2 124
wikibot 1.1 125 {{html wiki="true"}}
Xhulia Jasimi 4.1 126 {{code}}if address "From" "virusalert@informatik.tu-muenchen.de" {
wikibot 1.1 127 discard;
128 }
129 {{/code}}
130 {{/html}}
131
132
Aysegül Omus 8.2 133 === 2.4. Forward or move by subject ===
wikibot 1.1 134
Aysegül Omus 8.2 135
wikibot 1.1 136 {{html wiki="true"}}
Xhulia Jasimi 4.1 137 {{code}}if header :contains "subject" "my_project" {
wikibot 1.1 138 # Zum Verschieben in einen Ordner
Xhulia Jasimi 4.1 139 # fileinto "INBOX.project";
wikibot 1.1 140
141 # Zum Weiterleiten mit lokaler Kopie
Xhulia Jasimi 4.1 142 redirect :copy "me@example.com";
wikibot 1.1 143
144 # Zum Weiterleiten ohne lokale Kopie
Xhulia Jasimi 4.1 145 # redirect "me@example.com";
wikibot 1.1 146 }
147 {{/code}}
148 {{/html}}
149
Aysegül Omus 8.2 150 For more information about redirects, please read [[here>>https://xwiki.rbg.tum.de/bin/view/Informatik/Helpdesk/IntumMatumEmailWeiterleitungAbwesenheitsnotiz]].
wikibot 1.1 151
Aysegül Omus 8.2 152 === 2.5. Sort by Address Additions ===
wikibot 1.1 153
154
155 {{html wiki="true"}}
Xhulia Jasimi 4.1 156 {{code}}require ["mailbox"];
wikibot 1.1 157
Xhulia Jasimi 5.1 158 if envelope :matches "to" "*+abc@*" {
Aysegül Omus 8.2 159 # Creates the respective folder auotmatically, if it does not exist yet and moves the email, which contains the squence *+abc@*.
Xhulia Jasimi 5.1 160 fileinto :create "INBOX.abc";
wikibot 1.1 161 }
162 {{/code}}
163 {{/html}}