If you start your .forward file with # Exim filter, then the Exim MTA can do some processing of your incoming Email. Documentation about this is available at:

Testing a filter

You can create a filter with any filename (such as $HOME/exim.filter) and then test it with

/usr/sbin/exim -bf $HOME/exim.filter -f fromaddress -bfl username -bfs +suffix

You might need to use "/usr/sbin/exim4" instead of "/usr/sbin/exim", depending on which version you have installed, and the naming scheme used by your distribution.

This will read an Email from stdin(3) and tell you which tests matched, and what would have happened if that message was actually being delivered. You can change fromaddress, username, and suffix to test specific rules, and you can omit -bfl if username is your own username. If your filter is simple enough that it doesn't use any message headers you can supply an empty message.


A simple example

# Exim filter - do not edit this line!
# only works for exim... others will treat it as a plain .forward file...

# if this message is an error (bounce/"delivery failed"), then deliver to original
# address as per usual
if error_message then finish endif

# I have mail forwarded to me from an account at another machine.
# it currently only gets spam, so automatically save to somewhere else.
# This match is a regular expression, hence need to double escape the "."
if $header_received: contains remotehost\\.co\\.nz
 and $header_from: does not contain remotehost\\.co\\.nz
 save $home/Mail/remotehostspam 0600 # 0600 is the file mode (as in chmod)
 seen finish

# default action - get exim to deliver as if this forward file wasn't here
# change this to whatever address this server is accepting your mail for

For the WLUG MailServer

Since Exim on the WlugServer supports a suffix (eg any mail to gets delivered to username, regardless the suffix), you can filter incoming messages based on this.

Probably the only thing to be aware of is that if you use the save command, it saves to the named MailBox using MBox format rather than MailDir. Add a "/" at the end of the folder name to tell Exim to use MailDir.

# Exim filter - do not edit this line!

# don't do any filtering for bounces/failure notifications
if error_message then finish endif

# the 'testprint' command will print out its argument if you are running
# exim in test mode, and will do nothing if run 'live'
testprint "suffix is $local_part_suffix, subject is $h_subject"

# discard any mail that has "+nospam" as a suffix...
if ${local_part_suffix} is "+nospam" then
  seen # tell exim that we've delivered it (even though we haven't really)
  finish # don't try any more tests or deliveries

# discard mail that spam assassin assigned 5 or more points
# (SA on hoiho puts '+' chars in the X-Spam-Score header)
if $h_x-spam-score: contains +++++ then
   seen finish

# any mail with the "+foo" suffix will have a copy sent elsewhere,
# AS WELL AS delivered as if this rule wasn't here
if ${local_part_suffix} is "+foo" then
  unseen # pretend that we haven't delivered it, when we really have

# any mail with a suffix matching this regular expression will be saved into
# the "bugs" directory as maildir (ie one file per message).
# Note that:
# 1) \ and $ in a regular expression need to be \ escaped,
# 2) you need to use " and double-escaping if your pattern has whitespace, and
# 3) exim uses perl-compatible regular expressions
# (This matches if the suffix contains "bugs" or contains 3 or more digits in a row
if ${local_part_suffix} matches bugs|\\d{3,} then
  # 0600 is the octal file permissions
  save $home/Maildir/bugs/ 0600
  finish # finish processing this filter file
# Note! if you want mail applications to correctly recognise a folder as maildir
# format, make sure that it exists and has 3 subdirectories named
# "new", "tmp", and "cur". Otherwise you risk losing mail...

# if a message has a particular sender address (either From or Sender), save it
# into a particular file (as mbox). Note that this variable will be empty for
# automatically generated messages such as bounces
if $sender_address matches "@domainz\\\\.co\\\\.nz\\$" then
  save $home/Maildir/domainnames/ 0600

# ignore any mail that was sent from this network
if $h_received: contains then
  # "seen finish" tells exim that we have processed this message
  seen finish

# default action, if this filter hasn't yet caused a 'significant delivery'
# for the incoming message

if not delivered then
  deliver ${local_part}

Yet Another Exim Filter recipe:

Rather than specific known suffices, deliver into a Maildir folder that's named the same as the suffix. No suffix? Go into INBOX:

# Exim filter

if $local_part_suffix is ""
  save $home/Maildir/
  # Remove the first '-', and any periods in the suffix.
  save $home/Maildir/.${sg{${sg{$local_part_suffix}{[\.]}{}}}{^-}{}}/

Escaping reserved characters in filters and system_filter

The manual writes something along the lines of that you need to double-escape certain characters for regular expressions since they get un-escaped once by Exim, and then once again by the regex. So for strings inside quotes, you need to escape 4 times, ie escaping "[" and "]":

headers add "New-Subject1: ${sg{$h_old-subject:}{\\\\[StringToRemove\\\\]}{}}"

lib/main.php:944: Notice: PageInfo: Cannot find action page

lib/main.php:839: Notice: PageInfo: Unknown action