MIMEDefang Script Modification by Scott Harris <scott@ozmatrix.com>:

# If SpamAssassin found SPAM, append report.  We do it as a separate
# attachment of type text/plain  
    
sub filter_end_aux ($) {
    my($entity) = @_;
        
# No sense doing any extra work
    return if message_rejected();
    
    # Spam checks if SpamAssassin is installed
    if ($Features{"SpamAssassin"}) {
        if (-s "./INPUTMSG" < 200*1024) {
            # Only scan messages smaller than 200kB.  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();
            if ($hits >= $req) {   
                md_log('spam', $hits, $RelayAddr);
                my($score);
                if ($hits < 40) {
                    $score = "*" x int($hits);
                } else {
                    $score = "*" x 40;
                }
    # 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...
                #action_change_header("X-Spam-Score", "$hits ($score) $names");
            
                action_add_header("X-Spam-Warning", "SpamAssassin says this message is SPAM");
                action_add_header("X-Spam-Status", "Yes, hits=$hits required=$req");
                action_add_header("X-Spam-Report","$report");
                } else {
                action_add_header("X-Spam-Status", "No");
                } 
                # if we're quite confident it actually IS spam, just bounce it
                if ($hits > 5) {
                action_quarantine_entire_message();
                action_bounce("Message seems to be spam, rejected");    
                }
                # If you find the SA report useful, add it, I guess...  
                action_add_part($entity, "text/plain", "-suggest",
                                "$report\n",
                                "SpamAssassinReport.txt", "inline");
            } else {
                # Delete any existing X-Spam-Score header?
                action_delete_header("X-Spam-Score");
            }
                
                # Now this is the real filter_end
                sub filter_end ($) {
                my($entity) = @_;
                
                # Do the real work
                filter_end_aux($entity);
 
                # And send notifications
                send_quarantine_notifications();
                }
                            
    }
}
                
# DO NOT delete the next line, or Perl will complain.
1;