bogofilter script
Michael Gale
michael.gale at utilitran.com
Thu Nov 4 21:14:11 CET 2004
Hello,
I have been using Bogofilter for some time now and it works great, but
I am now curious on how the bogofilter script works, if some one could
explain the following or correct me understanding that would be great.
Script from bogofilter documentation:
#!/bin/sh
FILTER=/usr/bin/bogofilter
FILTER_DIR=/var/spool/filter
POSTFIX=/usr/sbin/sendmail
export BOGOFILTER_DIR=/home/bogofilter
# Exit codes from <sysexits.h>
EX_TEMPFAIL=75
EX_UNAVAILABLE=69
cd $FILTER_DIR || \
{ echo $FILTER_DIR does not exist; exit $EX_TEMPFAIL; }
# Clean up when done or when aborting.
trap "rm -f msg.$$ ; exit $EX_TEMPFAIL" 0 1 2 3 15
# bogofilter -e returns: 0 for OK, nonzero for error
rm -f msg.$$ || exit $EX_TEMPFAIL
$FILTER -p -u -e > msg.$$ || exit $EX_TEMPFAIL
exec <msg.$$ || exit $EX_TEMPFAIL
rm -f msg.$$ # safe, we hold the file descriptor
exec $POSTFIX "$@"
exit $EX_TEMPFAIL
The first part is easy:
FILTER=/usr/bin/bogofilter
FILTER_DIR=/var/spool/filter
POSTFIX=/usr/sbin/sendmail
export BOGOFILTER_DIR=/home/bogofilter
Set up the variables and export the BOGOFILTER_DIR variable.
The second part is also easy:
# Exit codes from <sysexits.h>
EX_TEMPFAIL=75
EX_UNAVAILABLE=69
cd $FILTER_DIR || \
{ echo $FILTER_DIR does not exist; exit $EX_TEMPFAIL; }
# Clean up when done or when aborting.
trap "rm -f msg.$$ ; exit $EX_TEMPFAIL" 0 1 2 3 15
Set two exit codes, a FILTER_DIR check and a trap for signals 0,1,2,3,15
This is where I get a little confused:
# bogofilter -e returns: 0 for OK, nonzero for error
1. rm -f msg.$$ || exit $EX_TEMPFAIL
2. $FILTER -p -u -e > msg.$$ || exit $EX_TEMPFAIL
3. exec <msg.$$ || exit $EX_TEMPFAIL
4. rm -f msg.$$ # safe, we hold the file descriptor
5. exec $POSTFIX "$@"
6. exit $EX_TEMPFAIL
line 2. Has bogofilter read from input / pipe a message and direct the
out put to msg.$$ (process ID) and exit if unable to do so.
line 3. Passes the new file containing the scanned message to the exec
function ?
line 4. Removes the message
line 5. Executes sendmail passing the argument array $@
that contains the new message.
line 6. Exit with a EX_TEMPFAIL ?
I don't understand line 1. < Why the need to remove a file that should
not exist ? Also if EX_TEMPFAIL is a exit status when some thing goes
wrong why does it exit with that value at the end ?
Thanks.
--
Michael Gale
Lan Administrator
Utilitran Corp.
We Pledge Allegiance to the Penguin
More information about the Bogofilter
mailing list