#!/bin/sh
#
# $Author$
# $Source$
# $Header$


# Variables which configure this script:
lucy_address=lucyx-mtg@euphrosyne.LOCAL
question_file=/tmp/lucy$$.txt
textdir=/afs/athena.mit.edu/astaff/project/lucydev/text

# make sure stuff this script needs is up front:
# eval `/etc/athena/sh_commands_path`
# PATH=$PATH:/bin/athena

# Introductory note:
if [ "x$XLOGIN" = "xtrue" ]; then
	/bin/cat < ${textdir}/pre-question.txt
	read foo		# Wait for user to press Return.
fi

# Choose editor and use it to compose question:
if [ "x$EDITOR" = "x" ]; then
	EDITOR=emacs ; export EDITOR
fi

# Users may choose to redo steps:
lucy_step=1

while [ $lucy_step -lt 3 ]; do

	if [ $lucy_step -eq 1 ]; then
		if [ "x$XLOGIN" = "xtrue" ]; then
			/bin/cat < ${textdir}/xsession.txt
		fi
		$EDITOR $question_file
	fi

	# Zero subject, etc if redoing them.
	if [ $lucy_step -eq 2 ]; then
		subject=
		personal=
		publish=
	fi

	if [ "x$subject" = "x" ]; then

		# Get subject line:
		/bin/cat < ${textdir}/subject.txt
		while [ "x$subject" = "x" ]; do
			echo -n 'Subject --> '
			read subject
		done

		# Get personal line:
		/bin/cat < ${textdir}/personal.txt
		while [ "x$personal" = "x" ]; do
			echo -n 'Send personal reply to: '
			read personal
		done

		# Get publish line:
		/bin/cat < ${textdir}/publish.txt
		while [ "x$publish" = "x" ]; do
			echo -n 'Type yes or no --> '
			read publish
		done
	fi

	/bin/cat < ${textdir}/whatnow.txt
	lucy_step=0
	while [ \( ${lucy_step}x -lt 1 \) -o \( ${lucy_step} -gt 3 \) ]; do
		echo -n ' --> '
		read lucy_step
	done
done

echo 'SEND PERSONAL REPLY: ' $personal >> $question_file
echo 'PUBLISH QUESTION/ANSWER IN BROWSER: ' $publish >> $question_file

mail -s "$subject" $lucy_address < $question_file \
	&& echo "Your question has been sent to lucy."
rm -f $question_file
