Changeset 58
- Timestamp:
- 25.11.2006 00:37:28 (2 years ago)
- Files:
-
- trunk/devel/FuzzyOcr.cf (modified) (1 diff)
- trunk/devel/FuzzyOcr.pm (modified) (7 diffs)
- trunk/devel/FuzzyOcr/Config.pm (modified) (6 diffs)
- trunk/devel/FuzzyOcr/Hashing.pm (modified) (2 diffs)
- trunk/devel/FuzzyOcr/Misc.pm (modified) (5 diffs)
- trunk/devel/INSTALL (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/devel/FuzzyOcr.cf
r55 r58 16 16 # Verbosity level (see manual) Attention: Don't set to 0, but to 0.0 for quiet operation. (Default value: 1) 17 17 #focr_verbose 2 18 # 19 # When focr_verbose>1 you can log to stderr by setting this variable to 1 (Default value: 0) 20 #focr_log_stderr 1 18 21 # 19 22 # Logfile (make sure it is writable by the plugin) (Default value: /etc/mail/spamassassin/FuzzyOcr.log) trunk/devel/FuzzyOcr.pm
r57 r58 19 19 use Fcntl ':flock'; 20 20 21 use lib qw(.); # Allow placing of FuzzyOcr in siteconfigdir 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 24 use FuzzyOcr::Hashing qw(check_image_hash_db check_image_hash_db add_image_hash_db calc_image_hash); … … 93 94 } 94 95 96 my $ddb; 95 97 my $imgdir; 96 98 my %imgfiles = (); … … 113 115 debuglog("Variable \$ENV{HOME} not defined and getpwuid failed, personal wordlist function not available..."); 114 116 } 115 }116 if ($conf->{focr_enable_image_hashing} == 3) {117 $conf->{focr_ddb} = get_ddb();118 117 } 119 118 … … 266 265 } 267 266 debuglog("Found: $cnt images"); $cnt = 0; 267 if ($conf->{focr_enable_image_hashing} == 3) { 268 $ddb = $conf->{focr_ddb} = get_ddb(); 269 } 268 270 269 271 my $haserr = open RAWERR, ">$imgdir/raw.err"; … … 602 604 $scan =~ s/\$efile/$efile/g; 603 605 #unlink $efile if (-e $efile); 604 debuglog("Trying: $scanset");606 #debuglog("Trying: $scanset"); 605 607 printf RAWERR qq(## $scan 2>>$efile\n) if ($haserr>0); 606 608 … … 707 709 } 708 710 if ( $conf->{focr_verbose} > 0 and $conf->{focr_verbose} < 3 ) { 709 debuglog($debuginfo) ;711 debuglog($debuginfo) unless ($conf->{focr_enable_image_hashing} == 3); 710 712 } 711 713 for my $set ( 0 .. 3 ) { … … 719 721 } 720 722 if ($conf->{focr_enable_image_hashing} == 3) { 721 $ conf->{focr_ddb}->disconnect;723 $ddb->disconnect; 722 724 } 723 725 debuglog("FuzzyOcr ending successfully..."); trunk/devel/FuzzyOcr/Config.pm
r55 r58 134 134 sub get_ddb { 135 135 return undef unless (HAS_DBI and HAS_DBD_MYSQL); 136 use DBI; 136 137 my $conf = get_config(); 137 138 my %dopts = ( AutoCommit => 1 ); … … 197 198 setting => 'focr_logfile', 198 199 type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 200 }); 201 202 push (@cmds, { 203 setting => 'focr_log_stderr', 204 default => 0, 205 type => $Mail::SpamAssassin::Conf::CONF_TYPE_BOOL 199 206 }); 200 207 … … 406 413 $conf = $opts->{conf}; 407 414 415 #add_facilities('FuzzyOcr'); 408 416 # find external binaries 409 417 @paths = split(/:/, $conf->{'focr_path_bin'}); … … 521 529 } 522 530 if ($conf->{focr_enable_image_hashing} == 3) { 523 my $ddb = $conf->{focr_ddb} =get_ddb();531 my $ddb = get_ddb(); 524 532 if (defined $ddb) { 525 533 my $db = $conf->{focr_mysql_db}; … … 594 602 debuglog("Stored [$err] Hashes in $db.$tab") if $err>0; 595 603 } 596 $conf->{focr_ddb}->disconnect; 597 delete $conf->{focr_ddb}; 604 $ddb->disconnect; 598 605 debuglog("done updating MySQL database"); 599 606 } … … 685 692 my @lines = split('\n',$_[0]); 686 693 my $limit = defined $_[1] ? $_[1] : 1; 687 foreach (@lines) { dbg ("FuzzyOcr: $_"); }688 694 if ( $conf->{focr_verbose} > $limit ) { 689 695 logfile($_[0]) if defined $conf->{focr_logfile}; 696 if ($conf->{focr_log_stderr}) { 697 foreach (@lines) { info ("FuzzyOcr: $_"); } 698 } 699 } else { 700 foreach (@lines) { dbg ("FuzzyOcr: $_"); } 690 701 } 691 702 } trunk/devel/FuzzyOcr/Hashing.pm
r57 r58 121 121 # Expire old records... 122 122 $sql = qq(delete from $db.$dbfile where $dbfile.check < $then); 123 debuglog($sql );123 debuglog($sql,2); 124 124 $ddb->do($sql); 125 125 } … … 130 130 debuglog("Matched [$next] time(s). Prev match: ".fmt_time($now - $when)); 131 131 $sql = qq(update $db.$dbfile set $dbfile.match='$next',$dbfile.check='$now' where $dbfile.key='$key'); 132 debuglog($sql );132 debuglog($sql,2); 133 133 $ddb->do($sql); 134 134 } trunk/devel/FuzzyOcr/Misc.pm
r57 r58 43 43 my $t = get_timeout(); 44 44 my ($cmd, $stdout, $stderr, $return_stdout) = @_; 45 my ($pgm,undef) = split(' ',$cmd,2); 45 46 $stdout = '>/dev/null' unless $stdout; 46 47 $stderr = '>/dev/null' unless $stderr; 47 48 my $retcode; 48 49 if ($conf->{'focr_global_timeout'}) { 50 my $begin = [gettimeofday]; 49 51 my $pid = fork(); 50 52 if (not defined $pid) { … … 52 54 return -1; 53 55 } elsif (not $pid) { 56 debuglog("Exec: $cmd $stdout $stderr",2); 54 57 open(STDOUT, $stdout); 55 58 open(STDERR, $stderr); … … 58 61 } else { 59 62 set_pid($pid); 60 wait(); 61 $retcode = $?; 63 wait(); $retcode = $?; 64 debuglog("Elapsed: ". 65 sprintf ("%.6f",tv_interval($begin, [gettimeofday])) 66 ." sec. ($pgm)"); 62 67 unset_pid(); 63 68 if ($return_stdout and $stdout !~ m,/dev/null,i) { … … 80 85 return -1; 81 86 } elsif (not $pid) { 82 debuglog("Exec: $cmd $stdout $stderr" );87 debuglog("Exec: $cmd $stdout $stderr",2); 83 88 open(STDOUT, $stdout); 84 89 open(STDERR, $stderr); … … 90 95 debuglog("Elapsed: ". 91 96 sprintf ("%.6f",tv_interval($begin, [gettimeofday])) 92 ." sec. ($ cmd)");97 ." sec. ($pgm)"); 93 98 unset_pid(); 94 99 if ($return_stdout and $stdout !~ m,/dev/null,i) { trunk/devel/INSTALL
r49 r58 57 57 focr_max_size_<img_type> <max-size> 58 58 59 where <img_type> is one of the following: 59 where <max-size> is expressed in bytes (compared to the pnm 60 filesize), and <img_type> is one of the following: 60 61 61 62 - gif
