Re: [exim] presorting(filtering) email before using imap

Top Page
Delete this message
Reply to this message
Author: Phil Pennock
Date:  
To: Mark Elkins
CC: exim-users
Subject: Re: [exim] presorting(filtering) email before using imap
On 2012-04-11 at 14:20 +0200, Mark Elkins wrote:
> What do people use - that actually works for themselves.
> (Looking for working suggestions/examples!)


Sieve's the way to go. The up-side is it's a common language for mail
filtering; the down-side is, when I last looked at open web front-ends
for it, they all encoded their state and rules in magic comments, rather
than actually "understanding" Sieve, so you end up having to pick just
one front-end for management.

If you're happy working with text files, Sieve is easy anyway and you
can ignore that. Examples below.

Sieve is accompanied by ManageSieve, a protocol for uploading/activating
Sieve scripts; the server is required to syntax check at upload time.

With Exim, you can have Exim interpret the Sieve config; there's a
non-standard requirement for a header-line in the file, but if you use
pysieved as the server, it can take care of that for you.

There's also Sieve for dovecot, and Sieve for Cyrus IMAP which is what
I'm currently using. Dovecot's come a long way though and I'm seriously
considering switching. Here's where Sieve wins: I'll get to keep the
same filter rules for the new system.

There's one known ManageSieve command-line client which handles TLS
securely; er, I wrote it. It's since been adapted as the basis of a
Perl CPAN module. "sieve-connect".

Some snippets extracted from my sieve filter, which can redirect
messages to other addresses, which end up in other folders, handled
differently to "fileinto" because I have accumulated a crufty layout
over the years ... at least it lets me choose some okay samples. This
handles one of my old domains, "globnix.org", where I subscribed my own
email address directly to a number of mailing-lists. With spodhuis.org,
some Exim config means that if the IMAP folder exists, then the email
address exists, so I just subscribe with addresses such as
"exim-users@???" and avoid needing to write Sieve rules for
each list I subscribe to.

----------------------------8< cut here >8------------------------------
require ["fileinto", "envelope"];

if not header :matches "Envelope-to" "*@globnix.???" {
keep;
stop;
}

if exists "List-Id" {

  if header :contains "List-Id" [
    "<dhcp-announce.lists.isc.org>",
    "<w3c-announce.w3.org>",
    "<pgsql-announce.postgresql.org>",
    "<conferences.yapceurope.org>"
  ] {
    redirect "misc-announce@???"; stop;
  }


  if header :contains "List-Id" "<putty-announce.lists.tartarus.org>" {
    redirect "sw-announce@???"; stop;
  }


  if header :contains "List-Id" "<risks.csl.sri.com>" {
    fileinto "globnix/risks-digest"; stop;
  }


}

if exists "Mailing-List" {

  if header :matches :comparator "i;octet"
    "Mailing-List" "contact zsh-users-help@???;*" {
      fileinto "globnix/zsh-users"; stop;
  }


}

if header :is "Content-Type" "text/html" {
fileinto "Spam/html-only"; stop;
}

# Default:
fileinto "globnix/rest";
stop;

# vim: set filetype=sieve sw=2 expandtab :
----------------------------8< cut here >8------------------------------