#!/bin/sh -
MYBIN="$HOME/binp"

# mail - runs the UCB mail command no matter what it's called
# Steve Kinzler, steve@kinzler.com, Dec 93/Mar 98/Oct 98
# https://kinzler.com/me/home.html#unixuni

case "$ReMail99" in
?*)	echo "$0: aborting recursive mail front-end" 1>&2; exit 1;;
*)	ReMail99=true; export ReMail99;;
esac

if test $# = 0 -a -f "$HOME/tmp/.nomail"
then
	echo "Ignoring mail for $USER"
	echo "Remove $HOME/tmp/.nomail to activate"
	exit 2
fi

case "$MAILCMD" in
?*)	exec "$MAILCMD" ${1+"$@"};;
esac

cmd=/usr/ucb/Mail;  test -f $cmd && exec $cmd ${1+"$@"}
cmd=/usr/bin/Mail;  test -f $cmd && exec $cmd ${1+"$@"}
cmd=/usr/sbin/Mail; test -f $cmd && exec $cmd ${1+"$@"}
cmd=/usr/bin/mailx; test -f $cmd && exec $cmd ${1+"$@"}

path=${BACKPATH-`echo ":$PATH:" | sed "s:$MYBIN::g; s/^://; s/:$//"`}
MAILCMD=`wh -p "$path" mail 2> /dev/null | sed 1q`; export MAILCMD

exec "$MAILCMD" ${1+"$@"}
