Penguin

Differences between version 5 and predecessor to the previous major change of EximFilter.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 5 Last edited on Thursday, December 2, 2004 4:29:19 pm by JohnMcPherson Revert
Older page: version 2 Last edited on Wednesday, September 24, 2003 8:29:53 am by JohnMcPherson Revert
@@ -2,28 +2,120 @@
  
 If you have exim installed, you can probably find comprehensive documentation on this in 
  /usr/share/doc/exim/filter.txt{,.gz} 
 otherwise have a look online at www.exim.org/exim-html-3.30/doc/html/filter.html or www.exim.org/exim-html-4.00/doc/html/filter.html depending on which version of exim you have installed. 
+  
+!!!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''  
+(changing fromaddress, username, and suffix if you want to test specific  
+rules in your filter file).  
+  
+This will read an email message from stdin(3), but you can supply an empty message  
+if your filter is simple enough that it doesn't use any message headers.  
+If you don't give -bfl it will default to your username.  
+  
+Exim will then tell you which tests it matched, and what it would have done if it received that message 'for real'.  
+  
+----  
+!!!Examples  
  
 Here is a simple example: 
+<verbatim>  
+# 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  
+</verbatim>  
+----  
+!Example for [WLUG] MailServer  
+  
+Since exim on the mail server supports a suffix (eg any mail to username+suffix@example.com gets delivered to username, regardless of what string is used for 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 argument as a file ('mbox' format) rather than as a 'Maildir'  
+directory.  
+  
+<verbatim>  
+# 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  
  
- # 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  
+# default action, if this filter hasn't yet caused a 'significant delivery'  
+# for the incoming message 
  
- # 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  
- seen finish  
- endif 
+if not delivered then  
+ deliver ${local_part}  
+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  
+</verbatim>