#
# usertable: generate rules to rewrite with usertable
#

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

#|# domain names for usertable rewriting
#|##USERTABLE_DOMAIN_NAMES='usertable.domain.name1 usertable.domain.name2'
#|# path for usertable database or "nis" (default: /etc/usertable.db)
#|# how to make DB: makemap btree /etc/usertable.db < /etc/usertable
#|#USERTABLEDB=/etc/usertable
#|##USERTABLEDB=nis
#|# apply maildrop of usertable for local users (yes/no)
#|#USERTABLE_APPLY_LOCAL=no

if [ "$USERTABLE_DOMAIN_NAMES" ]
then

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

	# allocate class character
	_ALLOC_MODE=normal
	_ALLOC_TYPE=class
	_ALLOC_DIR=down
	_ALLOC_PREF=
	_ALLOC_USAGE='domain names for usertable [usertable]'
	. $MASTERDIR/$CHARALLOC
	_UD_CHAR=$_ALLOC_CHAR

	: ${USERTABLEDB=/etc/usertable}

	exec << EoF
$USERTABLE_DOMAIN_NAMES
EoF
	CLASS=`sed 's/^/C'$_UD_CHAR' /'`

HDRUSERTABLE="\\
# usertable domain names\\
$CLASS"

	if [ "$USERTABLEDB" = nis ]
	then

HDRUSERTABLE="$HDRUSERTABLE\\
# usertable (rewrite user names)\\
Kusertable nis -o usertable"

	else

HDRUSERTABLE="$HDRUSERTABLE\\
# usertable (rewrite user names)\\
Kusertable btree -o $USERTABLEDB"

	fi

S11USERTABLEMAILNAME1='\
# user name rewriting\
R$+<@$='$_UD_CHAR'>		$:$(usertable $1:mailname $: $1 $)<@$2>\
R$+@$+<@$='$_UD_CHAR'>		$:$1<@$2>'

S0USERTABLEMAILDROP='\
# address rewriting\
R$+<@$='$_UD_CHAR'>		$:$(usertable $1:maildrop $: $1 $)<@$2>\
R$+@$+<@$='$_UD_CHAR'>		$@$>97 $1@$2			retry'

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

S5USERTABLEMAILDROP='\
# address rewriting\
R$+			$:$(usertable $1:maildrop $: $1 $)\
R$+@$+			$@$>97 $1@$2			retry'

S11USERTABLEMAILNAME2='\
# user name rewriting\
R$+			$:$(usertable $1:mailname $: $1 $)'

S21USERTABLEMAILNAME='\
# user name rewriting\
R$+			$:$(usertable $1:mailname $: $1 $)'

	fi

fi
