#!	/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.
#
#
#	Pine option:
#	allow user to choose whether or not to save copies of outgoing mail.
#
set pc = ~/.pinerc
#
#	check for use of Pine
#
if( ! -e $pc ) then
cat << "EOT"

Evidently you have not yet used Pine.  You can not specify whether to
save outgoing mail until after you have used Pine.

"EOT"
exit
endif
#
#	check for obvious cases
#
set x = `grep '^default-fcc' ~/.pinerc`
set y = ( $x )
#	don't try to figure it out if none, several, or blanks on line
if( $#y != 1 ) goto unclear
if( $x == 'default-fcc=""' ) goto not_saving
if( $x == 'default-fcc=sent-mail' ) goto saving
if( $x == 'default-fcc="sent-mail"' ) goto saving
#	uclink and uclink2,3,... work differently if have nothing after fcc=
if( $x == 'default-fcc=' ) then
	set h = `hostname | sed -e 's/\..*$//'`
	if( $h == "uclink" ) then
		set y = "default-fcc=sent-mail"
		goto saving
	else
		goto not_saving
	endif
endif
#
unclear:
set temp = `mktemp`
grep -v '^default-fcc=' ~/.pinerc > $temp
echo " "
echo It is not clear whether or not you are saving copies of outgoing mail.
read0:
echo -n  'Do you want to save copies of outgoing mail? (y/n) '
set r = $<
set y = ( $r )
if( $#y != 1 ) set r = "ERR"
if( $r == "y" ) then
	echo 'default-fcc=sent-mail' >> $temp
	set message = 'Ok.  Copies of outgoing messages will be saved in folder "sent-mail".'
	goto install
else if( $r == "n" ) then
	echo 'default-fcc=""' >> $temp
	set message = 'Ok.  Copies of outgoing messages will not be saved.'
	goto install
else
	echo "*** you must answer 'y' or 'n'."
	echo " "
	goto read0
endif

#==================================================================

saving:
set y = `echo $y | sed -e 's/default-fcc=//'`
echo Copies of outgoing mail are being saved in folder \"$y\".
read1:
echo -n  'Do you want to keep saving copies of outgoing mail? (y/n) '
set r = $<
set y = ( $r )
if( $#y != 1 ) set r = "ERR"
if( $r == "y" ) then
	echo 'Ok.  No change.'
	exit
else if( $r == "n" ) then
	set temp = `mktemp`
	sed -e 's/^default-fcc=.*$/default-fcc=""/' < $pc > $temp
	set message = 'Ok.  Copies of outgoing messages will not be saved.'
	goto install
else
	echo "*** you must answer 'y' or 'n'."
	echo " "
	goto read1
endif

#==================================================================

not_saving:
echo Copies of outgoing mail are not being saved.
read2:
echo -n 'Do you want to start saving copies of outgoing mail? (y/n) '
set r = $<
set y = ( $r )
if( $#y != 1 ) set r = "ERR"
if( $r == "y" ) then
	set temp = `mktemp`
	sed -e 's/^default-fcc=.*$/default-fcc=sent-mail/' < $pc > $temp
	set message = 'Ok.  Copies of outgoing messages will be saved in folder "sent-mail".'
	goto install
else if( $r == "n" ) then
	echo 'Ok.  No change.'
	exit
else
	echo "*** you must answer 'y' or 'n'."
	echo " "
	goto read2
endif
exit

install:
set htemp = `mktemp -c -p .pine -d ~`
/bin/cp $temp $htemp
if( $status ) goto error
/bin/mv $htemp ~/.pinerc
if( $status ) goto error
echo $message
if( -e $temp ) /bin/rm -f $temp
exit



#==================================================================

error:
cat << "EOT"

*** Your requested changes could not be installed, possibly due to
*** quota or permission problems.  No change was made.

"EOT"
if( -e $temp ) /bin/rm -f $temp
if( -e $htemp ) /bin/rm -f $htemp
exit
