#
# hub: generate rules to send mails for non-local users to hub host
#

REVISION_ID='@(#)hub	3.8 (motonori/WIDE) 3/14/94'

#|# hub host
#|##HUB_HOST='hub.host.name'
#|# list of users who should be recognized as remote
#|##REMOTE_USERS=/etc/users.remote
#|# list of users who should be recognized as local (higher preference)
#|##NON_REMOTE_USERS=/etc/users.local
#|# relay local to hub host (yes/no)
#|#RELAY_LOCAL_TO_HUBHOST=no

if [ "$HUB_HOST" ]
then

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

	# allocate macro character
	_ALLOC_MODE=normal
	_ALLOC_TYPE=macro
	_ALLOC_DIR=down
	_ALLOC_PREF=
	_ALLOC_USAGE='hub host name [hub]'
	. $MASTERDIR/$CHARALLOC
	_HH_CHAR=$_ALLOC_CHAR

	MACRO=${HUB_HOST+D$_HH_CHAR$HUB_HOST}
	if [ "$MACRO" = "" ]
	then
		MACRO='#D'$_HH_CHAR'hub.host.name'
	fi

	if [ "$REMOTE_USERS" ]
	then
		# allocate class character
		_ALLOC_MODE=normal
		_ALLOC_TYPE=class
		_ALLOC_DIR=down
		_ALLOC_PREF=
		_ALLOC_USAGE='remote users [hub]'
		. $MASTERDIR/$CHARALLOC
		_RU_CHAR=$_ALLOC_CHAR
	fi
	case "$REMOTE_USERS" in
	"") ;;
	/*)     # file definition
		CLASS_RU="F$_RU_CHAR$REMOTE_USERS" ;;
	*)      # definition in .cf
		exec << EoF
$REMOTE_USERS
EoF
		CLASS_RU=`sed 's/^/C'$_RU_CHAR' /'` ;;
	esac
	if [ "$CLASS_RU" = "" ]
	then
		CLASS_RU='#F'$_RU_CHAR'/etc/users.remote'
	fi

	if [ "$NON_REMOTE_USERS" ]
	then
		# allocate class character
		_ALLOC_MODE=normal
		_ALLOC_TYPE=class
		_ALLOC_DIR=down
		_ALLOC_PREF=
		_ALLOC_USAGE='non remote users [hub]'
		. $MASTERDIR/$CHARALLOC
		_NR_CHAR=$_ALLOC_CHAR
	fi
	case "$NON_REMOTE_USERS" in
	"") ;;
	/*)     # file definition
		CLASS_NR="F$_NR_CHAR$NON_REMOTE_USERS" ;;
	*)      # definition in .cf
exec << EoF
$NON_REMOTE_USERS
EoF
CLASS_NR=`sed 's/^/C'$_NR_CHAR' /'` ;;
	esac

#|# exact address specification
#|#WITH_HUB_ADDR=no
#|#IGNORE_HUB_MX=no

	: ${WITH_HUB_ADDR=no}
	if [ "$WITH_HUB_ADDR" != no ]
	then
		HUBADDR='<@$'$_HH_CHAR'>'
	fi

	: ${IGNORE_HUB_MX=no}
	if [ "$IGNORE_HUB_MX" != no ]
	then
		HUBRELAY='relay:[$'$_HH_CHAR']'
		IGNOREMXNUMERIC='R<$*[[$+]]>$*		$:<$1[$2]>$3			avoid nesting'
	else
		HUBRELAY='relay:$'$_HH_CHAR
	fi

	HUBHOSTRULE='# see if we have a hub'

	if [ "$NON_REMOTE_USERS" ]
	then

HDRHUBHOST="\\
# users who should be recognized as remote\\
$CLASS_RU\\
# users who should be recognized as local\\
$CLASS_NR\\
# hub host\\
$MACRO"

HUBHOSTRULE="$HUBHOSTRULE"'\
R$='$_NR_CHAR'			$@$1				local users'

	else

HDRHUBHOST="\\
# users who should be recognized as remote\\
$CLASS_RU\\
# hub host\\
$MACRO"

	fi

HUBHOSTRULE="$HUBHOSTRULE"'\
R$='$_RU_CHAR'			$:$>88 <'"$HUBRELAY"'>:$1'"$HUBADDR"'		to hub host'

fi

: ${RELAY_LOCAL_TO_HUBHOST=no}
if [ "$HUB_HOST" != "" -a "$RELAY_LOCAL_TO_HUBHOST" != no ]
then

LOCALHUBRETRYRULE='R$+			$:.$1				retrymarker'

	if [ "$_LU_CHAR" = "" ]
	then
		echo "hub: character is not allocated for local users." 1>&2
	fi

S0LOCALHUBRULE='# prepend send-hub marker on locals\
R$+			$:.$1				send-hub marker\
R..$+			$:$1				remove with retrymarker\
R.$*$=@$*		$:$1$2$3			remove send-hub marker\
R.$='$_LU_CHAR'			$:$1				remove send-hub marker'

S5LOCALHUBRULE='# send locals to hub host except prog/file/include job\
R.|$+			$:|$1				prog mailer\
R./$+			$:/$1				file mailer\
R.:$+			$::$1				include mailer\
R.$+			'"$DISPATCH"' <'"$HUBRELAY"'>:$1'"$HUBADDR"'		send to hubhost'

#|# make local sticky (yes/no)
#|#LOCAL_STICKY=no

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

STICKYRULE='\
# local sticky delivery\
R$-<@$j>		$#local$:$1\
R$-.$-<@$j>		$#local$:$1.$2'

	fi

fi
