#! /bin/sh
# Script to let people inc mail into PINE using kpop.
# A mailbox location of ~/mail/inbox is hardcoded into the program.

PATH="/usr/bin:/bin:/usr/athena/bin:/bin/athena:$PATH"
export PATH

# This variable is used by pmail: it controls where your mail ends up.
POPBOX="$HOME"/mail/inbox
export POPBOX



msg1="pine-inc: message:
	Pine in the sipb locker has been upgraded.
	The new version will automatically incorporate your mail for
	you, which means that you no longer need to run \"pine-inc\"
	when you run \"pine\".  We encourage you to stop doing so.
	(You are seeing this message because you *did* run \"pine-inc\".)
"

msg2="	From now on, the \"pine-inc\" script is going to continue
	printing messages like this, to encourage you to stop using it.
	You can avoid getting these messages by either not running
	\"pine-inc\", or by instead running the script \"pine-inc3\".
"

msg3="	Additional motivation for stopping use of this script is the
	fact that \"pine-inc\" (and \"pine-inc3\") *will* lose some of
	your mail if you run it when you are too far over quota.
"

msgn="	For more information, send mail to bug-sipb@mit.edu.
"

echo "$msg1"
if [ 20000410 -lt "`date +%Y%m%d`" ] ; then	# Apr 10, 2000
    echo "$msg2"
fi
if [ 20000501 -lt "`date +%Y%m%d`" ] ; then	# May 1, 2000
    echo "$msg3"
fi
echo "$msgn"
perl -e 'if (-t) { print "Press RETURN or ENTER to continue running \"pine-inc\"... "; $_=<>; } else { sleep(4); }'


sipbbin=`athdir /mit/sipb`
if [ $? != 0 ] ; then sipbbin="/mit/sipb/bin" ; fi
pmail="$sipbbin"/pmail
mailrc="$HOME"/.mailrc


if [ ! -r "$POPBOX" ] ; then
    echo "Creating $POPBOX" | sed "s,$HOME,~,g" 1>&2
    sleep 2				# give enough time to hit Control-C
    dir=`dirname "$POPBOX"`
    if [ ! -d "$dir" ] ; then
	mkdir "$dir"
	fs setacl "$dir" system:anyuser none
    fi
    touch "$POPBOX"
    if [ $? != 0 ] ; then
	echo "Error: Could not create $POPBOX" 1>&2
	exit 1
    fi
fi


if [ -r "$mailrc" ] ; then
	mailrcsave="$mailrc".save$$
	# Be sure to put .mailrc back on exit
	trap 'mv "$mailrcsave" "$mailrc"' 0 1 2 3 15
	# Move .mailrc aside so that pmail works the default way
	mv "$mailrc" "$mailrcsave"
	"$pmail" -N < /dev/null > /dev/null
	exit $?
else
	exec "$pmail" -N < /dev/null > /dev/null
fi
