#
# acceptaddr: generate rules for domain master
#
# (this file must be included after "canon")

REVISION_ID='@(#)acceptaddr	3.17 (motonori/WIDE) 2/3/95'

#|# addresses which should be accepted as local
#|##ACCEPT_ADDRS='$m'	# can be used with R8 sendmail
#|##ACCEPT_ADDRS=$MY_DOMAIN
#|##ACCEPT_ADDRS='accept.domain.name1 accept.domain.name2 ...'
#|# use /etc/sendmail.aa file (yes/optional/no)
#|# ("optional" is for R8 only)
#|#USE_aa_FILECLASS=no
#|#aa_FILE_PATH='/etc/sendmail.aa'
#|# accept mails for all hosts within my domain
#|# (yes/no/"a specific domain with leading dot"; default for "yes" is .$m)
#|#ACCEPT_LOWER=no
#|# lower name matching style (lw-file/!lw-file/any/one)
#|#LOWER_MATCH_STYLE=any
#|#lw_FILE_PATH='/etc/sendmail.lw'
#|# if LOWER_NAMES is defined, it is used instead of lw_FILE
#|##LOWER_NAMES='lower1 lower2 lower3'

: ${USE_aa_FILECLASS=no}
: ${ACCEPT_LOWER=no}
if [ "$ACCEPT_ADDRS" != "" -o "$USE_aa_FILECLASS" != no -o "$ACCEPT_LOWER" != no ]
then

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

	if [ "$CANON_ENVELOPE" = "" ]
	then
	    echo "acceptaddr: no default definition for CANON_ENVELOPE." 1>&2
	fi

fi

if [ "$ACCEPT_ADDRS" != "" -o "$USE_aa_FILECLASS" != no ]
then

	# allocate class character
	_ALLOC_MODE=normal
	_ALLOC_TYPE=class
	_ALLOC_DIR=down
	_ALLOC_PREF=
	_ALLOC_USAGE='accepting address [acceptaddr]'
	. $MASTERDIR/$CHARALLOC
	_AA_CHAR=$_ALLOC_CHAR

	# define a class to use /etc/sendmail.aa
	: ${aa_FILE_PATH='/etc/sendmail.aa'}
	case "$USE_aa_FILECLASS" in
	no)		FILECLASS='#F'"$_AA_CHAR$aa_FILE_PATH" ;;
	# options is R8 only
	optional)	FILECLASS='F'$_AA_CHAR' -o '"$aa_FILE_PATH" ;;
	*)		FILECLASS='F'"$_AA_CHAR$aa_FILE_PATH" ;;
	esac

	if [ "$ACCEPT_ADDRS" ]
	then

		exec << EoF
$ACCEPT_ADDRS
EoF
		CLASS=`sed 's/^/C'$_AA_CHAR' /'`

	else

		CLASS='#C'$_AA_CHAR' accept.domain.name'

	fi

HDRACCEPTADDR="\\
# address which should be accepted\\
$FILECLASS\\
$CLASS"

	if [ "$CF_FORMAT" = V1 ]
	then

S4ACCEPTADDR='\
R$+%$=w@$='$_AA_CHAR'		$1@$j				u%host@dom => u@host\
R$+%$j@$='$_AA_CHAR'		$1@$j				u%host@dom => u@host\
R$+%$='$_AA_CHAR'@$j		$1@$2				u%dom@host => u@dom\
R$+%$='$_AA_CHAR'@$='$_AA_CHAR'		$1@$2				u%dom@dom => u@dom'

	else

S4ACCEPTADDR='\
R$+%$=w@$='$_AA_CHAR'		$1@$j				u%host@dom => u@host\
R$+%$='$_AA_CHAR'@$j		$1@$2				u%dom@host => u@dom\
R$+%$='$_AA_CHAR'@$='$_AA_CHAR'		$1@$2				u%dom@dom => u@dom'

DSPTACCEPTRULE='R<$='$_AA_CHAR'>.$*		$@$2				delete local host\
R<$-:$='$_AA_CHAR'>.$*		$@$3				delete local host'

	fi

S0ACCEPTADDR='\
R<@$='$_AA_CHAR'>:$*		$@$>'"$R_S0RETRY"' $2			@here:... -> ...\
R$*<@$='$_AA_CHAR'>		$@$>'"$R_S0RETRY"' $1			...@here -> ...'

	if [ "$CANON_ENVELOPE" = no ]
	then

