Penguin
Annotated edit history of EximFilter version 14, including all changes. View license author blame.
Rev Author # Line
8 AristotlePagaltzis 1 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:
2
7 JohnMcPherson 3 * <tt>/usr/share/doc/exim/filter.txt{,.gz}</tt>
8 AristotlePagaltzis 4 * [Exim 3.3 Filter Specification | http://www.exim.org/exim-html-3.30/doc/html/filter.html]
5 / [Exim 4.0 Filter Specification | http://www.exim.org/exim-html-4.00/doc/html/filter.html]
7 JohnMcPherson 6
7 !!! Testing a filter
8
9 You can create a filter with any filename (such as $HOME/exim.filter) and then
10 test it with
11
12 <pre>
13 /usr/sbin/exim -bf $HOME/exim.filter -f ''fromaddress'' -bfl ''username'' -bfs ''+suffix''
14 </pre>
9 JohnMcPherson 15 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.
16
7 JohnMcPherson 17
18 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.
19
20 !!! Examples
21
22 !! A simple example
23
24 <verbatim>
25 # Exim filter - do not edit this line!
26 # only works for exim... others will treat it as a plain .forward file...
27
13 JohnMcPherson 28 # if this message is an error (bounce/"delivery failed"), then deliver to original
29 # address as per usual
7 JohnMcPherson 30 if error_message then finish endif
31
32 # I have mail forwarded to me from an account at another machine.
33 # it currently only gets spam, so automatically save to somewhere else.
34 # This match is a regular expression, hence need to double escape the "."
35 if $header_received: contains remotehost\\.co\\.nz
36 and $header_from: does not contain remotehost\\.co\\.nz
37 then
38 save $home/Mail/remotehostspam 0600 # 0600 is the file mode (as in chmod)
39 seen finish
40 endif
41
42 # default action - get exim to deliver as if this forward file wasn't here
43 # change this to whatever address this server is accepting your mail for
44 deliver thisemailaddress@verisign.com
45 finish
46 </verbatim>
11 JohnMcPherson 47
7 JohnMcPherson 48
49 !! For the [WLUG] MailServer
50
9 JohnMcPherson 51 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.
7 JohnMcPherson 52
11 JohnMcPherson 53 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.
7 JohnMcPherson 54
55 <verbatim>
56 # Exim filter - do not edit this line!
57
13 JohnMcPherson 58 # don't do any filtering for bounces/failure notifications
7 JohnMcPherson 59 if error_message then finish endif
60
61 # the 'testprint' command will print out its argument if you are running
62 # exim in test mode, and will do nothing if run 'live'
63 testprint "suffix is $local_part_suffix, subject is $h_subject"
64
65 # discard any mail that has "+nospam" as a suffix...
66 if ${local_part_suffix} is "+nospam" then
67 seen # tell exim that we've delivered it (even though we haven't really)
68 finish # don't try any more tests or deliveries
9 JohnMcPherson 69 endif
70
71 # discard mail that spam assassin assigned 5 or more points
72 # (SA on hoiho puts '+' chars in the X-Spam-Score header)
73 if $h_x-spam-score: contains +++++ then
74 seen finish
7 JohnMcPherson 75 endif
76
77
78 # any mail with the "+foo" suffix will have a copy sent elsewhere,
79 # AS WELL AS delivered as if this rule wasn't here
80 if ${local_part_suffix} is "+foo" then
81 unseen # pretend that we haven't delivered it, when we really have
82 deliver otheraddress@example.com
83 endif
84
85
86 # any mail with a suffix matching this regular expression will be saved into
87 # the "bugs" directory as maildir (ie one file per message).
88 # Note that:
89 # 1) \ and $ in a regular expression need to be \ escaped,
90 # 2) you need to use " and double-escaping if your pattern has whitespace, and
91 # 3) exim uses perl-compatible regular expressions
92 # (This matches if the suffix contains "bugs" or contains 3 or more digits in a row
93 if ${local_part_suffix} matches bugs|\\d{3,} then
94 # 0600 is the octal file permissions
11 JohnMcPherson 95 save $home/Maildir/bugs/ 0600
7 JohnMcPherson 96 finish # finish processing this filter file
97 endif
98 # Note! if you want mail applications to correctly recognise a folder as maildir
99 # format, make sure that it exists and has 3 subdirectories named
100 # "new", "tmp", and "cur". Otherwise you risk losing mail...
101
102 # if a message has a particular sender address (either From or Sender), save it
103 # into a particular file (as mbox). Note that this variable will be empty for
104 # automatically generated messages such as bounces
105 if $sender_address matches "@domainz\\\\.co\\\\.nz\\$" then
11 JohnMcPherson 106 save $home/Maildir/domainnames/ 0600
7 JohnMcPherson 107 endif
108
109
110 # ignore any mail that was sent from this network
111 if $h_received: contains static.tfn.net.tw then
112 # "seen finish" tells exim that we have processed this message
113 seen finish
114 endif
115
116
117 # default action, if this filter hasn't yet caused a 'significant delivery'
118 # for the incoming message
119
120 if not delivered then
121 deliver ${local_part}
122 endif
123
12 MatthewMcEachen 124 </verbatim>
125
126
127 !! Yet Another Exim Filter recipe:
128
13 JohnMcPherson 129 Rather than specific known suffices, deliver into a Maildir folder that's named the same as the suffix. No suffix? Go into INBOX:
12 MatthewMcEachen 130
131 <verbatim>
132 # Exim filter
133
134 if $local_part_suffix is ""
135 then
136 save $home/Maildir/
137 else
138 # Remove the first '-', and any periods in the suffix.
139 save $home/Maildir/.${sg{${sg{$local_part_suffix}{[\.]}{}}}{^-}{}}/
140 endif
14 MikeBordignon 141 </verbatim>
142
143 !! Escaping reserved characters in filters and system_filter
144
145 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 "~]":
146
147 <verbatim>
148 headers add "New-Subject1: ${sg{$h_old-subject:}{\\\\[StringToRemove\\\\]}{}}"
7 JohnMcPherson 149 </verbatim>

PHP Warning

lib/blame.php:177: Warning: Invalid argument supplied for foreach()