Sieve filters

My email is all hosted at Tuffmail, which a friend recommended a few years ago, and which I now recommend to other friends in turn. Yes, you have to pay, but the spam filtering is wonderful, you can buy loads of storage, and it’s never down. One of the best things is being able to filter mail directly on the server — I never use my mail client’s rules, as all my email is in the correct folders already.

But setting up the filters on Tuffmail is a bit arcane. There’s no pretty interface, and you have to write the rules using the [Sieve filtering language](http://en.wikipedia.org/wiki/Sieve_(mail_filtering_language)). It’s very powerful but there doesn’t seem to be any easy-to-read and comprehensive documentation. There are some examples but they’re scattered all over the place.

This won’t fix that problem, but here’s another scattered example, an anonymised version of my own Sieve filters, with duplicate clauses removed. Hopefully it’s useful to someone.

# You have to 'require' certain features before you can use them 
# in rules.
require ["fileinto", "regex", "imapflags"];


# Redirect emails related to a specific TypePad weblog to the person 
# responsible for running it.
if allof (
     header :contains ["From"] "noreply@sixapart.com",
     header :contains ["Subject"] "[Blog Name]"
) {
     redirect "anne@example.com";
     stop;
}


# File emails from a specific email address into a specific mailbox 
# within a subfolder. 
if header :contains ["To"] "philgyford@example.com" {
    fileinto "FolderName/MailboxName";
    stop;
}


# File emails from any social networking sites into a folder called 
# "@Social". Note the use of a regular expression to match Facebook's 
# emails to addresses of a form like:
# notification+odfojhrw@facebookmail.com
if anyof (
     header :contains ["X-Twitterrecipientscreenname"] "philgyford",
     header :contains ["From"] "invitations@linkedin.com",
     header :contains ["Reply-To"] "noreply@facebookmail.com",
     header :regex ["From"] "notification\+.+@facebookmail.com",
     header :contains ["Sender"] "messages-noreply@bounce.linkedin.com"
)
 {
    fileinto "@Social";
    stop;
}


# File emails from a mailing list into a specific folder/mailbox.
if header :contains ["List-ID"] "mailing-list-name.yahoogroups.com" {
    fileinto "FolderName/Mailbox Name";
    stop;
}


# File emails sent to, OR CC'd to, a mailing list into a mailbox 
# two levels deep.
if header :contains ["To", "CC"] "mailinglist@example.com" {
    fileinto "FolderName/Subfolder Name/MailboxName";
    stop;
}


# File emails from two different mailing lists into the same 
# specific mailbox.
if header :contains ["List-ID"] ["mailing-list.lists.example.com", "backup-mailing-list.googlegroups.com"] {
    fileinto "Mailbox Name";
    stop;
}


# File messages from a mailing list I never get round to reading, 
# and mark them as read so I don't feel guilty.
if header :contains ["From"] "mailinglist@example.com" {
    setflag "\\Seen";
    fileinto "FolderName/MailboxName";
    stop;
}


# For emails I keep receiving but never want to read or see,
# mark as read and file them in the Trash.
if anyof (
    header :contains ["From"] "\"Billy Nomates\" <billy@example.com>",
    header :contains ["From"] "another@example.com" # You can add comments here too.
) {
    setflag "\\Seen";
    fileinto "Trash";
    stop;
}

Comments

  • I am also a Tuffmail customer (*love* the service) and am continually on the lookout for good, simple Sieve examples. This one fits the bill perfectly. Thanks!

Commenting is disabled on posts once they’re 30 days old.

2 Jul 2010 at Twitter

  • 4:57pm: Belatedly heading St James Park-wards for @mala's picnic time.
  • 1:56pm: I find my Steelcase Leap chair more comfortable than my Aeron, but right now the Aeron's airy sweat-reducing mesh would be a positive boon.
  • 1:54pm: @dorianmoore I know - some people all of a sudden seem to think anything slightly whizzy, that's not Flash, is "HTML5".
  • 8:48am: Back at BRIGington Towers, time to catch up on a week's worth of ignored to-dos.

Music listened to most that week

  1. Ikonika (15)
  2. Digital Mystikz (3)
  3. Kode9 (3)
  4. Wagon Christ (3)
  5. Pixies (2)
  6. Thompson Twins (2)
  7. The Jam (2)
  8. Zomby (2)
  9. Terror Danjah (2)
  10. Aztec Camera (2)

More at Last.fm...