Mailfilter und Regeln¶
Mit Sieve kannst du eingehende Mails filtern. Sieve-Skripte können Mails automatisch löschen oder weiterleiten, automatische Antworten verschicken, Mails beim Eingang in Ordner sortieren, als gelesen markieren oder kennzeichnen und bei oder nach der Zustellung ablehnen.
Ein Sieve-Skript besteht aus Bedingungen, die auf eingehende Mails angewendet werden. Passt eine Mail zu einer Bedingung, werden die zugehörigen Aktionen ausgeführt. Du kannst beliebig viele Skripte speichern, aber immer nur eines aktivieren. Eine gute Sieve-Referenz (English) erklärt die einzelnen Bausteine.
Auf die Skripte zugreifen¶
Viele Mailclients unterstützen ManageSieve zum direkten Bearbeiten von Filtern. Schau deshalb zuerst nach einer Sieve- oder Filtereinstellung in deinem Client.
ManageSieve¶
| Einstellung | Wert |
|---|---|
| Server | dein Hostname (<something>.uberspace.de) |
| Port | 4190 |
| Benutzername | Deine vollständige Mailadresse einschließlich Domain |
| Passwort | Dein Passwort für die Mailadresse |
sieve-connect¶
Wenn dein Mailclient kein ManageSieve unterstützt, kannst du deine Skripte mit sieve-connect auf der Kommandozeile verwalten. Das Tool ist auf U8-Hosts vorinstalliert:
[isabell@moondust ~]$ sieve-connect --server $HOSTNAME --user isabell@example.com --list
Sieve/IMAP Password:
"main" ACTIVE
Beispiele¶
Das Rad musst du nicht neu erfinden. Hier sind ein paar Beispiele:
Mails in Ordner sortieren
Dieses Beispiel sortiert Mails von mailinglist@allcolorsarebeautiful.example in einen Ordner und Mails an *@allcolorsarebeautiful.example in einen anderen. Außerdem senkt es den maximalen Spam-Score auf 4.
require ["fileinto", "reject", "relational", "comparator-i;ascii-numeric"];
# Mail with a spam score greater than 4 is probably SPAM, sort it and stop
if allof (
not header :matches "X-Rspamd-Score" "-*",
header :value "ge" :comparator "i;ascii-numeric" "X-Rspamd-Score" "4")
{
fileinto "Spam";
stop;
}
# Sort mail from mailinglist into folder mailinglist
if address :is "from" ["mailinglist@allcolorsarebeautiful.example", "anothermailinglist@allcolorsarebeautiful.example" ]
{
fileinto "mailinglist";
stop;
}
# Sort mail to *@allcolorsarebeautiful.example into a special folder
if address :is :domain "to" "allcolorsarebeautiful.example"
{
fileinto "important";
stop;
}
# Forward all incoming mail to multiple recipients
redirect "recipient1@example.com";
redirect "recipient2@example.com";
# The command "keep" is executed automatically, if no other action is taken.
Abwesenheitsantwort
require ["variables", "vacation"];
if header :matches "Subject" "*" {
set "subjwas" "${1}";
}
vacation
# Reply at most once a week to a same sender
:days 7
:subject "Out of office ${subjwas}"
"I'm not in the office from 20 May until 31 May.
Best regards
Jane Doe";
# The command "keep" is executed automatically, if no other action is taken.
Eine andere Mailadresse über neue Mails informieren
require ["enotify", "variables"];
# Set notification address
set "notify_address" "mailto:notfyme@example.com";
# Set From address for notification
set "notify_from" "mailnotifier@example.com";
# Store From address and Subject in variables
if address :matches "from" "*" {
set "from_address" "${1}";
}
if header :matches "subject" "*" {
set "subject" "${1}";
}
# Send notification mail
notify :from "${notify_from}" :message "New mail message received from: ${from_address} Subject: ${subject}" "${notify_address}";
Fehlersuche¶
Mit sieve-test prüfst du dein Sieve-Skript auf der Kommandozeile und siehst, welche Aktionen es ausführen würde:
[isabell@moondust ~]$ ENVELOPE_SENDER=sender@example.com # replace sender@example.com with the sender address to test
[isabell@moondust ~]$ ENVELOPE_RECIPIENT=recipient@example.com # replace recipient@example.com with the recipient address to test
[isabell@moondust ~]$ TEST_MAILBOX=isa # replace isa with the name of the mailbox to test
[isabell@moondust ~]$ EMAIL_FILE=/home/isabell/testmail.eml # replace the path with the path to the .eml-file you want to test
[isabell@moondust ~]$ sieve-test -c /dev/null -D -t - -Tlevel=matching -f $ENVELOPE_SENDER -a $ENVELOPE_RECIPIENT -l maildir:$HOME/users/$TEST_MAILBOX script.sieve $EMAIL_FILE
[...]
Performed actions:
* store message in folder: Spam
Implicit keep:
(none)
sieve-test(isabell): Info: final result: success
Auch Fastmails Sieve Tester kann die Syntax prüfen und zeigen, was ein Skript mit einer angegebenen Mail machen würde.