Penguin
Note: You are viewing an old revision of this page. View the current version.

If you start your .forward file with "# Exim filter", then the Exim mail program 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

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.

Examples

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 filter generates an error, 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
then
 save $home/Mail/remotehostspam 0600 # 0600 is the file mode (as in chmod)
 seen finish
endif

# 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
deliver thisemailaddress@verisign.com
finish

For the WLUG MailServer

Since Exim on the MailServer supports a suffix (eg any mail to username+suffix@example.com 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.

# Exim filter - do not edit this line!

# if this filter generates an error, then exim will act as if there was
# no filter file (as per usual)
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
endif


# 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
  deliver otheraddress@example.com
endif


# 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/new/$message_id.$domain 0600
  finish # finish processing this filter file
endif
# 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/mail/domainnames 0600
endif


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


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

if not delivered then
  deliver ${local_part}
endif