#!	/bin/csh
#
# Copyright 1993, 1994, 1995 by the Regents of the University of California.
# see the file "Copyright" in the distribution for conditions of use.
#
#
#	show forwarding status
#
if( ! -e ~/.forward ) then
	echo Your mail is being saved in your inbox, and not being forwarded.
	echo You are not automatically replying to incoming mail.
	set s = 0
	goto vac_mess
endif
#
set awkf = `mktemp -pawk`
#
cat << "EOT" > $awkf
BEGIN { disp = "***"; vac = "***"; err = 0; }
{
	if( FILENAME == "-" ) {
		if( NR == 1 ) keep = $0;
		if( NR == 2 ) vacation = $0;
	} else if( disp == "***" && NF == 1 ) {
		if( substr( $0, length(), 1 ) == "," ) {
			line = substr( $0, 1, length() - 1 );
		} else {
			line = $0;
		}
		if( line == keep ) {
			disp = "kept in your inbox";
		} else if( line == "/dev/null" ) {
			disp = "discarded";
		} else {
			disp = "forwarded to " line;
		}
	} else if( vac == "***" && $0 == vacation ) {
		vac = "yes";
	} else {
		err++;
	}
}
END {
	if( err != 0 || disp == "***" ) {
		print "*** Sorry, status information can not be deciphered.";
		exit 2
	} else {
		print "Your incoming mail will be " disp ".";
		if( vac == "yes" ) {
			print "You are using vacation to automatically send replies.";
			exit 1;
		} else {
			print "You are not using vacation to automatically send replies.";
			exit 0;
		}
	}
}
"EOT"
#	no double quotes allow the $USER to be expanded
cat << EOT | awk -f $awkf - ~/.forward
\\$USER
"|/usr/ccs/bin/vacation $USER"
EOT
set s = $status

vac_mess:
echo " "
if( -e ~/.vacation.msg ) then
	echo Your vacation message is:
	echo " "
	$PAGER ~/.vacation.msg
else
	echo You do not have a vacation message.
endif
echo " "

if( $s == 0 && -e ~/.vacation.msg ) then
	echo " "
	echo "*** You have a vacation message, but it is not being used."
	echo " "
endif

if( $s == 1 && ! -e ~/.vacation.msg ) then
	echo " "
	echo "*** Although you have enabled the automatic reply function,"
	echo "*** you have no vacation message\!"
	echo " "
endif

if( $?awkf ) then
	/bin/rm $awkf
endif
