| 1 |
# |
| 2 |
# reto_procmail.recipe - Check message with crm114 |
| 3 |
# |
| 4 |
# Copyright 2004 Reto Lichtensteiger |
| 5 |
# Copyright 2004-2009 William S. Yerazunis. |
| 6 |
# This file is under GPLv3, as described in COPYING. |
| 7 |
# |
| 8 |
|
| 9 |
|
| 10 |
# NOTE: This recipe invokes crm114 on a message. It does NOT filter |
| 11 |
# the message to a spam folder. How you choose to manage that task |
| 12 |
# up to you. |
| 13 |
# |
| 14 |
|
| 15 |
CRM="/usr/local/bin/crm" |
| 16 |
CRMDIR="${HOME}/.crm114" |
| 17 |
UTRACE="" # -t turns on crm script tracing |
| 18 |
|
| 19 |
CRMVERSION="`${CRM} '-{ output /:*:_crm_version:/}' < /dev/null` [stats_only]" |
| 20 |
|
| 21 |
# |
| 22 |
# It is possible for crm114 to DoS if it receives a very large message. |
| 23 |
# To prevent this, the author has coded an upper bound to the size |
| 24 |
# message that mailfilter.crm will accept. |
| 25 |
# |
| 26 |
# We can prevent messages from hitting that limit by only feeding a |
| 27 |
# portion of the message to crm114, but this has a slightly more |
| 28 |
# subtle problem in that messages are often fed to crm114 as filters, |
| 29 |
# which means procmail expects the message to be modified. Using |
| 30 |
# head(1) to limit the message size going into a filter recipe will |
| 31 |
# truncate the actual message, not just a copy. "Oops" |
| 32 |
# |
| 33 |
# This recipe set uses crm114 as a direct "f"ilter if the message is |
| 34 |
# smaller than $BIGGEST, otherwise the message is truncated with head |
| 35 |
# and crm114 is set (via "--stats_only" switch) to report only. The |
| 36 |
# output from crm114 when run in this mode is captured and formail is |
| 37 |
# used to put the same headers in place that crm114 would normally |
| 38 |
# add. |
| 39 |
# |
| 40 |
|
| 41 |
BIGGEST="20000" |
| 42 |
|
| 43 |
:0 |
| 44 |
* < ${BIGGEST} |
| 45 |
{ |
| 46 |
:0 fw |
| 47 |
| ${CRM} ${UTRACE} -u ${CRMDIR} mailfilter.crm |
| 48 |
|
| 49 |
# if crm114 failed, return the mail to the queue where the MTA will |
| 50 |
# retry delivery at a later date. (EX_TEMPFAIL in /usr/include/sysexits.h) |
| 51 |
|
| 52 |
:0 e |
| 53 |
{ EXITCODE=75 } |
| 54 |
} |
| 55 |
|
| 56 |
# |
| 57 |
# If the first recipe doesn't match the size test, then the message is |
| 58 |
# larger than ${BIGGEST} |
| 59 |
# |
| 60 |
|
| 61 |
:0 E |
| 62 |
{ |
| 63 |
# For programs invoked via backtick operator, procmail puts the mail |
| 64 |
# message on stdin. The line below feeds the mail message through |
| 65 |
# head to truncate it and then into crm114. |
| 66 |
|
| 67 |
CRMOUT="`head -c ${BIGGEST} | ${CRM} -u ${CRMDIR} mailfilter.crm --stats_only\`" |
| 68 |
|
| 69 |
# If CRMOUT is undefined (or empty) then crm114 failed. Set the exit |
| 70 |
# code to 75, so that procmail uses that as an exitcode. THe MTA |
| 71 |
# that invoked procmail will see that as "TEMPFAIL" and requeue the |
| 72 |
# message. THe script then unsets the HOST variable to tell procmail |
| 73 |
# to exit. |
| 74 |
|
| 75 |
:0 |
| 76 |
* CRMOUT ?? ^^^^ |
| 77 |
{ |
| 78 |
EXITCODE=75 |
| 79 |
HOST |
| 80 |
} |
| 81 |
|
| 82 |
:0 |
| 83 |
* CRMOUT ?? ^- |
| 84 |
{ VALUE="SPAM" } |
| 85 |
|
| 86 |
:0 E |
| 87 |
{ VALUE="Good" } |
| 88 |
|
| 89 |
:0 f |
| 90 |
| formail -A "X-CRM114-Version: ${CRMVERSION}" \ |
| 91 |
-A "X-CRM114-Status: ${VALUE} ( pR: ${CRMOUT})" |
| 92 |
|
| 93 |
CRMOUT |
| 94 |
VALUE |
| 95 |
} |
| 96 |
|
| 97 |
:0 |
| 98 |
* ^X-CRM114-Status: SPAM |
| 99 |
{ LOG="SPAM: CRM114 (Sure)${NL}" } |
| 100 |
|
| 101 |
# Unset variables |
| 102 |
CRM |
| 103 |
CRMDIR |
| 104 |
CRMVERSION |
| 105 |
UTRACE |
| 106 |
|