Sieve¶
Sieve is a scripting language used to automate many tasks related to e-mail accounts (for example, auto-replying, copying messages to another address, or rejecting certain messages). The Sieve script runs server side
.
Sieve script management is possible with:
- e-mail program (e.g. in
Thunderbird
additional add-on is required) - Perl
sieve-connect
script - installed on Serv00.com servers - webmail Roundcube (
Settings
→Filters
) - no syntax knowledge is required.
The structure of the Sieve script is not complicated and you do not need to know any programming language to write the simplest rule. The script consists of a list of simple commands, such as: fileinto
(move to folder), if
(if any condition is met), discard
etc.
Syntax¶
require ["fileinto", "reject", "vacation", "regex", "relational", "comparator-i;ascii-numeric"];
if size :over 1024K {
reject "Message undelivered. Too large.";
stop;
}
require["..."];
- this line informs what modules we will use (fileinto
to put messages in a folder, reject
to reject messages, vacation
to send an automatic message, regex
to use regular expressions and relational
with comparator-i;ascii-numeric
for numeric comparisons).
if size :over 1024K {
- This line checks if the message size is greater than 1024 KB
.
reject "(...)";
- in this line the message is rejected.
stop;
- in this line Steve stops parsing the rest of the script.
}
- closing parenthesis of what happens when the condition in if
is met.
Test¶
size
- checks whether the size of the message is greater than :over
or smaller :under
than the given value in M
(megabytes), K
(kilobytes) or in bytes by default (for example 10M
, 20K
, 1024
).
header
- checking header fields.
address
- check only the address from the header. For example, the message was sent as John Smith <jsmith@domain>
. The sentence header "From" :is "jsmith@domain"
is false, while address :is "jsmith@domain"
is true.
allof (list of tests)
- returns true
only if each of the tests in the list is true.
anyof (list of tests)
- returns true
when any of the tests in the list is true.
true
- always returns true
.
false
- always returns `false'.
not <test>
- returns false
when the test returned true
and vice-versa.
Comparisons¶
:is
- the value of the tested field must be identical to the given parameter.
:matches
- the value of the tested field must match the given pattern. In the pattern, apart from characters, you can use *
- zero or more any characters and ?
- adding one any character.
:contains
- the value of the tested field must contain the specified parameter.
:over
- works only for numbers. If the given value is greater than the checked value, it returns true
.
:under
- only works for numbers. If the given value is less than the checked value, it returns true
.
:count
- allows you to count how many items there are in a given field.
Construction¶
[...]
- square brackets are used to indicate groups. For example, ["John","Adam","Michael"]
indicates a group of three people.
{...}
- braces are used to indicate a block of instructions that must be executed if the test result is true.
if
- is used to check whether the given expression is true
. If it is, the statement block specified after the if is executed.
else
- if the expression in if
is false
, the block of statements given after else
is executed.
elseif
- combination of else
and if
. If the expression in the if is false, another if is executed.
stop
- ends the script.
Actions¶
keep
- keeps the message in the current folder.
fileinto "FOLDERNAME"
- moves the message to the specified folder. If it does not exist, the message will go to the inbox.
discard
- deletes the message without notifying the sender.
reject "REASON"
- returns an error message to the sender with an optional reason.
redirect "EMAIL_ADDRESS"
- forwards the message without keeping a copy of it, unless keep
or fileinto
is executed.
Comment¶
# A one-line comment from '#' to the end of the line. The content is ignored by the Sieve parser.
/* Block comment
* All lines are ignored from the moment the comment starts with '/*',
* until the end of the comment with a string */
Examples¶
- Messages sent to
john.smith@domain
andj.smith@domain
will receive an automatic reply (example of configuration from Webmail Roundcube - Autoresponder):
require ["vacation"];
vacation
# Send maximum once a day to the same recipient
:days 1
:subject "Out of Office - Automatic Reply"
:addresses ["john.smith@domain", "j.smith@domain"]
"Good morning,
I am out of office, please contact Adam Smith - adam.smith@domain.
Regards,
John Smith";
- News from
newsletter@domain
will be kept inINBOX.Newsletters
folder:
if address :is "From" "newsletter@domain" {
fileinto "INBOX.Newsletters";
stop;
}
- Messages from domain
domain
will be stored inINBOX.Example
folder:
if address :is "From" "newsletter@mypals.org" {
fileinto "INBOX.Example";
stop;
}
- Deletes messages with the following types of attachments:
if header :contains "x-attached"
[".exe",".bat",".js",".com",".cmd",".ini",".dll",".bas",".cpl",".drv",".inf",".sys",".pif"] {
discard;
stop;
}
- Rejects messages larger than
5MB
, notifying the sender.
if size :over 5M {
reject "Message size up to 5MB.";
}
- Messages from
Adam Adamsky
that have not been sent to anyone else will be kept in theINBOX.Adam
folder:
if allof(
header :contains ["From"] "Adam Adamsky",
header :is ["Bcc:","Cc:"] ""
){
fileinto "INBOX.Adam";
}
Warning
If a symbolic link to the script isn't created you must create it manually. Go to the mailbox directory with the command: cd ~/mail/ADDRESS@EMAIL
(where ADDRESS@EMAIL
is the address of the mailbox you created) and execute the command: ln -s sieve/managesieve.sieve .dovecot.sieve
(managesieve.sieve
- default script name).
Spam¶
Configuration options regarding the behavior towards messages detected as spam are available via Devil and DevilWEB. By Sieve (including the visual editor available in webmail) you can add e.g. additional actions for messages detected as spam which received a given point value.
Headers are added to the e-mail:
X-Spam-Status
- informing about the probability of spam (0
- normal message,5
- probable spam,>10
- automatic rejection of the message by the server) along with an indication of the score and the reason for awarding points.X-Spam-Level
- marking of the score in the form of rounded stars (for example, 1 rounded point awarded is visible as one star, two rounded points as two stars).X-Spam-Flag
- informing that the message has been identified as spam.