Changeset 67

Show
Ignore:
Timestamp:
29.11.2006 23:38:33 (2 years ago)
Author:
decoder
Message:

Added focr_end_config (last line in FuzzyOcr?.cf) to allow spamassassin --lint to fail when scanset/preprocessor parsing fails
Removed userstate from configs, except from personal wordlist, and fixed personal wordlist loading mechanism

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/devel/FuzzyOcr.cf

    r65 r67  
    179179#focr_score_ham 1 
    180180###################################################################### 
     181 
     182# DO NOT REMOVE THIS LINE, IT IS REQUIRED UNDER ALL CIRCUMSTANCES 
     183focr_end_config 
  • trunk/devel/FuzzyOcr.pm

    r65 r67  
    2121use lib qw(. /etc/mail/spamassassin); # Allow placing of FuzzyOcr in siteconfigdir 
    2222 
    23 use FuzzyOcr::Config qw(kill_pid get_tmpdir set_tmpdir get_pms save_pms get_timeout get_ddb get_thresholds get_scansets get_config get_wordlist set_config finish_parsing_end load_global_words load_personal_words debuglog logfile); 
     23use FuzzyOcr::Config qw(kill_pid get_tmpdir set_tmpdir get_pms save_pms get_timeout get_ddb get_thresholds get_scansets get_config get_wordlist set_config finish_parsing_end parse_config load_global_words load_personal_words debuglog logfile); 
    2424use FuzzyOcr::Hashing qw(check_image_hash_db check_image_hash_db add_image_hash_db calc_image_hash); 
    2525use FuzzyOcr::Deanimate qw(deanimate); 
     
    5757        debuglog("Global Timeout set at ".$conf->{focr_timeout}." sec."); 
    5858        $t->run(sub { 
    59             $end = fuzzyocr_do( $conf, $pms ); 
     59            $end = fuzzyocr_do( $self, $conf, $pms ); 
    6060        }); 
    6161        if ($t->timed_out()) { 
     
    7373        } 
    7474    } else { 
    75         $end = fuzzyocr_do( $conf, $pms ); 
     75        $end = fuzzyocr_do( $self, $conf, $pms ); 
    7676    } 
    7777    debuglog("Processed in ". 
     
    8282 
    8383sub fuzzyocr_do { 
    84     my ( $conf, $pms ) = @_; 
    85      
     84    my ( $self, $conf, $pms ) = @_; 
     85 
    8686    if ( $pms->get_score() > $conf->{focr_autodisable_score} ) { 
    8787        debuglog("Scan canceled, message has already more than $conf->{focr_autodisable_score} points."); 
     
    101101    my $cnt      = 0; 
    102102    my $imgerr   = 0; 
    103  
    104     #debuglog("Starting FuzzyOcr..."); 
    105     #debuglog("Attempting to load personal wordlist..."); 
     103    my $main = $self->{main}; 
     104 
     105    debuglog("Starting FuzzyOcr..."); 
     106    debuglog("Attempting to load personal wordlist..."); 
    106107    if ($conf->{focr_personal_wordlist} =~ m/^\//) { 
    107108        load_personal_words( $conf->{focr_personal_wordlist} ); 
    108109    } else { 
    109         my $homedir  = (getpwuid($<))[7]; 
    110         if ($homedir) { 
    111             load_personal_words( $homedir . "/$conf->{focr_personal_wordlist}" ); 
    112         } elsif (defined($ENV{HOME})) { 
    113             load_personal_words( $ENV{HOME} . "/$conf->{focr_personal_wordlist}" ); 
    114         } else { 
    115             debuglog("Variable \$ENV{HOME} not defined and getpwuid failed, personal wordlist function not available..."); 
    116         } 
     110        my $peruserlist  = $main->sed_path($conf->{focr_personal_wordlist}); 
     111        unless ($peruserlist) { 
     112            debuglog("Error getting personal wordlist, skipping..."); 
     113        } 
     114        load_personal_words($peruserlist); 
    117115    } 
    118116 
     
    339337                $tfile .= "-fixed.gif"; 
    340338                printf RAWERR "## $conf->{focr_bin_giffix} $file >$tfile 2>>$efile\n" if ($haserr>0); 
    341                  
    342                $retcode = save_execute("$conf->{focr_bin_giffix} $file", undef, ">$tfile", ">>$efile"); 
     339 
     340                $retcode = save_execute("$conf->{focr_bin_giffix} $file", undef, ">$tfile", ">>$efile"); 
    343341 
    344342                if ($retcode<0) { # only care if we timed out 
  • trunk/devel/FuzzyOcr/Config.pm

    r65 r67  
    2626    get_ddb 
    2727    finish_parsing_end  
     28    parse_config  
    2829    load_global_words  
    2930    load_personal_words  
     
    246247    push (@cmds, { 
    247248        setting => 'focr_digest_db', 
    248         default => "__userstate__/FuzzyOcr.hashdb", 
     249        default => "/etc/mail/spamassassin/FuzzyOcr.hashdb", 
    249250        type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 
    250251       }); 
     
    264265    push (@cmds, { 
    265266        setting => 'focr_db_hash', 
    266         default => "__userstate__/FuzzyOcr.db", 
     267        default => "/etc/mail/spamassassin/FuzzyOcr.db", 
    267268        type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 
    268269       }); 
     
    270271    push (@cmds, { 
    271272        setting => 'focr_db_safe', 
    272         default => "__userstate__/FuzzyOcr.safe.db", 
     273        default => "/etc/mail/spamassassin/FuzzyOcr.safe.db", 
    273274        type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 
    274275       }); 
     
    370371    push (@cmds, { 
    371372        setting => 'focr_scanset_file', 
    372         default => '/etc/mail/spamassassin/FuzzyOcr.scansets'
     373        default => "/etc/mail/spamassassin/FuzzyOcr.scansets"
    373374        type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 
    374375        }); 
    375376    push (@cmds, { 
    376377        setting => 'focr_preprocessor_file', 
    377         default => '/etc/mail/spamassassin/FuzzyOcr.preps', 
    378         type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 
    379         }); 
     378        default => "/etc/mail/spamassassin/FuzzyOcr.preps", 
     379        type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 
     380        }); 
     381 
    380382    push (@cmds, { 
    381383            setting => 'focr_minimal_scanset', 
     
    443445 
    444446    $conf->{parser}->register_commands(\@cmds); 
     447} 
     448 
     449sub parse_config { 
     450    my ($self, $opts) = @_; 
     451    if ($opts->{key} eq 'focr_end_config') { 
     452        $conf = $opts->{conf}; 
     453        # Parse preprocessor file 
     454        my $pfile = $conf->{'focr_preprocessor_file'}; 
     455        debuglog("Starting preprocessor parser for file \"$pfile\"..."); 
     456        (my $retcode, @preprocessors) = parse_preprocessors($pfile); 
     457        if ($retcode) { 
     458            warn("Error parsing preprocessor file \"$pfile\", aborting..."); 
     459            return 0; 
     460        } 
     461 
     462        # Parse scanset file 
     463        my $sfile = $conf->{'focr_scanset_file'}; 
     464        debuglog("Starting scanset parser for file \"$sfile\"..."); 
     465        ($retcode, @scansets) = parse_scansets($sfile); 
     466        if ($retcode) { 
     467            warn("Error parsing scanset file \"$sfile\", aborting..."); 
     468            return 0; 
     469        } 
     470        return 1; 
     471    } 
     472    return 0; 
    445473} 
    446474 
     
    477505        debuglog(" $k => ".$conf->{$k}); 
    478506    } 
    479     # Parse preprocessor file 
    480     my $pfile = $conf->{'focr_preprocessor_file'}; 
    481     (my $retcode, @preprocessors) = parse_preprocessors($pfile); 
    482     if ($retcode) { 
    483         debuglog("Error parsing preprocessor file \"$pfile\", aborting..."); 
    484         return 1; 
    485     } 
     507 
    486508    foreach my $prep (@preprocessors) { 
    487509        my $prepcmd = $prep->{command}; 
     
    490512    } 
    491513 
    492     # Parse scanset file 
    493     my $sfile = $conf->{'focr_scanset_file'}; 
    494     ($retcode, @scansets) = parse_scansets($sfile); 
    495     if ($retcode) { 
    496         debuglog("Error parsing scanset file \"$sfile\", aborting..."); 
    497         return 1; 
    498     } 
    499514    foreach my $scan (@scansets) { 
    500515        my $scancmd = $scan->{ocr_command}; 
     
    723738    my ($file) = @_; 
    724739 
    725     open(SFILE, "<$file"); 
    726     if ($?) { 
     740    unless (open(SFILE, "<$file")) { 
    727741        debuglog("Failed to open scanset file \"$file\", aborting..."); 
    728742        return 1; 
     
    792806    my ($file) = @_; 
    793807 
    794     open(PFILE, "<$file"); 
    795     if ($?) { 
     808    unless (open(PFILE, "<$file")) { 
    796809        debuglog("Failed to open preprocessor file \"$file\", aborting..."); 
    797810        return 1;