#!/bin/csh -fb
# (The "-fb" might need to be changed to "-f" on some systems)
#
#
# This is sun-message.  It looks at $2 to figure out how to decode $1, then gives the
# user a short menu of choices, display, save, or quit.
#
mkdir /tmp/decode.$$
cd /tmp/decode.$$

if (! $?METAMAIL_PAGER) then
    set METAMAIL_PAGER=more
endif

if ($2 == "uuencode") then
    set fn=`mktemp $METAMAIL_TMPDIR/audio.XXXXXX`
    test -n "$fn"
    if $? then
	    exit 1
    endif

    uudecode -o $fn $1

    echo "The following file was uudecoded:"
    echo ""

    set defans = "1"
    while (1)
	ls -l

	echo ""
	echo "Please choose one:"
	echo ""
	echo "1 -- Display it as ASCII text"
	echo "2 -- Save it as a file"
	echo "3 -- Quit this menu"
	echo ""
	echo -n "Which do you prefer (1 - 3)? [$defans] "

	set ans = $< 
	if (x$ans == x) then
	    set ans = $defans
	endif
	if ($ans == 3)  then
	    rm $1
	    cd /tmp; /bin/rm -rf /tmp/decode.$$
	    exit 0
	else if ($ans == 1) then
	    ${METAMAIL_PAGER} $fn
	else if ($ans == 2) then
	    set nfn = ""
	    echo -n "Save as: $HOME/"
	    set nfn = $<
	    if (x$nfn != x) then
		/bin/cp $fn ${HOME}/$nfn
	    else
		echo "Not Saved."
	    endif
	else
	    echo "Invalid choice."
	endif
	set defans = "3"
    end
else
    ${METAMAIL_PAGER} $1
endif


