Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
EximFilter
Edit
PageHistory
Diff
Info
LikePages
If you start your <tt>.forward</tt> file with __<tt># Exim filter</tt>__, then the [Exim] [MTA] can do some processing of your incoming [Email]. Documentation about this is available at: * <tt>/usr/share/doc/exim/filter.txt{,.gz}</tt> * [Exim 3.3 Filter Specification | http://www.exim.org/exim-html-3.30/doc/html/filter.html] / [Exim 4.0 Filter Specification | http://www.exim.org/exim-html-4.00/doc/html/filter.html] !!! Testing a filter You can create a filter with any filename (such as $HOME/exim.filter) and then test it with <pre> /usr/sbin/exim -bf $HOME/exim.filter -f ''fromaddress'' -bfl ''username'' -bfs ''+suffix'' </pre> 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 <tt>-bfl</tt> 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 <verbatim> # 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 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> !! For the [WLUG] MailServer Since [Exim] on the WlugServer supports a suffix (eg any mail to <tt>username+suffix@example.com</tt> gets delivered to <tt>username</tt>, regardless the <tt>suffix</tt>), you can filter incoming messages based on this. Probably the only thing to be aware of is that if you use the <tt>save</tt> 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. <verbatim> # 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 endif # 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 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/ 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/Maildir/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 </verbatim> !! 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: <verbatim> # Exim filter if $local_part_suffix is "" then save $home/Maildir/ else # Remove the first '-', and any periods in the suffix. save $home/Maildir/.${sg{${sg{$local_part_suffix}{[\.]}{}}}{^-}{}}/ endif </verbatim> !! 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 "~]": <verbatim> headers add "New-Subject1: ${sg{$h_old-subject:}{\\\\[StringToRemove\\\\]}{}}" </verbatim>
2 pages link to
EximFilter
:
WlugMailNotes
EximNotes