3 ### Spam filtering for distorted.org.uk Exim configuration
5 ### (c) 2012 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This program is free software; you can redistribute it and/or modify
11 ### it under the terms of the GNU General Public License as published by
12 ### the Free Software Foundation; either version 2 of the License, or
13 ### (at your option) any later version.
15 ### This program is distributed in the hope that it will be useful,
16 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ### GNU General Public License for more details.
20 ### You should have received a copy of the GNU General Public License
21 ### along with this program; if not, write to the Free Software Foundation,
22 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 ###--------------------------------------------------------------------------
28 SECTION(global, policy)m4_dnl
29 spamd_address = CONF_spamd_address CONF_spamd_port
31 SECTION(routers, allspam)m4_dnl
32 ## If we're verifying an address and the recipient has a `~/.mail/spam-limit'
33 ## file, then look up the recipient and sender addresses to find a plausible
34 ## limit and insert it into the `address_data' where the RCPT ACL can find
35 ## it. This router always declines, so it doesn't affect the overall outcome
36 ## of the verification.
41 local_part_suffix = CONF_user_suffix_list
42 local_part_suffix_optional = true
45 ${if def:address_data {$address_data}{}} \
46 ${if exists {CONF_userconf_dir/spam-limit} \
47 {${lookup {$local_part_prefix\
52 nwildlsearch {CONF_userconf_dir/spam-limit} \
56 ${if exists {CONF_userconf_dir/spam-limit.userv} \
57 {${run {timeout 5s -- \
58 userv $local_part exim-spam-limit \
64 {${if match{$value}{\N^[0-9]+$\N} \
70 SECTION(acl, rcpt-hooks)m4_dnl
71 ## Do per-recipient spam-filter processing.
72 require acl = rcpt_spam
74 SECTION(acl, misc)m4_dnl
77 ## If the client is trusted, or this is a new submission, don't
78 ## bother with any of this. We will have verified the sender
79 ## fairly aggressively before granting this level of trust.
80 accept hosts = +trusted
81 accept condition = ${if eq{$acl_c_mode}{submission}}
83 ## Otherwise we should check.
88 ## See if we should do this check.
89 accept acl = skip_spam_check
91 ## Always accept mail to `postmaster'. Currently this is not
92 ## negotiable; maybe a tweak can be added to `domains.conf' if
94 accept local_parts = postmaster
96 ## Collect the user's spam threshold from the `address_data'
97 ## variable, where it was left by the `fetch_spam_limit' router
98 ## during recipient verification. (This just saves duplicating this
99 ## enormous expression.)
100 warn set acl_m_this_spam_limit = \
101 ${sg {${extract {spam_limit} \
102 {${if def:address_data \
103 {$address_data}{}}} \
105 {^(|.*\\D.*)\$}{CONF_spam_max}}
107 ## If there's a spam limit already established, and it's different
108 ## from this user's limit, then the sender will have to try this user
110 defer !hosts = +trusted
111 message = "You'd better try this one later"
112 condition = ${if def:acl_m_spam_limit {true}{false}}
113 condition = ${if ={$acl_m_spam_limit} \
114 {$acl_m_this_spam_limit} \
117 ## There's no limit set yet, or the user's limit is the same as the
118 ## existing one, or the client's local and we're not checking for
119 ## spam anyway. Whichever way, it's safe to set it now.
120 warn set acl_m_spam_limit = $acl_m_this_spam_limit
125 SECTION(acl, data-spam)m4_dnl
127 require acl = data_spam
129 SECTION(acl, misc)m4_dnl
132 ## See if we should do this check.
133 accept acl = skip_spam_check
135 ## Check header validity.
136 require verify = header_syntax
138 ## Check the message for spam, comparing to the configured limit.
139 deny spam = exim:true
140 message = Tinned meat product detected ($spam_score)
141 condition = ${if >{$spam_score_int}{$acl_m_spam_limit} \
144 ## Insert headers from the spam check now that we've decided to
145 ## accept the message.
148 ## Convert the limit (currently 10x fixed point) into a
149 ## decimal for presentation.
150 set acl_m_spam_limit_presentation = \
151 ${sg{$acl_m_spam_limit}{\N(\d)$\N}{.\$1}}
153 ## Convert the report into something less obnoxious. Plain
154 ## old SpamAssassin has an `X-Spam-Status' header which
155 ## lists the matched rules and provides some other basic
156 ## information. Try to extract something similar from the
159 ## This is rather fiddly.
161 ## Firstly, escape angle brackets, because we'll be using
162 ## them for our own purposes.
163 set acl_m_spam_tests = ${sg{$spam_report}{([!<>])}{!\$1}}
165 ## Trim off the blurb paragraph and the preview. The rest
166 ## should be fairly well behaved. Wrap double angle-
167 ## brackets around the remainder; these can't appear in the
168 ## body because we escaped them all earlier.
169 set acl_m_spam_tests = \
170 ${sg{$acl_m_spam_tests} \
171 {\N^(?s).*\n Content analysis details:(.*)$\N} \
174 ## Extract the information about the matching rules and
175 ## their scores. Leave `<<...>>' around everything else.
176 set acl_m_spam_tests = \
177 ${sg{$acl_m_spam_tests} \
178 {\N(?s)\n\s*(-?[\d.]+)\s+([-\w]+)\s\N} \
181 ## Strip everything still in `<<...>>' pairs, including any
182 ## escaped characters inside.
183 set acl_m_spam_tests = \
184 ${sg{$acl_m_spam_tests}{\N(?s)<<([^!>]+|!.)*>>\N}{}}
186 ## Trim off a trailing comma.
187 set acl_m_spam_tests = ${sg{$acl_m_spam_tests}{,\s*\$}{}}
189 ## Undo the escaping.
190 set acl_m_spam_tests = ${sg{$acl_m_spam_tests}{!(.)}{\$1}}
192 ## Insert the headers.
193 add_header = X-SpamAssassin-Score: \
194 $spam_score/$acl_m_spam_limit_presentation \
196 add_header = X-SpamAssassin-Status: \
198 limit=$acl_m_spam_limit_presentation, \n\t\
199 tests=$acl_m_spam_tests
205 ###----- That's all, folks --------------------------------------------------