Configuring Exim4 dot forward Filtering

Posted by Tom Willett Mon, 02 Oct 2006 20:44:00 GMT

For a detail discussion of Exim's filter system, you should check out Exim's documentation itself (http://www.exim.org/exim-html-4.40/doc/html/filter_toc.html ). For just the short of it, read on.

In order for Exim to recognize a .forward as having Exim4 filter rules, the first non-whitespace entry must be:

# Exim filter

Character case and anything following it on the same line are ignored.

Next, you'll likely want some rules in your Exim4 filter .forward file. Using a simple if then elif else endif construct you can perform various tests against each incoming email before delivery (or discarding) it to a specified location. You can perform evaluations against any existing entry in an email's header, like so:

# Match any email who's To: header contains "exim"
# and save it to .dir1
if $h_to: contains "exim" then save Maildir/.dir1/

# Match email with a From: header that's
# exactly "not@wanted.com" and save it to .SPAM
elif $h_from: is "not@wanted.com" then save Maildir/.SPAM/

endif

To access the email header of your choice, append $header_, or as abbreviated above, just $h_, to the full name of an email header, following by a colon (:). The keywords is and contains are self explanatory. The save keyword, when followed by a path that ends with a forward slash (/), will deliver the email being evaluated in Maildir format. As such, the trailing slash is crucial. Don't omit it.

In Courier's IMAP hierarchy, directories beneath the root are dot directories. In addition, all subdirectories are denoted by periods, not additional forward slashes. So, lists/Debian/User/ is actually .Lists.Debian.User/ on the filesystem and should be referred to in Exim filters as "save Maildir/.Lists.Debian.User/" for things to be saved the way you expect.

Each user can set up their own filters by creating a .forward file in their home directory. If the first line of this file reads # Exim filter then Exim4 will treat it as a filter.

Here is an example of an Exim filter that checks the headers that SpamAssassin adds and puts the mail in the appropriate Maildir folder:

# Exim filter
if $h_X-Spam-Status: CONTAINS "Yes"
     or
  $h_X-Spam-Flag: CONTAINS "Yes"
then
  save $home/Maildir/.Spam/
  finish
endif

Comments

Leave a comment

Comments