#!/bin/sh
#
# Checks Received: headers against TCATS whitelist.
# Exits with return code of 1 if there was a match,
# otherwise 0.  Meant to be called from procmail.
#

skip='^(127\.|10\.|192\.168\.|172\.[12]?[0-9]\.|172\.30\.|172\.31\.)'

for ip in `formail -x Received:|egrep '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'| \
           sed -Ee 's/[^0-9]*([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*/\1/'`
do
    if echo "$ip" | egrep "$skip" > /dev/null
    then
        continue
    fi
    rblip=`echo $ip |awk -F. '{printf "%s.%s.%s.%s.accept.stop-spam.org",$4,$3,$2,$1}'`
    if host -t a "$rblip" > /dev/null 2> /dev/null
    then
        exit 1
    fi
done 


