#!	/bin/csh -f
#
# Copyright 1993, 1994, 1995 by the Regents of the University of California.
# see the file "Copyright" in the distribution for conditions of use.
#
#
#		Step 1 - intro
#
set noglob
set logon = $USER
set name = ( $NAME )
cat << EOT

This program allows you to create a vacation message.  You can either
use the editor to create a message or use a simple message such
as:

    From: $logon@uclink.berkeley.edu ($name)
    Subject: I am on vacation
    Delivered-By-The-Graces-Of: The Vacation program
    Precedence: bulk
    
    I am on vacation until July 22 and am not reading my email.
    It is being saved and I will read it at that time.
    If you have something urgent, contact my friend Joe at
    helpful@uclink.berkeley.edu .
    
          - $name

EOT
cat << "EOT"

After you complete the process of creating the message, you will
be asked whether you want to save it or not.

"EOT"
#		Step 2 - The Name	
#
retry2:
echo ' '
echo First, your name in the first line of the header above is:
echo '		'\"$name\"
echo -n "Is that ok? (y/n) "
set x = $<
set y = ( $x )
if( $#y != 1 ) set x = "ERR"
if( $x == "y" ) goto step3
if( $x != "n" ) then
	echo '*** You must enter "y" or "n".'
	goto retry2
endif
#
echo -n "Enter how you want your name to be entered: "
set name = $< 

#		Step 3 - get the Subject
step3:

set subject = "I am on vacation"
retry3:
echo ' '
echo Next, the subject in the message above is \"$subject\".
echo -n "Is that ok? (y/n) "
set x = $<
set y = ( $x )
if( $#y != 1 ) set x = "ERR"
if( $x == "y" ) goto step4
if( $x != "n" ) then
	echo '*** You must enter "y" or "n".'
	goto retry3
endif

echo -n "Enter the subject line you want: "
set subject = $<
if( "$subject" =~ quit ) exit

#		Step 4 - Now the body
step4:
cat << EOT

The name and subject you have selected will be put in the header of
the message.  Now it is time for you to compose the body of the message
and signature, e.g.:

    I am on vacation until July 22 and am not reading my email.
    It is being saved and I will read it at that time.
    If you have something urgent, contact my friend Joe at
    helpful@uclink.berkeley.edu .

          - $name
    
It is easiest to use an editor to compose the message.  If you do not
know how to use a UCLink editor, you can choose the above message
with simple modifications.

EOT
set temp_body = `mktemp -c`
set temp_all = `mktemp -c`
retry4:
echo -n "Do you want to use an editor? (y/n) "
set x = $<
set y = ( $x )
if( $#y != 1 ) set x = "ERR"
if( $x == "y" ) goto step5
if( $x != "n" ) then
	echo '*** You must enter "y" or "n".'
	goto retry4
endif

#		Step 5a - no editor

step5a:
set temp_bdy1 = `mktemp -c -pbody1`
cat << "EOT"

You will now be promted for three items: a reason, a date, and a
referral which will be fit into your message.  All are optional.
If you do not want to specify one, just press Return without entering
any text.

Typical reasons are:
	I am on vacation
or
	I am out of town
"EOT"
echo -n "Enter reason: "
set reason = $<

echo -n "Enter date at which you will return and start reading email: "
set date = $<

echo -n "Enter a referral for pressing matters: "
set ref = $<

set y1 = ( $reason )
set y2 = ( $date )
set y3 = ( $ref )
if( $#y1 == 0 && $#y2 == 0 ) then
	echo I am not currently reading my email. >> $temp_bdy1 
else if( $#y1 == 0 && $#y2 != 0 ) then
	echo I will not be reading my email until $date. >> $temp_bdy1
else if( $#y1 != 0 && $#y2 == 0 ) then
	echo $reason and not currently reading my email. >> $temp_bdy1
else
	echo $reason and will not be reading my email until $date. >> $temp_bdy1
endif

if( $#y2 == 0 ) then
	echo It is being saved so that I can read it later.  >> $temp_bdy1
else
	echo It is being saved so that I can read it at that time. >> $temp_bdy1
endif

if( $#y3 != 0 ) then
	echo If you have something urgent, contact >> $temp_bdy1
	echo $ref >> $temp_bdy1
endif
fmt $temp_bdy1 > $temp_body
/bin/rm $temp_bdy1
echo " " >> $temp_body
echo "	- $name" >> $temp_body
goto step6


#		Step 5 - invoke the editor

step5:
set file = $temp_body
set embedded
source $MENU_LIB/edit_file

#		Step 6 - put it together

step6:
cat << EOT >> $temp_all
From: $logon@uclink.berkeley.edu ($name)
Subject: $subject
Delivered-By-The-Graces-Of: The Vacation program
Precedence: bulk

EOT
cat $temp_body >> $temp_all

#		Step 7 - review before saving

cat << EOT

Ok.  Your full message now is:

EOT
cat $temp_all
retry5:
echo ' '
echo -n 'Do you want to save it as your message? (y/n) '
set x = $<
set y = ( $x )
if( $#y != 1 ) set x = "ERR"
if( $x == "n" ) exit
if( $x != "y" ) then
	echo '*** You must enter "y" or "n".'
	goto retry5
endif

unset noglob
set temph = `mktemp -c -p. tmp -d ~`
if( $status ) goto error
/bin/cp $temp_all $temph
if( $status ) goto error
/bin/mv $temph ~/.vacation.msg
if( $status ) goto error

echo " "
echo The message has been saved.
exit 0


error:
cat << EOT

The message could not be saved, possibly due to quota errors.

EOT
exit 1
