Changeset 67
- Timestamp:
- 29.11.2006 23:38:33 (2 years ago)
- Files:
-
- trunk/devel/FuzzyOcr.cf (modified) (1 diff)
- trunk/devel/FuzzyOcr.pm (modified) (6 diffs)
- trunk/devel/FuzzyOcr/Config.pm (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/devel/FuzzyOcr.cf
r65 r67 179 179 #focr_score_ham 1 180 180 ###################################################################### 181 182 # DO NOT REMOVE THIS LINE, IT IS REQUIRED UNDER ALL CIRCUMSTANCES 183 focr_end_config trunk/devel/FuzzyOcr.pm
r65 r67 21 21 use lib qw(. /etc/mail/spamassassin); # Allow placing of FuzzyOcr in siteconfigdir 22 22 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);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 parse_config load_global_words load_personal_words debuglog logfile); 24 24 use FuzzyOcr::Hashing qw(check_image_hash_db check_image_hash_db add_image_hash_db calc_image_hash); 25 25 use FuzzyOcr::Deanimate qw(deanimate); … … 57 57 debuglog("Global Timeout set at ".$conf->{focr_timeout}." sec."); 58 58 $t->run(sub { 59 $end = fuzzyocr_do( $ conf, $pms );59 $end = fuzzyocr_do( $self, $conf, $pms ); 60 60 }); 61 61 if ($t->timed_out()) { … … 73 73 } 74 74 } else { 75 $end = fuzzyocr_do( $ conf, $pms );75 $end = fuzzyocr_do( $self, $conf, $pms ); 76 76 } 77 77 debuglog("Processed in ". … … 82 82 83 83 sub fuzzyocr_do { 84 my ( $ conf, $pms ) = @_;85 84 my ( $self, $conf, $pms ) = @_; 85 86 86 if ( $pms->get_score() > $conf->{focr_autodisable_score} ) { 87 87 debuglog("Scan canceled, message has already more than $conf->{focr_autodisable_score} points."); … … 101 101 my $cnt = 0; 102 102 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..."); 106 107 if ($conf->{focr_personal_wordlist} =~ m/^\//) { 107 108 load_personal_words( $conf->{focr_personal_wordlist} ); 108 109 } 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); 117 115 } 118 116 … … 339 337 $tfile .= "-fixed.gif"; 340 338 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"); 343 341 344 342 if ($retcode<0) { # only care if we timed out trunk/devel/FuzzyOcr/Config.pm
r65 r67 26 26 get_ddb 27 27 finish_parsing_end 28 parse_config 28 29 load_global_words 29 30 load_personal_words … … 246 247 push (@cmds, { 247 248 setting => 'focr_digest_db', 248 default => " __userstate__/FuzzyOcr.hashdb",249 default => "/etc/mail/spamassassin/FuzzyOcr.hashdb", 249 250 type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 250 251 }); … … 264 265 push (@cmds, { 265 266 setting => 'focr_db_hash', 266 default => " __userstate__/FuzzyOcr.db",267 default => "/etc/mail/spamassassin/FuzzyOcr.db", 267 268 type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 268 269 }); … … 270 271 push (@cmds, { 271 272 setting => 'focr_db_safe', 272 default => " __userstate__/FuzzyOcr.safe.db",273 default => "/etc/mail/spamassassin/FuzzyOcr.safe.db", 273 274 type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 274 275 }); … … 370 371 push (@cmds, { 371 372 setting => 'focr_scanset_file', 372 default => '/etc/mail/spamassassin/FuzzyOcr.scansets',373 default => "/etc/mail/spamassassin/FuzzyOcr.scansets", 373 374 type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 374 375 }); 375 376 push (@cmds, { 376 377 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 380 382 push (@cmds, { 381 383 setting => 'focr_minimal_scanset', … … 443 445 444 446 $conf->{parser}->register_commands(\@cmds); 447 } 448 449 sub 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; 445 473 } 446 474 … … 477 505 debuglog(" $k => ".$conf->{$k}); 478 506 } 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 486 508 foreach my $prep (@preprocessors) { 487 509 my $prepcmd = $prep->{command}; … … 490 512 } 491 513 492 # Parse scanset file493 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 }499 514 foreach my $scan (@scansets) { 500 515 my $scancmd = $scan->{ocr_command}; … … 723 738 my ($file) = @_; 724 739 725 open(SFILE, "<$file"); 726 if ($?) { 740 unless (open(SFILE, "<$file")) { 727 741 debuglog("Failed to open scanset file \"$file\", aborting..."); 728 742 return 1; … … 792 806 my ($file) = @_; 793 807 794 open(PFILE, "<$file"); 795 if ($?) { 808 unless (open(PFILE, "<$file")) { 796 809 debuglog("Failed to open preprocessor file \"$file\", aborting..."); 797 810 return 1;
