UserPreferences

ApplicationNotes/CyrusImapNotes/SieveFiltering


1. Sieve Filtering

Sieve is Cyrus IMAP's mail filtering mechanism. It requires a script which is installed on the server using sieveshell. Sieve itself is documented in a number of RFCs, but the starting one is [WWW]RFC 3028.

1.1. Filtering Mailing Lists

Mailman lists tend to be easy to filter because Mailman adds a number of headers that identify the list. Here's an example to just filter a Mailman mailing list; I like to filter on the X-BeenThere header because it's shorter and more concise than most of the other headers.
require "fileinto";

if header :contains "X-BeenThere" "some-list" {
  fileinto "INBOX.some-list";
}

1.2. Marking Messages As Read

Sometimes you're on a mailing list and certain people get on your nerves. You don't necessarily want to just discard the person's messages, in case you want to read back through a thread, but you're rather not notice them most of the time, so you can simply mark them as read. Here's an example script which filters messages from a mailing list into its own folder and marks certain senders as read. The IMAP Flags extension is documented in a [WWW]Draft RFC. It is implemented in at least Cyrus IMAP 2.1.14.
require [ "fileinto", "imapflags" ];

if header :contains "X-BeenThere" "some-list" {
  if header :contains "From" 
  [
    "somejerk@example.com",
    "anotherjerk@example.net"
  ]
  {
    addflag "\\Seen";  
  }
  fileinto "INBOX.some-list";
}