Changeset 108

Show
Ignore:
Timestamp:
11.12.2006 17:38:57 (2 years ago)
Author:
jorge
Message:

Added: Option to not log PMS(msgid,from,to) These are logged in spamd.
Change: Automatically skip images with width < 4 pixels (tall images)
Change: Automatically skip images with height < 4 pixels (flat images)
Fixed: Handling of BMP images (wrongly decoded)
Fixed: Exiting subroutine via next at FuzzyOcr?.pm line 689.

Files:

Legend:

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

    r107 r108  
    3333# Default value: 1 
    3434#focr_verbose 3 
     35 
     36# Log Message-Id, From, To 
     37# Default: 1 
     38#focr_log_pmsinfo 0 
    3539 
    3640# Send logging output to stderr. 
  • trunk/devel/FuzzyOcr.pm

    r104 r108  
    125125    my $main     = $self->{main}; 
    126126 
    127     my $from = $pms->get('From') ? $pms->get('From') : "<no sender>"; 
    128     my $to = $pms->get('To') ? $pms->get('To') : "<no receipients>"; 
    129     my $msgid = $pms->get('Message-Id') ? $pms->get('Message-Id') : "<no messageid>"; 
    130  
    131     chomp($from, $to, $msgid); 
    132  
    133127    debuglog("Starting FuzzyOcr..."); 
    134     infolog("Processing Message with ID \"$msgid\" ($from -> $to)"); 
     128     
     129    #Show PMS info if asked to 
     130    unless ($conf->{focr_log_pmsinfo}) { 
     131        my $msgid = $pms->get('Message-Id') ? $pms->get('Message-Id') : "<no messageid>"; 
     132        my $from = $pms->get('From') ? $pms->get('From') : "<no sender>"; 
     133        my $to = $pms->get('To') ? $pms->get('To') : "<no receipients>"; 
     134        chomp($from, $to, $msgid); 
     135        infolog("Processing Message with ID \"$msgid\" ($from -> $to)"); 
     136    } 
     137 
    135138    foreach my $p ( 
    136139        $pms->{msg}->find_parts(qr(^image\b)i), 
     
    152155        my $w = 0; my $h = 0; 
    153156 
    154         my $blah = substr($pdata,0,3); 
    155  
    156157        if ( substr($pdata,0,3) eq "\x47\x49\x46" ) { 
    157158            ## GIF File 
    158159            $imgfiles{$filename}{ftype} = 1;  
    159160            ($w,$h) = unpack("vv",substr($pdata,6,4)); 
    160             infolog("GIF: [${h}x${w}] $filename"); 
     161            infolog("GIF: [${h}x${w}] $filename ($pdatalen)"); 
    161162            $imgfiles{$filename}{width}  = $w; 
    162163            $imgfiles{$filename}{height} = $h; 
     
    185186            } else { 
    186187                ($h,$w) = unpack("nn",substr($pdata,$pos+3,4)); 
    187                 infolog("JPEG: [${h}x${w}] $filename"); 
     188                infolog("JPEG: [${h}x${w}] $filename ($pdatalen)"); 
    188189                $imgfiles{$filename}{ftype} = 2; 
    189190                $imgfiles{$filename}{height} = $h; 
     
    196197            $imgfiles{$filename}{width}  = $w; 
    197198            $imgfiles{$filename}{height} = $h; 
    198             infolog("PNG: [${h}x${w}] $filename"); 
     199            infolog("PNG: [${h}x${w}] $filename ($pdatalen)"); 
    199200        } elsif ( substr($pdata,0,2) eq "BM" ) { 
    200201            ## BMP File 
    201             ($w,$h) = unpack("NN",substr($pdata,18,8)); 
     202            ($w,$h) = unpack("VV",substr($pdata,18,8)); 
    202203            $imgfiles{$filename}{ftype}  = 4; 
    203204            $imgfiles{$filename}{width}  = $w; 
    204205            $imgfiles{$filename}{height} = $h; 
    205             infolog("BMP: [${h}x${w}] $filename"); 
     206            infolog("BMP: [${h}x${w}] $filename ($pdatalen)"); 
    206207        } elsif ( 
    207208            ## TIFF File 
     
    219220                last if ($h != 0 and $w != 0); 
    220221            } 
    221             infolog("TIFF: [${h}x${w}] $filename ($worder)"); 
     222            infolog("TIFF: [${h}x${w}] $filename ($pdatalen) ($worder)"); 
    222223            infolog("Cannot determine size of TIFF image, setting to '1x1'") if ($h == 0 and $w == 0); 
    223224            $imgfiles{$filename}{ftype}  = 5; 
     
    231232            delete $imgfiles{$filename}; 
    232233            next; 
    233  
     234        } 
     235 
     236        #Skip images that cannot contain text 
     237        if ($imgfiles{$filename}{height} < 4) { 
     238            infolog("Skipping narrow image"); 
     239            delete $imgfiles{$filename}; 
     240            next; 
     241        } 
     242 
     243        #Skip images that cannot contain text 
     244        if ($imgfiles{$filename}{width} < 4) { 
     245            infolog("Skipping flat image"); 
     246            delete $imgfiles{$filename}; 
     247            next; 
    234248        } 
    235249 
     
    309323    } 
    310324 
    311     IMAGE: 
    312325    my $haserr; 
    313326    foreach my $filename (keys %imgfiles) { 
     
    352365            if ($conf->{focr_skip_gif}) { 
    353366                infolog("Skipping image check"); 
    354                 next IMAGE
     367                next
    355368            } 
    356369            if (defined($conf->{focr_max_size_gif}) and ($$pic{fsize} > $conf->{focr_max_size_gif})) { 
     
    375388                unless (defined $conf->{"focr_bin_$a"}) { 
    376389                    errorlog("Cannot exec $a, skipping image"); 
    377                     next IMAGE; 
    378                 } 
    379             } 
     390                    next; 
     391                } 
     392            } 
     393 
    380394            my @stderr_data; 
    381  
    382395            my ($retcode, @stdout_data) = save_execute( 
    383396                "$conf->{focr_bin_giftext} $file", 
     
    504517            if ($conf->{focr_skip_jpeg}) { 
    505518                infolog("Skipping image check"); 
    506                 next IMAGE
     519                next
    507520            } 
    508521 
     
    524537                unless (defined $conf->{"focr_bin_$a"}) { 
    525538                    errorlog("Cannot exec $a, skipping image"); 
    526                     next IMAGE
     539                    next
    527540                } 
    528541            } 
     
    546559            if ($conf->{focr_skip_png}) { 
    547560                infolog("Skipping image check"); 
    548                 next IMAGE
     561                next
    549562            } 
    550563            if (defined($conf->{focr_max_size_png}) and ($$pic{fsize} > $conf->{focr__max_size_png})) { 
     
    563576                unless (defined $conf->{"focr_bin_$a"}) { 
    564577                    errorlog("Cannot exec $a, skipping image"); 
    565                     next IMAGE
     578                    next
    566579                } 
    567580            } 
     
    586599            if ($conf->{focr_skip_bmp}) { 
    587600                infolog("Skipping image check"); 
    588                 next IMAGE
     601                next
    589602            } 
    590603            if (defined($conf->{focr_max_size_bmp}) and ($$pic{fsize} > $conf->{focr_max_size_bmp})) { 
     
    603616                unless (defined $conf->{"focr_bin_$a"}) { 
    604617                    errorlog("Cannot exec $a, skipping image"); 
    605                     next IMAGE
     618                    next
    606619                } 
    607620            } 
     
    625638            if ($conf->{focr_skip_tiff}) { 
    626639                infolog("Skipping image check"); 
    627                 next IMAGE
     640                next
    628641            } 
    629642            if (defined($conf->{focr_max_size_tiff}) and ($$pic{fsize} > $conf->{focr_max_size_tiff})) { 
     
    643656                unless (defined $conf->{"focr_bin_$a"}) { 
    644657                    errorlog("Cannot exec $a, skipping image"); 
    645                     next IMAGE
     658                    next
    646659                } 
    647660            } 
     
    689702                if ($score > 0) { 
    690703                    infolog("Image in KNOWN_GOOD. Skipping OCR checks..."); 
    691                     next IMAGE
     704                    next
    692705                } 
    693706            } 
    694707            if ($digest eq '') { 
    695708                infolog("Empty Hash, skipping..."); 
    696                 next IMAGE
     709                next
    697710            } 
    698711        } else { 
     
    833846                        } 
    834847                    } 
    835                     infolog("Resorting scanset list...")
     848                    my $newlist
    836849                    @$scansets = sort { $b->{hit_counter} <=> $a->{hit_counter} } @$scansets; 
     850                    foreach my $s (@$scansets) { 
     851                        $newlist .= ' ' . $s->{label} . '(' . $s->{hit_counter} . ')'; 
     852                    } 
     853                    infolog("New sorted list:$newlist"); 
     854 
    837855                } 
    838856                last; 
  • trunk/devel/FuzzyOcr/Config.pm

    r107 r108  
    241241    push (@cmds, { 
    242242        setting => 'focr_log_stderr', 
     243        default => 1, 
     244        type => $Mail::SpamAssassin::Conf::CONF_TYPE_BOOL 
     245    }); 
     246 
     247    push (@cmds, { 
     248        setting => 'focr_log_pmsinfo', 
    243249        default => 1, 
    244250        type => $Mail::SpamAssassin::Conf::CONF_TYPE_BOOL