Changeset 52

Show
Ignore:
Timestamp:
23.11.2006 20:43:57 (2 years ago)
Author:
decoder
Message:

Removed all qx calls, added save_execute calls instead.

Files:

Legend:

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

    r50 r52  
    2020 
    2121use lib qw(.); # Allow placing of FuzzyOcr in siteconfigdir 
    22 use FuzzyOcr::Config qw(kill_pid get_pms save_pms get_timeout save_timeout get_ddb get_thresholds get_scansets get_config get_wordlist set_config finish_parsing_end load_global_words load_personal_words debuglog logfile); 
     22use FuzzyOcr::Config qw(kill_pid get_tmpdir set_tmpdir get_pms save_pms get_timeout save_timeout get_ddb get_thresholds get_scansets get_config get_wordlist set_config finish_parsing_end load_global_words load_personal_words debuglog logfile); 
    2323use FuzzyOcr::Hashing qw(check_image_hash_db check_image_hash_db add_image_hash_db calc_image_hash); 
    2424use FuzzyOcr::Deanimate qw(deanimate); 
     
    136136        } 
    137137 
    138         $imgdir = Mail::SpamAssassin::Util::secure_tmpdir() unless ($imgdir); 
     138        $imgdir = Mail::SpamAssassin::Util::secure_tmpdir(); 
     139         
     140        set_tmpdir($imgdir); 
     141 
    139142        unless ($imgdir) { 
    140143            debuglog("Scan canceled, cannot create Image TMPDIR."); 
     
    299302                } 
    300303            } 
    301             my @stdout_data; 
    302304            my @stderr_data; 
    303305 
    304             if ($conf->{focr_global_timeout}) { 
    305                 @stdout_data = qx($conf->{focr_bin_giftext} $file); 
    306             } else { 
    307                 my $t = get_timeout(); 
    308                 my $retcode = $t->run_and_catch(sub { 
    309                     @stdout_data = qx($conf->{focr_bin_giftext} $file); 
    310                 }); 
    311                 if ($retcode) { 
    312                     chomp $retcode; 
    313                     debuglog("$conf->{focr_bin_giftext} Timed out [$retcode], skipping..."); 
    314                     ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    315                 } 
    316             } 
     306            my ($retcode, @stdout_data) = save_execute("$conf->{focr_bin_giftext} $file", ">$imgdir/giftext.info", ">>$imgdir/giftext.err", 1); 
     307 
     308            if ($retcode) { 
     309                chomp $retcode; 
     310                debuglog("$conf->{focr_bin_giftext} Timed out [$retcode], skipping..."); 
     311                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
     312            } 
     313 
    317314            foreach (@stdout_data) { 
    318315                unless ($interlaced_gif) { 
     
    332329                $tfile .= "-fixed.gif"; 
    333330                printf RAWERR "## $conf->{focr_bin_giffix} $file >$tfile 2>>$efile\n" if ($haserr>0); 
    334                 if ($conf->{focr_global_timeout}) { 
    335                     qx($conf->{focr_bin_giffix} $file >$tfile 2>>$efile); 
    336                 } else { 
    337                     my $t = get_timeout(); 
    338                     my $retcode = $t->run_and_catch(sub { 
    339                         qx($conf->{focr_bin_giffix} $file >$tfile 2>>$efile); 
    340                     }); 
    341                     if ($retcode) { 
    342                         chomp $retcode; 
    343                         debuglog("$conf->{focr_bin_giffix}: Timed out [$retcode], skipping..."); 
    344                         printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    345                         ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    346                     } 
    347                 } 
     331                $retcode = save_execute("$conf->{focr_bin_giffix} $file", ">$tfile", ">>$efile"); 
     332 
     333                if ($retcode) { 
     334                    chomp $retcode; 
     335                    debuglog("$conf->{focr_bin_giffix}: Timed out [$retcode], skipping..."); 
     336                    printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
     337                    ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
     338                } 
     339 
    348340                if (open ERR, $efile) { 
    349341                    @stderr_data = <ERR>; 
     
    387379                } 
    388380                printf RAWERR qq(## $conf->{focr_bin_gifinter} $cfile >$tfile 2>>$efile\n) if ($haserr>0); 
    389                 if ($conf->{focr_global_timeout}) { 
    390                     qx($conf->{focr_bin_gifinter} $cfile >$tfile 2>>$efile); 
    391                 } else { 
    392                     my $t = get_timeout(); 
    393                     my $retcode = $t->run_and_catch(sub{ 
    394                         qx($conf->{focr_bin_gifinter} $cfile >$tfile 2>>$efile); 
    395                     }); 
    396                     if ($retcode) { 
    397                         chomp $retcode; 
    398                         printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    399                         debuglog("$conf->{focr_bin_gifinter}: Timed out [$retcode], skipping..."); 
    400                         ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    401                     } 
    402                 } 
    403             } 
    404  
    405             printf RAWERR qq(## $conf->{focr_bin_giftopnm} $tfile >$pfile 2>>$efile\n) if ($haserr>0); 
    406             if ($conf->{focr_global_timeout}) { 
    407                 qx($conf->{focr_bin_giftopnm} $tfile >$pfile 2>>$efile); 
    408             } else { 
    409                 my $t = get_timeout(); 
    410                 my $retcode = $t->run_and_catch(sub { 
    411                     qx($conf->{focr_bin_giftopnm} $tfile >$pfile 2>>$efile); 
    412                 }); 
     381                $retcode = save_execute("$conf->{focr_bin_gifinter} $cfile", ">$tfile", ">>$efile"); 
     382 
    413383                if ($retcode) { 
    414384                    chomp $retcode; 
    415385                    printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    416                     debuglog("$conf->{focr_bin_giftopnm}: Timed out [$retcode], skipping..."); 
     386                    debuglog("$conf->{focr_bin_gifinter}: Timed out [$retcode], skipping..."); 
    417387                    ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    418388                } 
     389            } 
     390 
     391            printf RAWERR qq(## $conf->{focr_bin_giftopnm} $tfile >$pfile 2>>$efile\n) if ($haserr>0); 
     392            $retcode = save_execute("$conf->{focr_bin_giftopnm} $tfile", ">$pfile", ">>$efile"); 
     393 
     394            if ($retcode) { 
     395                chomp $retcode; 
     396                printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
     397                debuglog("$conf->{focr_bin_giftopnm}: Timed out [$retcode], skipping..."); 
     398                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    419399            } 
    420400        } 
     
    440420            } 
    441421            printf RAWERR qq(## $conf->{focr_bin_jpegtopnm} $file >$pfile 2>>$efile\n) if ($haserr>0); 
    442             if ($conf->{focr_global_timeout}) { 
    443                 qx($conf->{focr_bin_jpegtopnm} $file >$pfile 2>>$efile); 
    444             } else { 
    445                 my $t = get_timeout(); 
    446                 my $retcode = $t->run_and_catch(sub { 
    447                     qx($conf->{focr_bin_jpegtopnm} $file >$pfile 2>>$efile); 
    448                 }); 
    449                 if ($retcode) { 
    450                     chomp $retcode; 
    451                     printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    452                     debuglog("$conf->{focr_bin_jpegtopnm}: Timed out [$retcode], skipping..."); 
    453                     ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    454                 } 
     422            $retcode = save_execute("$conf->{focr_bin_jpegtopnm} $file", ">$pfile", ">>$efile"); 
     423 
     424            if ($retcode) { 
     425                chomp $retcode; 
     426                printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
     427                debuglog("$conf->{focr_bin_jpegtopnm}: Timed out [$retcode], skipping..."); 
     428                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    455429            } 
    456430        } 
     
    474448                } 
    475449            } 
     450 
    476451            printf RAWERR qq(## $conf->{focr_bin_pngtopnm} $file >$pfile 2>>$efile\n) if ($haserr>0); 
    477             if ($conf->{focr_global_timeout}) { 
    478                 qx($conf->{focr_bin_pngtopnm} $file >$pfile 2>>$efile); 
    479             } else { 
    480                 my $t = get_timeout(); 
    481                 my $retcode = $t->run_and_catch(sub { 
    482                     qx($conf->{focr_bin_pngtopnm} $file >$pfile 2>>$efile); 
    483                 }); 
    484                 if ($retcode) { 
    485                     chomp $retcode; 
    486                     printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    487                     debuglog("$conf->{focr_bin_pngtopnm}: Timed out [$retcode], skipping..."); 
    488                     ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    489                 } 
     452            $retcode = save_execute("$conf->{focr_bin_pngtopnm} $file", ">$pfile", ">>$efile"); 
     453 
     454            if ($retcode) { 
     455                chomp $retcode; 
     456                printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
     457                debuglog("$conf->{focr_bin_pngtopnm}: Timed out [$retcode], skipping..."); 
     458                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    490459            } 
    491460        } 
     
    510479            } 
    511480            printf RAWERR qq(## $conf->{focr_bin_bmptopnm} $file >$pfile 2>>$efile\n) if ($haserr>0); 
    512             if ($conf->{focr_global_timeout}) { 
    513                 qx($conf->{"focr_bin_bmptopnm"} $file >$pfile 2>>$efile); 
    514             } else { 
    515                 my $t = get_timeout(); 
    516                 my $retcode = $t->run_and_catch(sub { 
    517                     qx($conf->{"focr_bin_bmptopnm"} $file >$pfile 2>>$efile); 
    518                 }); 
    519                 if ($retcode) { 
    520                     chomp $retcode; 
    521                     printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    522                     debuglog("$conf->{focr_bin_bmptopnm}: Timed out [$retcode], skipping..."); 
    523                     ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    524                 } 
     481 
     482            $retcode = save_execute("$conf->{focr_bin_bmptopnm} $file", ">$pfile", ">>$efile"); 
     483            if ($retcode) { 
     484                chomp $retcode; 
     485                printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
     486                debuglog("$conf->{focr_bin_bmptopnm}: Timed out [$retcode], skipping..."); 
     487                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    525488            } 
    526489        } 
     
    546509            } 
    547510            printf RAWERR qq(## $conf->{focr_bin_tifftopnm} $file >$pfile 2>>$efile\n) if ($haserr>0); 
    548             if ($conf->{focr_global_timeout}) { 
    549                 qx($conf->{'focr_bin_tifftopnm'} $file >$pfile 2>>$efile); 
    550             } else { 
    551                 my $t = get_timeout(); 
    552                 my $retcode = $t->run_and_catch(sub { 
    553                     qx($conf->{'focr_bin_tifftopnm'} $file >$pfile 2>>$efile); 
    554                 }); 
    555                 if ($retcode) { 
    556                     chomp $retcode; 
    557                     printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
    558                     debuglog("$conf->{focr_bin_tifftopnm}: Timed out [$retcode], skipping..."); 
    559                     ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    560                 } 
     511            $retcode = save_execute("$conf->{focr_bin_tifftopnm} $file", ">$pfile", ">>$efile"); 
     512 
     513            if ($retcode) { 
     514                chomp $retcode; 
     515                printf RAWERR "?? Timed out > $retcode\n" if ($haserr>0); 
     516                debuglog("$conf->{focr_bin_tifftopnm}: Timed out [$retcode], skipping..."); 
     517                ++$imgerr if $conf->{focr_keep_bad_images}>0; next; 
    561518            } 
    562519        } 
     
    611568            my @ocrdata; 
    612569            printf RAWERR qq(## $scan 2>>$efile\n) if ($haserr>0); 
    613             if ($conf->{focr_global_timeout}) { 
    614                 @ocrdata = qx($scan 2>>$efile); 
    615             } else { 
    616                 my $t = get_timeout(); 
    617                 my $retcode = $t->run_and_catch(sub { 
    618                     @ocrdata = qx($scan 2>>$efile); 
    619                 }); 
    620                 if ($retcode) { 
    621                     chomp $retcode; 
    622                     open ERR,$efile; 
    623                     my @stderr = <ERR>; 
    624                     close ERR; 
    625                     my $errstr = join( '', $retcode,@stderr ); 
    626                     debuglog($errstr); 
    627                     printf RAWERR qq($errstr\n) if ($haserr>0); 
    628                     debuglog("Skipping scanset \"$scanset\" because of errors, trying next..."); 
    629                     next; 
    630                 } 
    631             } 
     570 
     571            ($retcode, @ocrdata) = save_execute("$scan", ">$imgdir/ocr.temp", ">>$efile"); 
     572            if ($retcode) { 
     573                chomp $retcode; 
     574                open ERR,$efile; 
     575                my @stderr = <ERR>; 
     576                close ERR; 
     577                my $errstr = join( '', $retcode,@stderr ); 
     578                debuglog($errstr); 
     579                printf RAWERR qq($errstr\n) if ($haserr>0); 
     580                debuglog("Skipping scanset \"$scanset\" because of errors, trying next..."); 
     581                next; 
     582            } 
     583 
    632584            debuglog("ocrdata=>>".join("",@ocrdata)."<<=end") 
    633585                if ($conf->{focr_verbose} > 2);