#
# canon: generate rules for canonicalization with nameserver lookup
#

REVISION_ID='@(#)canon	3.10 (motonori/WIDE) 2/26/94'

#|# canonicalization with nameserver lookup
#|# (all/one/short/unknown/no; or *-append)
#|#CANON=short	# if MX_SENDMAIL = yes
#|#CANON=no	# if MX_SENDMAIL = no
#|# domains which are already completed
#|##NO_CMPLT_DOMS='/etc/sendmail.topdomains'
#|##NO_CMPLT_DOMS='jp net edu com mil org gov us'
#|# every envelope address should be canonicalized (yes/no/unknown)
#|# this is for addresses which is not canonicalized by CANON definition
#|#CANON_ENVELOPE=no
##|#CANON_ENVELOPE=yes	# if MX_SENDMAIL = yes
##|#CANON_ENVELOPE=no	# if MX_SENDMAIL = no / CANON=all*

if [ "$MX_SENDMAIL" != no ]
then
	: ${CANON=short}
	: ${CANON_ENVELOPE=no}
#	: ${CANON_ENVELOPE=yes}
else
	: ${CANON=no}
	: ${CANON_ENVELOPE=no}
fi
case "$CANON" in
all*)		CANON_ENVELOPE=no ;;
*) ;;
esac

if [ "$CANON" != no -o "$CANON_ENVELOPE" != no ]
then

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

	# not canonicalizing addresses
	case "$CANON" in

	one*)	# only one token address should be canonicalized
CANONRULE2='# more than one token is OK\
R$*<@$-.$+>$*	$@$1<@$2.$3>$4' ;;

	short*)	# only one or two token address should be canonicalized
CANONRULE2='# more than two tokens is OK\
R$*<@$-.$-.$+>$*	$@$1<@$2.$3.$4>$5' ;;

	*) ;;	# any address should not be canonicalized

	esac

	if [ "$NO_CMPLT_DOMS" ]
	then

		# allocate class character
		_ALLOC_MODE=normal
		_ALLOC_TYPE=class
		_ALLOC_DIR=down
		_ALLOC_PREF=
		_ALLOC_USAGE='no completion domains [canon]'
		. $MASTERDIR/$CHARALLOC
		_KD_CHAR=$_ALLOC_CHAR

		# address not defined in NO_CMPLT_DOMS should be canonicalized
		case "$NO_CMPLT_DOMS" in
		/*) # defined by file
			CLASS="F$_KD_CHAR$NO_CMPLT_DOMS" ;;
		*)
			exec << EoF
$NO_CMPLT_DOMS
EoF
			CLASS=`sed 's/^/C'$_KD_CHAR' /'` ;;
		esac

KNOWNDOMAINS="\\
# well known domains (for avoidance of completion with nameserver)\\
$CLASS"

CANONRULE3='# known domains are OK\
R$*<@$*.$='$_KD_CHAR'>$*		$@$1<@$2.$3>$4'

	fi

	# on canonicalization with nameserver lookup
	case "$CANON" in

	all*|one*|short*|unknown*)
CANONRULE4='# canonicalize with nameserver lookup\
R$*<@$*>$*		$:$1<@$[$2$]>$3' ;;

	*) ;;	# any address should not be canonicalized

	esac


	# on addition of local domain to one-token address
	case "$CANON" in

	*append)	# append local domain on one-token address
CANONRULE5='# if nameserver fails\
R$*<@$->$*		$@$1<@$2.$m>$3			append my domain name' ;;

	*) ;;		# nothing should be done on one-token address

	esac

	if [ "$CANON_ENVELOPE" = no ]
	then

CANONRULE1='# official name is OK\
R$*<@$j>$*		$@$1<@$j>$2'

		if [ "$CF_FORMAT" != V1 -a "$CF_FORMAT" != NMTC ]
		then

STRIPTRAILINGDOT='# strip trailing dot off possibly canonical name\
R$*<@$+.>$*		$1<@$2>$3'

		fi
	else

		if [ "$CANON_ENVELOPE" = unknown ]
		then

CANONRULE1='# official name is OK\
R$*<@$j>$*		$@$1<@$j.>$2\
# known domains are OK\
R$*<@$*.$='$_KD_CHAR'>$*		$@$1<@$2.$3.>$4'

		else

CANONRULE1='# official name is OK\
R$*<@$j>$*		$@$1<@$j.>$2'

		fi

		if [ "$CF_FORMAT" = V1 -o "$CF_FORMAT" = NMTC ]
		then

STRIPTRAILINGDOT='R$*<@$+>$*		$:$1<@$2.>$3			append trailing dot'

		else

STRIPTRAILINGDOT='R$*<@$+.>$*		$@$1<@$2.>$3			canonicalized already\
R$*<@$+>$*		$:$1<@$2.>$3			append trailing dot'

		fi

S0CANONRULE='# canonicalize using the nameserver\
R$*<@$*$~'$_FD_CHAR'>$*		$:$1<@$[$2$3$]>$4'

S0STRIPTRAILINGDOT='\
# strip trailing dot off possibly canonical name\
R$*<@$+.>$*		$1<@$2>$3'

S1STRIPTRAILINGDOT='\
# strip trailing dot off possibly canonical name\
R$*<@$+.>$*		$1<@$2>$3'

S2STRIPTRAILINGDOT='\
# strip trailing dot off possibly canonical name\
R$*<@$+.>$*		$1<@$2>$3'

	fi

fi
