Hello,
i created patch for bogofilter.
There is 2 version of bogofilter scanner - fast (not fully implemented) and
verbose (add X-Bogosity header).
Should working - but use with caution.
I need talk with author of qmail-scanner to implement "official" bogofilter
plugin and clear my code (if will be used, because i'm not perl programmer)
--
Lampa
diff -rNC3 qmail-scanner-2.00/configure qmail-scanner-2.00-bogo/configure
*** qmail-scanner-2.00/configure Wed Apr 5 12:08:41 2006
--- qmail-scanner-2.00-bogo/configure Wed Dec 27 11:12:48 2006
***************
*** 38,44 ****
VERSION=`grep '^# Version: ' qmail-scanner-queue.template`
VERSION=`echo $VERSION|awk '{print $NF}'`
! SUPPORTED_SCANNERS="avgd,clamdscan,clamscan,bitdefender,nod32,clamuko,sweep,sophie,vscan,trophie,uvscan,csav,antivir,kavscanner,AvpLinux,kavdaemon,AvpDaemonClient,fsav,fprot,inocucmd,ravlin,vexira,verbose_spamassassin,fast_spamassassin"
SILENT_VIRUSES='klez,bugbear,hybris,yaha,braid,nimda,tanatos,sobig,winevar,palyh,fizzer,gibe,cailont,lovelorn,swen,dumaru,sober,hawawi,holar-i,mimail,poffer,bagle,worm.galil,mydoom,worm.sco,tanx,novarg,[EMAIL PROTECTED]'
--- 38,44 ----
VERSION=`grep '^# Version: ' qmail-scanner-queue.template`
VERSION=`echo $VERSION|awk '{print $NF}'`
! SUPPORTED_SCANNERS="avgd,clamdscan,clamscan,bitdefender,nod32,clamuko,sweep,sophie,vscan,trophie,uvscan,csav,antivir,kavscanner,AvpLinux,kavdaemon,AvpDaemonClient,fsav,fprot,inocucmd,ravlin,vexira,verbose_spamassassin,fast_spamassassin,verbose_bogofilter,fast_bogofilter"
SILENT_VIRUSES='klez,bugbear,hybris,yaha,braid,nimda,tanatos,sobig,winevar,palyh,fizzer,gibe,cailont,lovelorn,swen,dumaru,sober,hawawi,holar-i,mimail,poffer,bagle,worm.galil,mydoom,worm.sco,tanx,novarg,[EMAIL PROTECTED]'
***************
*** 149,154 ****
--- 149,155 ----
--mime-unpacker) if [ "$2" != "" ] ; then shift ; fi ; MIME_UNPACKER="$1" ;;
--sa-quarantine) if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ]; then shift ; fi ; SA_TEMP="$1" ;;
--install) INSTALLIT="1" ; if [ "$2" != "" -a "`echo $2|grep '\-'`" = "" ] ; then shift ; fi ;;
+ --bogofilter-dir) if [ "$2" != "" ] ; then shift ; fi ; BOGOFILTER_DIR="$1" ;;
*) cat <<EOF >&2
valid options:
***************
*** 320,325 ****
--- 321,327 ----
your system - YOU WILL NEED TO SET THIS VALUE IN ORDER TO GAIN ANY
PROTECTION. Something like "100000000" (100 Mb) might be appropriate.
--batch Do not confirm configure information (mainly for scripting)
+ --bogofilter-dir Directory for bogofilter wordlist.
--install Create directory paths, install perl script,
and change ownerships to match.
--mime-unpacker "reformime" Defaults to reformime.
***************
*** 1049,1054 ****
--- 1051,1077 ----
fi
fi
+ if [ "`echo $FIND_SCANNERS|grep bogofilter`" != "" -a "$BOGOFILTER_BINARY" = "" ]; then
+ if test -x $dir/bogofilter
+ then
+ BOGOFILTER_BINARY="$dir/bogofilter"
+ if [ "`echo $FIND_SCANNERS|grep fast_bogofilter`" != "" ]; then
+ BOGOFILTER_VERSION="fast_bogofilter"
+ BOGOFILTER_OPTIONS="-t -u"
+ INSTALLED_SCANNERS="$INSTALLED_SCANNERS
+ fast_bogofilter"
+ else
+ BOGOFILTER_VERSION="verbose_bogofilter"
+ BOGOFILTER_OPTIONS="-p -u"
+ INSTALLED_SCANNERS="$INSTALLED_SCANNERS
+ verbose_bogofilter"
+ fi
+ if [ "$BOGOFILTER_DIR" != "" ]; then
+ BOGOFILTER_OPTIONS="$BOGOFILTER_OPTIONS -d $BOGOFILTER_DIR"
+ fi
+ fi
+ fi
+
if [ "`echo $FIND_SCANNERS|grep spamassassin`" != "" -a "$SPAMASSASSIN_BINARY" = "" ]; then
if test -x $dir/spamassassin
then
***************
*** 1553,1558 ****
--- 1576,1590 ----
fi
fi
+ if [ "$BOGOFILTER_BINARY" != "" ]; then
+ if [ "$BOGOFILTER_VERSION" = "fast_bogofilter" ]; then
+ SCANNER_ARRAY="$SCANNER_ARRAY,\"fast_bogofilter\""
+ else
+ SCANNER_ARRAY="$SCANNER_ARRAY,\"verbose_bogofilter\""
+ fi
+ echo "bogofilter=$BOGOFILTER_BINARY";
+ fi
+
USERNAME=${USERNAME:-$LOGNAME}
SCANNER_ARRAY=`echo $SCANNER_ARRAY|sed 's/^,//g'`
***************
*** 1643,1648 ****
--- 1675,1681 ----
echo "scanners=`echo $SCANNER_ARRAY|sed 's/_scanner//g'`"
SCANNER_ARRAY="`echo $SCANNER_ARRAY|sed -e 's/fast_spamassassin/spamassassin/g' -e 's/verbose_spamassassin/spamassassin/g'`"
+ SCANNER_ARRAY="`echo $SCANNER_ARRAY|sed -e 's/fast_bogofilter/bogofilter/g' -e 's/verbose_bogofilter/bogofilter/g'`"
cat<<EOF
If that looks correct, I will now generate qmail-scanner-queue.pl
***************
*** 1803,1808 ****
--- 1836,1844 ----
s?SPAMC_BINARY?$SPAMC_BINARY?g;
s?SPAMC_OPTIONS?$SPAMC_OPTIONS?g;
s?SPAMC_SUBJECT?$SPAMC_SUBJECT?g;
+ s?BOGOFILTER_BINARY?$BOGOFILTER_BINARY?g;
+ s?BOGOFILTER_OPTIONS?$BOGOFILTER_OPTIONS?g;
+ s?BOGOFILTER_SUBJECT?$BOGOFILTER_SUBJECT?g;
s?USERNAME?$USERNAME?g;
s?SKIP_TEXT_MSGS?$SKIP_TEXT_MSGS?g;
s?FQDN?$FQDN?g;
#########################
## END of scanner definitions
##
diff -rNC3 qmail-scanner-2.00/qmail-scanner-queue.template qmail-scanner-2.00-bogo/qmail-scanner-queue.template
*** qmail-scanner-2.00/qmail-scanner-queue.template Wed Apr 5 11:52:40 2006
--- qmail-scanner-2.00-bogo/qmail-scanner-queue.template Wed Dec 27 13:03:32 2006
***************
*** 240,246 ****
--- 240,249 ----
my $spamc_options='SPAMC_OPTIONS';
my $spamc_subject='SPAMC_SUBJECT';
my $spamassassin_binary='SPAMASSASSIN_BINARY';
+ my $bogofilter_binary="BOGOFILTER_BINARY";
+ my $bogofilter_options="BOGOFILTER_OPTIONS";
my $sa_quarantine_over='SA_QUARANTINE';
+ my $bf_comment;
my ($sa_comment,$sa_level);
my $sa_symbol='+';
my ($tag_score)="";
***************
*** 1384,1404 ****
#Just run virus scanners over mail that isn't plain text
if ($plain_text_msg) {
#If it's plain text - just run anti-spam checks
! if ($scanType eq "spam" && $scanner =~ /(^spam)/i) {
! &debug("scanloop: scanner=$scanner,plain_text_msg=$plain_text_msg");
! &{$scanner};
}
! }else {
if ($scanType ne "spam") {
! if ($scanner !~ /(^spam)/i) {
! &debug("scanloop: scanner=$scanner,plain_text_msg=$plain_text_msg");
! &{$scanner};
! }
! }else{
! if ($scanner =~ /(^spam)/i) {
! &debug("scanloop: scanner=$scanner,plain_text_msg=$plain_text_msg");
! &{$scanner};
! }
}
}
if ($quarantine_event) {
--- 1387,1407 ----
#Just run virus scanners over mail that isn't plain text
if ($plain_text_msg) {
#If it's plain text - just run anti-spam checks
! if ($scanType eq "spam" && ($scanner =~ /(^spam|bogo)/i)) {
! &debug("scanloop: scanner=$scanner,plain_text_msg=$plain_text_msg");
! &{$scanner};
}
! } else {
if ($scanType ne "spam") {
! if ($scanner !~ /(^spam|bogo)/i) {
! &debug("scanloop: scanner=$scanner,plain_text_msg=$plain_text_msg");
! &{$scanner};
! }
! } else {
! if ($scanner =~ /(^spam|bogo)/i) {
! &debug("scanloop: scanner=$scanner,plain_text_msg=$plain_text_msg");
! &{$scanner};
! }
}
}
if ($quarantine_event) {
***************
*** 1459,1465 ****
print QMQ " Processed in $elapsed_time secs); $findate\n";
if ($sa_comment ne "") {
print QMQ "X-Spam-Status: $sa_comment\n";
! # print QMQ "X-Spam-Level: $sa_level\n";
}
#Only add these headers for Internet-incoming
if ( $descriptive_hdrs && !$QS_RELAYCLIENT) {
--- 1462,1470 ----
print QMQ " Processed in $elapsed_time secs); $findate\n";
if ($sa_comment ne "") {
print QMQ "X-Spam-Status: $sa_comment\n";
! }
! if ($bf_comment ne "") {
! print QMQ "X-Spam-Status: $bf_comment\n";
}
#Only add these headers for Internet-incoming
if ( $descriptive_hdrs && !$QS_RELAYCLIENT) {
***************
*** 1476,1481 ****
--- 1481,1489 ----
if ($sa_comment ne "" && /^(X-Spam-Status|X-Spam-Flag|X-Spam-Level):/i) {
s/^(X-Spam-Status|X-Spam-Flag|X-Spam-Level):/${V_HEADER}-MOVED-$1:/i;
}
+ if ($bf_comment ne "" && /^(X-Bogosity):/i) {
+ s/^(X-Bogosity):/${V_HEADER}-MOVED-$1:/i;
+ }
if ($sa_comment =~ /^yes/i && $spamc_subject ne "" && !/^Subject: \Q$spamc_subject\E/i && /^(Subject):(\s?)([^\n]+)\n/i ) {
$altered_subject="$1: $spamc_subject $3";
if ($altered_subject !~ /^: \Q$spamc_subject\E/) {
***************
*** 1676,1682 ****
sub scan_queue {
my ($scanner,$SCANINFO,$files,$sweep_eng,$sweep_product,$sophie_eng,$dir);
my $start_scan_time =time;
! my ($inocucmd_eng,$inocucmd_product,$spamassassin_eng);
chdir($scandir);
&debug("s_q: re-create the quarantine version file");
--- 1684,1690 ----
sub scan_queue {
my ($scanner,$SCANINFO,$files,$sweep_eng,$sweep_product,$sophie_eng,$dir);
my $start_scan_time =time;
! my ($inocucmd_eng,$inocucmd_product,$spamassassin_eng,$bogofilter_version);
chdir($scandir);
&debug("s_q: re-create the quarantine version file");
***************
*** 1900,1905 ****
--- 1908,1924 ----
}
close(SPAS);
$SCANINFO .= "spamassassin: $spamassassin_eng. ";
+ } elsif ($scanner eq "bogofilter") {
+ #X-Spam-Checker-Version: SpamAssassin 2.01
+ open(SPAS,"$bogofilter_binary -V 2>&1 |")||die "failed to call $bogofilter_binary -V - $!";
+ while (<SPAS>) {
+ chomp;
+ if (/^bogofilter version (.*)$/i) {
+ $bogofilter_version=$1;
+ }
+ }
+ close(SPAS);
+ $SCANINFO .= "bogofilter: $bogofilter_version. ";
} else {
#Catch-all for other ones
$SCANINFO .= "$scanner: ???. ";
diff -rNC3 qmail-scanner-2.00/sub-bogofilter.pl qmail-scanner-2.00-bogo/sub-bogofilter.pl
*** qmail-scanner-2.00/sub-bogofilter.pl Thu Jan 1 01:00:00 1970
--- qmail-scanner-2.00-bogo/sub-bogofilter.pl Wed Dec 27 11:54:01 2006
***************
*** 0 ****
--- 1,67 ----
+ sub bogofilter {
+ return if ($quarantine_event);
+ #Only run BF if mail is from a "remote" SMTP client, or QS_BOGOFILTER
+ #is defined via tcpserver...
+ if (defined($ENV{'RELAYCLIENT'}) && !defined($ENV{'QS_BOGOFILTER'})) {
+ &debug("BF: don't scan as RELAYCLIENT implies this was sent by a local user");
+ return;
+ }
+ my ($start_bogofilter_time)=[gettimeofday];
+ my ($bogofilter_status,$stop_bogofilter_time,$bogofilter_time);
+ my ($bf_status)=0;
+ my ($bf_score)=0;
+ my ($bf_version);
+ my ($bf_fast)=0;
+ $bf_fast=1 if ($bogofilter_options !~ /\-p/ && $bogofilter_options =~ /\-t/);
+ &debug("BF: run $bogofilter_binary $bogofilter_options < $scandir/$wmaildir/new/$file_id");
+ open(BF, "$bogofilter_binary $bogofilter_options < $scandir/$wmaildir/new/$file_id|") || &tempfail("cannot run $bogofilter_binary < $scandir/$wmaildir/new/$file_id - $!");
+ open(SOUT, ">$scandir/$wmaildir/new/$file_id.bogof") || &tempfail("cannot open for write $scandir/$wmaildir/new/$file_id.bogof - $!");
+ while (<BF>) {
+ if ($bf_fast) {
+ if (/^S|H|U (.*)/) {
+ $bf_score=$1;
+ $bf_version="unknown";
+ }
+ } else {
+ if (/^X-Bogosity: (Spam|Unsure|Ham), tests=bogofilter, spamicity=(.*), version=(.*)/) {
+ $bf_score=$2;$bf_version=$3;
+ }
+ }
+ print SOUT;
+ }
+ close(SOUT);
+ close(BF);
+
+ $bogofilter_status=($? >> 8);
+ # $bf_status = $bogofilter_status if ($bf_fast);
+
+ # $bf_score="0" if (!$bf_score);
+
+ if (!$bf_fast && -s "$scandir/$wmaildir/new/$file_id.bogof" && $bogofilter_status != 3) {
+ &debug("BF: overwriting $scandir/$wmaildir/new/$file_id with $scandir/$wmaildir/new/$file_id.bogof");
+ rename ("$scandir/$wmaildir/new/$file_id.bogof","$scandir/$wmaildir/new/$file_id");
+ } else {
+ unlink("$scandir/$wmaildir/new/$file_id.bogof");
+ }
+ &debug("BF: bf_status=$bogofilter_status, options=$bogofilter_options");
+ if ($bogofilter_status == 0) {
+ $tag_score .= "BF:1($bf_score):";
+ $bf_comment = "Yes, Score:$bf_score";
+ &debug("BF: yup, this smells like SPAM");
+ } elsif ($bogofilter_status == 1) {
+ $tag_score .= "BF:0($bf_score):";
+ $bf_comment = "No, Score:$bf_score";
+ &debug("BF: no SPAM ($bf_comment)");
+ } elsif ($bogofilter_status == 2) {
+ $tag_score .= "BF:-1($bf_score):";
+ $bf_comment = "Unsure, Score:$bf_score";
+ &debug("BF: unsure SPAM ($bf_comment)");
+ } else {
+ $tag_score .= "BF:X(XXX):";
+ $bf_comment = "Error, Score:X";
+ &debug("BF: ERROR ($bf_comment)");
+ }
+ $stop_bogofilter_time=[gettimeofday];
+ $bogofilter_time = tv_interval ($start_bogofilter_time, $stop_bogofilter_time);
+ &debug("BF: finished scan of dir \"$scandir/$file_id\" in $bogofilter_time secs");
+ }
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Qmail-scanner-general mailing list
Qmail-scanner-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qmail-scanner-general