CANONACCEPTADDR='# acceptable domains are OK\
R$*<@$='$_AA_CHAR'>$*		$@$1<@$2>$3'

	else

CANONACCEPTADDR='# acceptable domains are OK\
R$*<@$='$_AA_CHAR'>$*		$@$1<@$2.>$3'

	fi

fi

if [ "$ACCEPT_LOWER" != no ]
then

	case "$LOWER_MATCH_STYLE" in
	*lw-file)
		# allocate class character
		_ALLOC_MODE=normal
		_ALLOC_TYPE=class
		_ALLOC_DIR=down
		_ALLOC_PREF=
		_ALLOC_USAGE='lower matching hosts [acceptaddr]'
		. $MASTERDIR/$CHARALLOC
		AL_CHAR=$_ALLOC_CHAR

		if [ "$LOWER_NAMES" ]
		then

HDRACCEPTLOWER="\\
# lower names which should be accepted\\
C$AL_CHAR $LOWER_NAMES"

		else

			: ${lw_FILE_PATH='/etc/sendmail.lw'}
HDRACCEPTLOWER="\\
# lower names which should be accepted\\
F$AL_CHAR$lw_FILE_PATH"

		fi ;;
	esac

	: ${LOWER_MATCH_STYLE=any}
	case "$LOWER_MATCH_STYLE" in
	lw-file)
		RCVLWMATCH='$='$AL_CHAR ;;
	!lw-file)
		RCVLWMATCH='$~'$AL_CHAR ;;
	one)
		RCVLWMATCH='$-' ;;
	*)
		RCVLWMATCH='$*' ;;
	esac

	if [ "$ACCEPT_LOWER" = yes ]
	then
		if [ "$_AA_CHAR" ]
		then
			RCVLWAADOM='.$='$_AA_CHAR
		else
			RCVLWMYDOM='.$m'
		fi
	else
		RCVLWMYDOM=".$ACCEPT_LOWER"
	fi

	if [ "$RCVLWAADOM" ]
	then

S0ACCEPTLOWER='\
R<@'"$RCVLWMATCH$RCVLWAADOM"'>:$*		$@$>'"$R_S0RETRY"' $3			@here:... -> ...\
R$*<@'"$RCVLWMATCH$RCVLWAADOM"'>		$@$>'"$R_S0RETRY"' $1			...@here -> ...'

		if [ "$CF_FORMAT" != V1 ]
		then

DSPTACCEPTLOWER='R<'"$RCVLWMATCH$RCVLWAADOM"'>.$*		$@$3				delete local host\
R<$-:'"$RCVLWMATCH$RCVLWAADOM"'>:$*		$@$4				delete local host'

		fi

		if [ "$CANON_ENVELOPE" = no ]
		then

CANONACCEPTLOWER='# lowers are OK\
R$*<@'"$RCVLWMATCH$RCVLWAADOM"'>$*		$@$1<@$2.$3>$4'

		else

CANONACCEPTLOWER='# lowers are OK\
R$*<@'"$RCVLWMATCH$RCVLWAADOM"'>$*		$@$1<@$2.$3.>$4'

		fi

	
	else

S0ACCEPTLOWER='\
R<@'"$RCVLWMATCH$RCVLWMYDOM"'>:$*		$@$>'"$R_S0RETRY"' $2			@here:... -> ...\
R$*<@'"$RCVLWMATCH$RCVLWMYDOM"'>		$@$>'"$R_S0RETRY"' $1			...@here -> ...'

		if [ "$CF_FORMAT" != V1 ]
		then

DSPTACCEPTLOWER='R<'"$RCVLWMATCH$RCVLWMYDOM"'>.$*		$@$2				delete local host\
R<$-:'"$RCVLWMATCH$RCVLWMYDOM"'>:$*		$@$3				delete local host'

		fi

		if [ "$CANON_ENVELOPE" = no ]
		then

CANONACCEPTLOWER='# lowers are OK\
R$*<@'"$RCVLWMATCH$RCVLWMYDOM"'>$*		$@$1<@$2'"$RCVLWMYDOM"'>$3'

		else

CANONACCEPTLOWER='# lowers are OK\
R$*<@'"$RCVLWMATCH$RCVLWMYDOM"'>$*		$@$1<@$2'"$RCVLWMYDOM"'.>$3'

		fi

	fi

fi
