[Mimedefang] 'remove_redundant_html_parts called outside of filter_end' problem

Justin listuser at numbnuts.net
Thu Dec 11 20:34:52 EST 2003


On Fri, 12 Dec 2003, alan premselaar wrote:

> Well, I use clamd. I'm assuming it's faster, although I haven't really done
> any performance testing.  the only thing is that when I had the problem with
> the databases, clamd was dieing and causing the filter to tempfail, but if i
> switched to using clamav instead, it worked fine.  So, i'd say, if clamav is
> working for you, might as well stick with it.  (Unless someone else can
> provide a good reason to switch)

I figured clamd would be the only client/server method and clamav (or 
clamscan, I forget which) was the standalone load-the-virusDB-each-time 
client.  That's why I disabled clamav.  Clamd seems to be running 
normally.  It is writing the databae selfchecks on the hour like normal.  
I am still getting temp failures though. :(

I made some changes to my filter_end.  It makes more sense now I think.

sub filter_end ($) {
    my($entity) = @_;
        
    # If you want quarantine reports, uncomment next line
    # send_quarantine_notifications();   
        
    # IMPORTANT NOTE:  YOU MUST CALL send_quarantine_notifications() AFTER
    # ANY PARTS HAVE BEEN QUARANTINED.  SO IF YOU MODIFY THIS FILTER TO
    # QUARANTINE SPAM, REWORK THE LOGIC TO CALL 
send_quarantine_notifications()
    # AT THE END!!!
        
    # No sense doing any extra work
    return if message_rejected();
         
    # Spam checks if SpamAssassin is installed
    if ($Features{"SpamAssassin"}) {
      # List local IPs that you DO NOT want MD to run SA checks on
      # This excludes maple from this bypass but lets localhost and the 
/19 bypass SA.
      if ($RelayAddr ne "64.71.97.12" and
        $RelayAddr eq "127.0.0.1" or
        $RelayAddr =~ /^64\.71\.96\./ or
        $RelayAddr =~ /^64\.71\.97\./ or
        $RelayAddr =~ /^64\.71\.98\./ or
        $RelayAddr =~ /^64\.71\.99\./ or
        $RelayAddr =~ /^64\.71\.100\./ or
        $RelayAddr =~ /^64\.71\.101\./ or
        $RelayAddr =~ /^64\.71\.102\./ or 
        $RelayAddr =~ /^64\.71\.103\./ or
        $RelayAddr =~ /^64\.71\.104\./ or
        $RelayAddr =~ /^64\.71\.105\./ or
        $RelayAddr =~ /^64\.71\.106\./ or
        $RelayAddr =~ /^64\.71\.107\./ or
        $RelayAddr =~ /^64\.71\.108\./ or
        $RelayAddr =~ /^64\.71\.109\./ or
        $RelayAddr =~ /^64\.71\.110\./ or
        $RelayAddr =~ /^64\.71\.111\./
      ) {
            
        # Disabled extension checks by returning immediately. 
        return 0;
      } else {
                
        if (-s "./INPUTMSG" < 100*1024) {
            # Only scan messages smaller than 100kB.  Larger messages
            # are extremely unlikely to be spam, and SpamAssassin is
            # dreadfully slow on very large messages.
            my($hits, $req, $names, $report) = spam_assassin_check();
            my($score);
            if ($hits < 150) {
                $score = "*" x int($hits);
            } else {
                $score = "*" x 40;
            } # end of $hits < 150
    
            # We add a header which looks like this:
            # X-Spam-Score: 6.8 (******) NAME_OF_TEST,NAME_OF_TEST
            # The number of asterisks in parens is the integer part
            # of the spam score clamped to a maximum of 40.
            # MUA filters can easily be written to trigger on a   
            # minimum number of asterisks...
            if ($hits >= $req) {
                # Delete any existing X- Spam-related headers?
                action_delete_header("X-Spam-Score");
                action_delete_header("X-Spam-Report");
                action_delete_header("X-Spam-Status");
                action_delete_header("X-Scanned-By");
        
                my $fixed_report = $report;
                $fixed_report =~ s/\n+\z//g;        # fixes for multiline 
header
                $fixed_report =~ s/\n/\n\t/g;       # to stop sendmail 
complaining
        
                action_change_header("X-Spam-Score", "$score ($hits) 
$names");
                action_change_header("X-Spam-Report", "$fixed_report");
                # action_add_header("X-Spam-Report", "$fixed_report");
                md_graphdefang_log('spam', $hits, $RelayAddr);
        
                # Change the Subject line if $hits >= 10
                if ($hits >= 10) {
                   action_add_header("X-Original-Subject", "$Subject");
                   action_change_header("Subject", "***SPAM*** $Subject");
                }
        
            } else {
                # Delete any existing X-Spam-Score header?
                action_delete_header("X-Spam-Score");
                action_delete_header("X-Spam-Report");
                action_delete_header("X-Spam-Status");
                action_delete_header("X-Scanned-By");
            } #end of $hits >= $req
            
        } # end of size check 
                
      } # end of $RelayAddress check
                
    } # end of Features[SpamAssassin]
    
    # I HATE HTML MAIL!  If there's a multipart/alternative with both
    # text/plain and text/html parts, nuke the text/html.  Thanks for
    # wasting our disk space and bandwidth...
            
    # If you don't mind HTML mail, comment out the next line.     
    remove_redundant_html_parts($entity);   
            
    md_graphdefang_log('mail_in');
                
# I'm not sure why I have to comment this out.  If I don't I get an 
unmatced brace error.
# Strike that.  I no longer have to comment this out! 
} # sub filter_end


This canned the 'remove_redundant_html_parts called outside of filter_end'
problem, which was my initial problem.  Now, however, it doesn't appear to
be scoring anything if the message doesn't get temp failed first.  It's
most perplexing.  At least my filter is now easier to read and debug. :)

Thanks
 Justin



More information about the MIMEDefang mailing list