284530912d726cb8fa338a320cc6a2ca11a59834
[librecmc/package-feed.git] / mail / bogofilter / files / postfix-bogofilter
1 #!/bin/sh
2
3 FILTER=/usr/bin/bogofilter
4
5 # Attempt to read from bogofilter configuration.
6 FILTER_DIR=$(cat /etc/bogofilter.cf | sed 's/#.*//g' | grep ^bogofilter_dir | awk -F = '{ print $2 }')
7
8 # WARNING! The -i is crucial, else you may see
9 # messages truncated at the first period that is alone on a line
10 # (which can happen with several kinds of messages, particularly
11 # quoted-printable)
12 # -G is ignored before Postfix 2.3 and tells it that the message
13 # does not originate on the local system (Gateway submission),
14 # so Postfix avoids some of the local expansions that can leave
15 # misleading traces in headers, such as local address
16 # canonicalizations.
17 POSTFIX="/usr/sbin/sendmail -G -i"
18
19 # No bogofilter_dir set in /etc/bogofilter.cf; fall back on directory
20 # which persists across reboots.
21 if [ -z "$FILTER_DIR" ]; then
22         FILTER_DIR=/etc/bogofilter
23         export BOGOFILTER_DIR=$FILTER_DIR
24 fi
25
26 # Exit codes from <sysexits.h>
27 EX_TEMPFAIL=75
28 EX_UNAVAILABLE=69
29
30 cd $FILTER_DIR || \
31     { echo $FILTER_DIR does not exist; exit $EX_TEMPFAIL; }
32
33 # Clean up when done or when aborting.
34 trap "rm -f msg.$$ ; exit $EX_TEMPFAIL" 0 1 2 3 15
35
36 # bogofilter -e returns: 0 for OK, nonzero for error
37 rm -f msg.$$ || exit $EX_TEMPFAIL
38 $FILTER -p -e > msg.$$ || exit $EX_TEMPFAIL
39
40 exec <msg.$$ || exit $EX_TEMPFAIL
41 rm -f msg.$$ # safe, we hold the file descriptor
42 exec $POSTFIX "$@"
43 exit $EX_TEMPFAIL