Sieve lets you put more or less complex filter rules on the server side of your email mailboxes. Once the rule has been put in place, it will be applied to incoming mail, regardless of the mail client you’re using (Outlook, Thunderbird, Apple Mail, webmail, etc.).

Previously, Sieve rules were only available through SOGo, our webmail platform, but now they’re available from any email software.

With Thunderbird, for example, you can use the Sieve extension from Thomas Schmid that you can add via add-ons, but this type of add-on exists for just about any mail client you might have.

You can find documentation with examples on the wiki page for Dovecot, the IMAP server that Gandi Mail uses:

https://wiki2.dovecot.org/Pigeonhole/Sieve/Examples

Or on Wikipedia:

https://en.wikipedia.org/wiki/Sieve_%28mail_filtering_language%29#Example

Let’s take a look at how you could use Sieve filters from day to day.

Imagine you receive around 3,000 emails a day in your email inbox at work and about 200 in your personal email, both of which you access through your desktop as well as your phone. Here’s how Sieve filters could help you sort through this quantity of email efficiently on the server side of things:

  1. Distinguish between email addressed to you, and email from distribution lists

    Especially in a professional context, you might find you get two kinds of email: email addressed directly to you or that you’re copied on and email you receive by virtue of being on a distribution list. You can sort these so that only email directly addressed to you or that you’re copied on shows up in your Inbox, while email from distribution lists goes to a separate folder.

    First, remember that the line ‘require’ must be the first line in a Sieve file. If you want to use all of the following examples be sure to put them altogether in a single file that starts with ‘require’:

    require ["fileinto"];

    Then, if you’re the To: or CC: on an email:

    if header :contains ["to","cc"] "you@domain.tld" {
    fileinto "INBOX";
    stop;
    #Then say you want email from a @gandi.net email address in a separate folder
    } elsif header :matches "From" "*@gandi.net>" {
    fileinto "INBOX/Gandi";
    #Otherwise you can have everything go into a folder to sort through later
    } else {
    fileinto "INBOX/to-sort";
    }

  2. Use addresses yourname+whatever@ when you sign up at a new site, like yourname+amazone@domain.tld, etc.

    require ["variables", "envelope", "fileinto", "subaddress"];
    #Add the code from above

    if envelope :is :user "to" "yourname" {
    if envelope :matches :detail "to" "*" {
    #That way, everything that follows the + goes into a variable called 'name'
    set :lower :upperfirst "name" "${1}";
    }
    #If 'name' is empty, the email stays in the Inbox
    if string :is "${name}" "" {
    fileinto "Inbox";
    #Otherwise, it goes into the folder corresponding to the part after the +
    } else {
    fileinto "plus/${name}";
    }

  3. Delete spam

    Soon we’ll be introducing a new anti-spam update but already with Sieve, if an email has been flagged as SPAM, you can filter it to your Spam folder:

    if header :contains "X-Spam-Flag" "YES" {
    fileinto "Spam";
    }

    Then, if the Spam level is detected as high, defined by number of asterisks, you can reject the email directly, according to how sensitive you’d like your spam filter be

    if header :contains "X-Spam-Level" "*******" {
    discard;
    stop;
    }

  4. Manage your auto-reply

    When you leave on vacation (soon, we hope), you can add your away message directly in your Sieve file.
    “days 1” indicates that the away message only gets sent once per day per address

    require ["fileinto","imap4flags","regex","vacation"];
    # rule:[Auto-reply]
    vacation
    :days 1
    :subject "Out of the office until ..."
    text:
    Hello,
    I'm on vacation until ... and won't be checking my email regularly during this time.
    If this is an emergency, please contact ... at example@domain.tld.
    Sincerely,
    Your Name
    .
    ;

  5. Don’t miss messages from important people

    You can also flag messages from important people using Sieve, and set notifications on the mail client on your phone to notify you when you get a message that’s been flagged:

    require ["imap4flags"];
    if envelope "from" "important@person.tld" {
    setflag "\\Flagged";
    stop;
    }

These are just a few examples of rules that you can use with Sieve, but we encourage you to play around with Sieve. Have some fun with it and post any good rules you come up with in the comments!