F:\WEBSITES\testbed\zipped\yabb_svn_new\branches\2.5.2\cgi-bin\yabb2\Sources\SpamCheck.pl F:\WEBSITES\testbed\zipped\yabb_svn_new\trunk\cgi-bin\yabb2\Sources\SpamCheck.pm
############################################################################### ###############################################################################
# SpamCheck.pl                                                                # # SpamCheck.pm                                                                #
  # $Date: 01.05.16 $                                                           #
############################################################################### ###############################################################################
# YaBB: Yet another Bulletin Board                                            # # YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               # # Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2.5.2                                                  # # Version:        YaBB 2.6.12                                                 #
# Packaged:       October 21, 2012                                            # # Packaged:       January 5, 2016                                             #
# Distributed by: http://www.yabbforum.com                                    # # Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== # # =========================================================================== #
# Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved.     # # Copyright (c) 2000-2016 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by:  The YaBB Development Team                                     # # Software by:  The YaBB Development Team                                     #
#               with assistance from the YaBB community.                      # #               with assistance from the YaBB community.                      #
############################################################################### ###############################################################################
  our $VERSION = '2.6.12';
   
$spamcheckplver = 'YaBB 2.5.2 $Revision: 1.0 $'; $spamcheckpmver = 'YaBB 2.6.12 $Revision: 1651 $';
if ($action eq 'detailedversion') { return 1; } if ( $action eq 'detailedversion' ) { return 1; }
   
sub spamcheck { sub spamcheck {
   my ($rawcontent) = $_[0];     my ($rawcontent) = @_; 
   $rawcontent =~ s/[\r\n\t]/ /g;                #convert cr/lf/tab to space    $rawcontent =~ s/[\r\n\t]/ /gxsm;        #convert cr/lf/tab to space
   $rawcontent =~ s/\[(.*?){1,2}\]//g;            # rip out all make up yabb tags if it is a non yabbc message which can be uses to break and obscure words     $rawcontent =~ s/\[(.*?){1,2}\]//gxsm; 
   $rawcontent =~ s/\<(.*?){1,2}\>//g;            # rip out all make up html tags if it is a html message which can be uses to break and obscure words  
   my $testcontent = lc(" $rawcontent");            #add a leading space to trace start of the very first word and make it lowercase  # rip out all make up yabb tags if it is a non yabbc message which can be used to break and obscure words 
   my ($spamline,$spamcnt,$searchtype);     $rawcontent =~ s/\<(.*?){1,2}\>//gxsm; 
   if (-e "$vardir/spamrules.txt" ) {  
       fopen(SPAM, "$vardir/spamrules.txt") || &fatal_error("cannot_open","spamrules.txt", 1);  # rip out all make up html tags if it is a html message which can be used to break and obscure words 
       while ($buffer = <SPAM>) {     my $testcontent = lc " $rawcontent"; 
           chomp $buffer;  
           $spamline = "";  #add a leading space to trace start of the very first word and make it lowercase 
           if ($buffer =~ m/\~\;/) {     my ( $spamline, $spamcnt, $searchtype ); 
               ($spamcnt,$spamline) = split(/\~\;/, $buffer);     if ( -e "$vardir/spamrules.txt" ) { 
               $searchtype = "S";         fopen( SPAM, "$vardir/spamrules.txt" ) 
           } elsif ($buffer =~ m/\=\;/) {           or fatal_error( 'cannot_open', 'spamrules.txt', 1 ); 
               ($spamcnt,$spamline) = split(/\=\;/, $buffer);         while ( $buffer = <SPAM> ) { 
               $searchtype = "E";             chomp $buffer; 
           } else {             $spamline = q{}; 
               if ($buffer ne ""){             if ( $buffer =~ m/\~\;/xsm ) { 
                   $spamline = $buffer;                ( $spamcnt, $spamline ) = split /\~\;/xsm, $buffer;
                   $spamcnt = 0;                 $searchtype = 'S'; 
                   $searchtype = "S";             } 
               }             elsif ( $buffer =~ m/\=\;/xsm ) { 
           }                 ( $spamcnt, $spamline ) = split /\=\;/xsm, $buffer; 
           if(!$spamcnt){ $spamcnt = 0;}                 $searchtype = 'E'; 
           if($spamline ne ""){ push(@spamlines, [$spamline, $spamcnt, $searchtype]); }            }
       }             else { 
       fclose(SPAM);                 if ( $buffer ne q{} ) { 
   }                     $spamline   = $buffer; 
                     $spamcnt    = 0;
   for $spamrule (@spamlines) {                     $searchtype = 'S'; 
       chomp $spamrule;                 } 
       $is_spam = 0;             } 
       ($spamword,$spamlimit,$spamtype) = @{$spamrule};             if ( !$spamcnt ) { $spamcnt = 0; } 
       if ($spamtype eq "S" ) {            if ( $spamline ne q{} ) {
           @spamcount = $testcontent =~ /$spamword/gsi;                 push @spamlines, [ $spamline, $spamcnt, $searchtype ]; 
       } elsif ($spamtype eq "E" ) {             } 
           @spamcount = $testcontent =~ /\b$spamword\b/gsi;         } 
       }         fclose(SPAM); 
       $spamcounter = $#spamcount + 1;     } 
       if ($spamcounter > $spamlimit){  
           $is_spam = 1;     for my $spamrule (@spamlines) { 
           last;         chomp $spamrule; 
       }         $is_spam = 0; 
   }         ( $spamword, $spamlimit, $spamtype ) = @{$spamrule}; 
#   &fatal_error("error_occurred","$testcontent|$is_spam|$spamword|$spamcount|$spamtype");         if ( $spamtype eq 'S' ) { 
   return $is_spam;             @spamcount = $testcontent =~ /$spamword/igxsm; 
   return $spamword;         } 
         elsif ( $spamtype eq 'E' ) {
             @spamcount = $testcontent =~ /\b$spamword\b/igxsm;
         }
         $spamcounter = $#spamcount + 1;
         if ( $spamcounter > $spamlimit ) {
             $is_spam = 1;
             last;
         }
     }
     return ( $is_spam, $spamword );
} }
   
1; 1;