#
# mailertable: generate rules to use mailertable facility
#

REVISION_ID='@(#)mailertable	3.6 (motonori/WIDE) 2/26/94'

#|# use mailertable feature (yes/no/"database path"; default:/etc/mailertable)
#|# how to make DB: makemap hash /etc/mailertable.db < /etc/mailertable
#|#MAILERTABLE=no

: ${MAILERTABLE=no}
if [ "$MAILERTABLE" != no ]
then

	if [ "$REVISION_ID_LIST" ]
	then
		REVISION_ID_LIST="$REVISION_ID_LIST\\
# $REVISION_ID"
	else
		REVISION_ID_LIST="# $REVISION_ID"
	fi

	case "$MAILERTABLE" in
	/*) MAILERTABLEDB="$MAILERTABLE";;
	*)  MAILERTABLEDB="/etc/mailertable";;
	esac

HDRMAILERTABLE="\\
# mailer table (overriding domains)\\
Kmailertable hash -o $MAILERTABLEDB"

S0MAILERTABLE='\
# try mailer table lookup\
R$*<@$+>$*		$:<$2>:$1<@$2>$3		extract host name\
R<$+.>:$*		$:<$1>:$2			strip trailing dot\
R<$+>:$*		$:<$(mailertable $1$)>:$2	lookup\
R<$-:$+>:$*		$@$>88 <$1:$2>:$3		check -- resolved?\
R<$+>:$*		$:$>90 <$1>:$2			try domain'


MAILERTABLEBODY='\
###################################################################\
###  Ruleset 90 -- try domain part of mailertable entry		###\
###################################################################\
\
S90\
R$*<$-.$+>:$*		$:$1$2<$(mailertable .$3$@$1$2$@$2$)>:$4	lookup\
R$*<$-:$+>:$*		$@$>88 <$2:$3>:$4		check -- resolved?\
R$*<.$+>:$*		$@$>90 $1.<$2>:$3		no -- strip/try again\
R$*<$*>:$*		$:<$(mailertable .$@$1$2$@$2$)>:$3	try "."\
R<$-:$+>:$*		$@$>88 <$1:$2>:$3		"." found?\
R<$*>:$*		$@$2				no mailertable match'

fi
