Advanced filtering using Sieve

There are many advanced options available for filtering email at CSC, including auto-replies (a.k.a. vacation messages) and sub-addressing.

To understand how filtering works, you should also know some basic technical details of how email works, e.g. how communication works between email clients and servers, what email headers are, what formatting is used, the character encodings involved and so on. Below are some links to information that may be of use.

Note that this applies only to those who use CSC's email servers. Most KTH students store their mail on the central KTH.SE email servers. See the general information on email. (“Email” on the left.) For information on how to install and activate Sieve filters, se “Spam filtering”.

Wikipedia on Email addresses, defining some of the terms used

Sieve base specifications

More Sieve documentation

Wikipedia on Sieve, with some examples

Forwarding

You can set up two types of forwarding from your CSC account. The first is an unconditional forwarding. This will send any mail that arrives directly to another address. This is normally set up for newly created student accounts, to forward their email to the central KTH.SE email address. This is done by logging on to a Solaris host, and running chpobox:

alice@s-shell> chpobox
Changing mail forwarding address for "alice"
Mail forward address: some-address@example.com

chpobox will prompt with the currently set forwarding, if any. To remove this, just remove the text at the prompt. Any change will take a few minutes to take effect.

A more selective forwarding uses the Sieve mail filtering language. You can run tests on addresses, other headers, save messages into folders or forward to other addresses.

Example

if allof (address :is ["To", "Cc"] "alice@example.com"
          header :matches "Subject" ["CERT", "security"]) {
    # Forward a copy to Bob, and save a copy.
    redirect "bob@example.com";
    fileinto "INBOX.Security maillists";
}

Default is to “keep”, i.e. store in your Inbox, but only if message has not been filed or redirected.

Also, note that all folders must be referred to by IMAP-encoded names (a modified UTF-7 encoding). A folder named “Räksmörgås” would be “R&AOQ-;ksm&APY-;rg&AOU-;s”.

Auto-reply during vacation

The vacation functionality sends an automated reply to the sender. The system automatically keeps track of who has been sent a reply, and will not send a new reply for a certain number of days, controlled by the “:days” argument.

You should make sure that any spam handling or redirection is done before the vacation message is sent, see the example below.

While not strictly necessary, you probably want to use the “:mime” argument, so that you can specify the charset used. Otherwise international characters such as ÅÄÖ may display incorrectly. You may also need to make sure that the subject header is encoded correctly, all international characters require that you encode the header as a Mime header. Thus

:subject "Räksmörgås"

would have to be written as either

:subject "=?ISO-8859-1?Q?R=E4ksm=F6rg=E5s?="

or

:subject "=?UTF-8?Q?R=C3=A4ksm=C3=B6rg=C3=A5s?="

depending on your preferred encoding.

Example

require ["fileinto","vacation"];
if header :contains "X-Spam-Level" "**********" {
    fileinto "INBOX.A";
}
elsif header :contains "X-Spam-Level" "*****" {
    fileinto "INBOX.B";
}

vacation :days 5
    :addresses ["alice@kth.se" , "alice@nada.kth.se", "alice@csc.kth.se"]
    :subject "On vacation / =?ISO-8859-1?Q?P=E5_semester?="
    :mime
text:
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: 8BIT

Hello. I'm on vacation until the 29th of February.

For urgent matters, contact the work group on [address].

Regards
Alice
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Hej. Jag har semester och återkommer den 29/2.

Om det är mycket brådskande, kontakta arbetsgruppen på [adress].

Hälsningar
Alice
.
;

Sub-addressing (a.k.a. plus-addressing)

CSC's mail server is configured so that the local part of an email address (before the at sign) can contain an address tag, separated from the username by a plus character. In other words,

username+tag@csc.kth.se

will be delivered to the same address as

username@csc.kth.se

This can be used to create single-use addresses (for web forms, etc), and you can create filters that look for the tag:

if address :localpart :contains ["To", "Cc", "Bcc"] "+foo" {
    fileinto "INBOX.Foo";
}

Note that, unlike some mail servers, CSC's does not allow you to use the hyphen (“-”) to separate tags. “username-tag@csc.kth.se” will not work.