On Fri, 15 Dec 2006, Whit Blauvelt wrote:

On Wed, Dec 13, 2006 at 06:43:37PM +0900, Mark van Proctor wrote:

Has anyone implemented some form of parsing of the received headers to
determine who the previous relay was? When is the earliest time that these
headers are available? filter_begin? Are these easily accessible through
mimedefang's variables or will we need to build some kind of script that
will parse the actual mail files?


Here is what I use to determine if the mail originated locally.
$OURNET is the prefix of our class B address and $OURDOMAIN is our
domain name. I use this in filter_end to avoid calling SpamAssassin
for mail that originated locally.

#
# Returns 1 if all relays are local
#
sub check_local_sender () {
    return 0 if $RelayAddr !~ /^$OURNET/;
    open (HDRS,"<./HEADERS") or return 0;
    my $maybe = '(?: *\(may be forged\) *)';
    while (<HDRS>) {
        if 
(/^received:\s+from\s+([^\s]+)\s+\((.*)\[($IPADDR)\]$maybe\)\s+by\s+([^\s]+)\s+/i)
 {
            my $helo = $1;
            my $name = $2;
            my $addr = $3;
            my $by = $4;
            next if $addr eq '127.0.0.1' && $by eq 'localhost';
            last if $addr eq '127.0.0.1' && $by =~ /$OURDOMAIN$/;
            next if $addr =~ /^$OURNET/ && $by =~ /$OURDOMAIN$/;
            close HDRS;
            $RealHelo = $helo;
            $RealRelayName = $name;
            $RealRelayAddr = $addr;
            $RealRelayName = "[$RealRelayAddr]" unless $RealRelayName;
            return 0;
        } elsif (/^received:/i) {
            close HDRS;
            return 0;
        }
    }
    close HDRS;
    return 1;

- rick
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID.  You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list [email protected]
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang

Reply via email to