[Fwd: Whitelist ??]

Michael Gale michael.gale at utilitran.com
Tue Dec 7 00:11:22 CET 2004


Hello,

	I found a few errors of my own ... it seems the script was not working 
as expected before.

Here is the current version ...

#!/bin/sh

FILTER=/usr/local/bin/bogofilter
FILTER_DIR=/home/clamav/bogofilter/filter
POSTFIX=/usr/sbin/sendmail
export BOGOFILTER_DIR=/home/clamav/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

#### Before I was using ${2} .. wrong one ...
whitelistdir=`grep -i ${4} /etc/postfixvirtual/vmailbox | gawk '{print $2}'`

##### By spliting it up and using wc for the count ... grep errors about 
#####file not existing are piped to dev/null and a non-match is 
#####considered.
num=`echo $2 | grep -i -f 
$BOGOFILTER_DIR/whitelist/${whitelistdir}whitelist  2> /dev/null | wc -l`

if [ $num -eq 0 ]; then
         $FILTER -l -p -e > msg.$$ || exit $EX_TEMPFAIL
else
         $FILTER -l -p -e --spamicity_tags="Whitelisted,Ham,Unsure" > 
msg.$$ || exit $EX_TEMPFAIL
fi

exec <msg.$$ || exit $EX_TEMPFAIL
#cp msg.$$ /home/clamav/bogofilter/mail_archive/msg.$$
rm -f msg.$$ # safe, we hold the file descriptor
exec $POSTFIX "$@"
exit $EX_TEMPFAIL




David Relson wrote:
> On Mon, 06 Dec 2004 15:46:53 -0700
> Michael Gale wrote:
> 
> 
> Reading stdin twice isn't doable, AFAIK.  I use "cat > tmp.$$" to create
> a file and then use that.
> 
> 
>>if [ `grep -c -i -f $BOGOFILTER_DIR/whitelist/$whitelistdir/whitelist
>>
>>/dev/null` ]; then
>>         $FILTER -l -p -e --spamicity_tags="Whitelisted,Ham,Unsure" >
>>msg.$$ || exit $EX_TEMPFAIL
>>else
>>         $FILTER -l -p -e > msg.$$ || exit $EX_TEMPFAIL
>>fi
> 
> 
> FWIW, these lines could be rewritten as:
> 
>  grep ...
>  if [ $? ] ; then
>    OPTIONS="--spamicity_tags=..."
>  fi
>  $FILTER -l -p -e $OPTIONS > msg.$$ || exit $EX_TEMPFAIL
> 
> ...[snip]...
> 
> Looks reasonable to me.  I'll let others continue the search for
> gotchas.
> 
> Regards,
> 
> David
> _______________________________________________
> Bogofilter mailing list
> Bogofilter at bogofilter.org
> http://www.bogofilter.org/mailman/listinfo/bogofilter
> 
> 
> 
> 

-- 
Michael Gale
Lan Administrator
Utilitran Corp.

Linux: because a PC is a terrible thing to waste !!!



More information about the Bogofilter mailing list