1#!/bin/sh
2#This a qmail specific bogofilter frontend script which allows the use of a centralized bogofilter
3#running on an smtp mail server
4#Copyright (C) Gyepi Sam <gyepi@praxis-sw.com> 2002
5
6#Change this!
7domain='example.com'
8
9#Change this if you want.
10sender='postmaster'
11TMPDIR='/tmp'
12
13opt="X"
14
15case "$EXT2" in
16	register-spam)		# register as spam
17		opt="-s"
18	;;
19
20	register-nonspam)	# register as non-spam
21		opt="-n"
22	;;
23
24	spam)			# unregister as ham
25				# register as spam
26		opt="-Ns"
27	;;
28
29	nonspam)		# unregister as spam
30				# register as ham
31		opt="-Sn"
32	;;
33esac
34
35if [ "${opt}" = "X" ]; then
36
37 tmpfile=$(mktemp "$TMPDIR/bogofilter-fe-$$.XXXXXX")
38
39 cat - > $tmpfile
40
41 #Quite a few  MUAs use Resent-* headers
42 recipient=$(formail -x Resent-From < $tmpfile|grep -i $domain| tr '\n' ',')
43
44 #but some don't
45 if [ "${recipient}X" = "X" ]; then
46	recipient=$SENDER
47	echo "bogofilter-qfe: defaulting error response to $SENDER"
48 fi
49
50 #may need to weed out specific recipients here
51
52 subject=$(formail -x Subject < $tmpfile)
53
54 rm -f $tmpfile
55
56 if [ -z "$recipient" ]; then
57   exit 0
58 fi
59
60 /usr/qmail/bin/qmail-inject -f$sender@$domain $recipient<<EOF
61From: "bogofilter frontend" <$sender@$domain>
62To:$recipient
63Subject: Re:$subject
64
65I was unable to understand the message you sent to $RECIPIENT.
66
67To correct a bogofilter classification:
68
69Send mis-classified spam to bogofilter-spam@$domain
70Send mis-classified nonspam to bogofilter-nonspam@$domain
71 
72To register new messages:
73
74Send spam to bogofilter-register-spam@$domain
75Send nonspam to bogofilter-register-nonspam@$domain
76
77In either case, be sure to 'bounce' or 'resend' the message rather than forwarding it.
78
79EOF
80
81else
82
83 exec /usr/bin/formail -c | \
84 /bin/sed "/^Resent/d; /^Delivered-To/d; /^Received.*$domain/d; /^X-Bogosity/d" | \
85 /usr/bin/bogofilter -d /home/bogofilter $opt
86
87fi
88