All help articles

Filter recipes

Ready-to-copy Sieve filters for common jobs. In webmail, open Filters (the sliders button at the top), then Advanced: write your own Sieve script, paste one in, change the names and addresses, choose Check, and save. A ManageSieve app works too. To use several, put their require lines together at the top and the rest one after another. For how filters run and everything they can do, see Mail filters (Sieve).

Every recipe here is checked by the server's own tests against sample messages, so each one works as written.

Sorting

Each mailing list in its own folder

Mailing lists put their name in the List-Id header, such as Go Nuts <golang-nuts.googlegroups.com>. This files each list under Lists/, creating the folder the first time (Lists/golang-nuts).

# recipe: lists
require ["fileinto", "mailbox", "variables"];
if header :matches "list-id" "*<*.*>*" {
    fileinto :create "Lists/${2}";
    stop;
}

Receipts and invoices

# recipe: receipts
require ["fileinto"];
if anyof (header :contains "subject" ["receipt", "invoice", "order confirmation", "your order"],
          address :localpart :is "from" ["receipts", "billing", "invoice"]) {
    fileinto "Receipts";
    stop;
}

A folder for every plus address

Mail to you+shop@example.com goes to a folder called shop, made the first time. Mail with no tag stays in the inbox. (A domain administrator can turn this on for everyone instead: see Plus addressing.)

# recipe: plus-folders
require ["fileinto", "mailbox", "variables", "envelope", "subaddress"];
if envelope :detail :matches "to" "?*" {
    fileinto :create "${0}";
    stop;
}

Large messages

# recipe: large
require ["fileinto"];
if size :over 10M {
    fileinto "Large";
}

Spam

Zappocity scores mail from other servers and adds X-Spam-Score (such as 7.40) and X-Spam-Status (Yes, score=7.40 when it is spam by your junk score). Any copies of these headers that a sender wrote are removed first, so they can be trusted. See Spam and Junk.

Suspicious mail in a folder of its own

Mail scoring 3 or more, but under your junk score, goes to Maybe spam instead of the inbox:

# recipe: maybe-spam
require ["fileinto", "relational", "comparator-i;ascii-numeric"];
if allof(not header :matches "x-spam-score" "-*",
         header :value "ge" :comparator "i;ascii-numeric" "x-spam-score" "3") {
    fileinto "Maybe spam";
    stop;
}

The not ... "-*" part leaves out negative scores, which the numeric comparator would otherwise read as large numbers.

Throw away the worst

Mail that scored 25 or more is deleted without a trace. Be sure before using this: you will not see what it catches.

# recipe: discard-worst
require ["relational", "comparator-i;ascii-numeric"];
if allof(not header :matches "x-spam-score" "-*",
         header :value "ge" :comparator "i;ascii-numeric" "x-spam-score" "25") {
    discard;
    stop;
}

Mail that failed DMARC

The server records its checks in Authentication-Results, starting with its own name. This files mail that failed its sender's DMARC check in Junk. It reads the server's name from the environment, so a header that a sender wrote under another name does not count.

# recipe: dmarc-fail
require ["fileinto", "environment", "variables"];
if environment :matches "host" "*" {
    set "me" "${1}";
}
if header :matches "authentication-results" "${me};*dmarc=fail*" {
    fileinto "Junk";
    stop;
}

Refuse a sender's domain

The sender gets a bounce with your reason. Your blocked senders list under Settings → Spam does much the same without a script.

# recipe: refuse-domain
require ["reject", "envelope"];
if envelope :domain :is "from" ["spammy.example", "bulk-offers.example"] {
    reject "We do not accept mail from this sender.";
}

Out of office

Reply, but not to lists, bulk mail or robots

# recipe: vacation-exceptions
require ["vacation"];
if anyof (exists "list-id",
          header :is "precedence" ["bulk", "list", "junk"],
          address :localpart :matches "from" ["noreply*", "no-reply*", "mailer-daemon"]) {
    stop;
}
vacation :days 7 :subject "Out of office"
    "I am away until Monday and will answer when I am back.";

Vacation replies already skip mailing lists, bulk mail and automatic replies; use this when you want rules of your own on top. See Vacation replies.

Forwarding

A copy to another address

You keep the message and a copy goes on. Forwarding has to be allowed for your mailbox (Forward my mail in settings shows whether it is).

# recipe: forward-copy
require ["copy"];
redirect :copy "me@elsewhere.example";

Only from one person, flagged

# recipe: forward-boss
require ["copy", "imap4flags"];
if address :is "from" "boss@example.com" {
    addflag "\\Flagged";
    redirect :copy "assistant@example.com";
}

Dates and times

Mail that arrives at the weekend

currentdate is the time the message arrives, in UTC unless your script names a zone. Weekday 0 is Sunday and 6 is Saturday.

# recipe: weekend
require ["date", "relational", "fileinto"];
if anyof (currentdate :zone "+0000" :value "eq" "weekday" "0",
          currentdate :zone "+0000" :value "eq" "weekday" "6") {
    fileinto "Weekend";
    stop;
}

Out of hours, flagged for the morning

From 18:00 to 08:00 (UTC here; change the zone to yours, such as "-0500"):

# recipe: after-hours
require ["date", "relational", "imap4flags"];
if anyof (currentdate :zone "+0000" :value "ge" "hour" "18",
          currentdate :zone "+0000" :value "lt" "hour" "08") {
    addflag "\\Flagged";
}