./MailFilter/SuspiciousChars.pm


package MailFilter::SuspiciousChars;

use strict;
use warnings;
use Mimedefang qw{
    $SuspiciousCharsInHeaders
    $SuspiciousCharsInBody
    $MsgID
    md_graphdefang_log
    md_syslog
    action_bounce
    message_rejected
};

#***********************************************************************
# %PROCEDURE: filter_begin
# %ARGUMENTS:
#  None
# %RETURNS:
#  Nothing
# %DESCRIPTION:
#  Called just before e-mail parts are processed
#***********************************************************************

sub filter_begin () {
    # No sense doing any extra work
    if (message_rejected()) {
        md_syslog('debug', $MsgID . 
            ": SuspiciousChars check skipped, already rejected");
        return;
    }
    
    # ALWAYS drop messages with suspicious chars in headers or body
    if ($SuspiciousCharsInHeaders) {
        md_graphdefang_log('suspicious_chars_header');

        # Do NOT allow message to reach recipient(s)
        return action_bounce("Rejected because of violation of RFC2822 section 2.2", 554, "5.6.0");
    }
}

1;