#! /bin/sh 
#
# Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
#
# "@(#)postpatch	1.3	98/05/21 SMI"
#
askyesno_default ()
{
	while true
	do
		echo "$1 (y/n) [$2]: \c"
		read ans
		if [ "$ans" = "" ]
		then
			ans=$2
		fi
		case $ans in

			"Y"|"y") return 1;;

			"N"|"n") return 0;;

			*) echo "\tInvalid Input: $ans";;
		esac
	done
}

# Add a line to tailor file
BASE=`/usr/bin/pkginfo -r SUNWbbmta`
MAILUSER=`/usr/bin/pkgparam SUNWbbmta MAILUSER`
CONFIGDIR=${BASE}/etc/opt/SUNWmail/imta

GOTLIBUTIL=`/usr/bin/grep -c IMTA_LIBUTIL ${CONFIGDIR}/imta_tailor`

if [ "${GOTLIBUTIL}" = "0" -a ! -z "${BASE}" -a ! -z "${CONFIGDIR}" ]; then
  TMP=/tmp/inetmail.$$
  sed -e s@VERSION=1.1@VERSION=1.1.1@ ${CONFIGDIR}/imta_tailor > $TMP
  echo "IMTA_LIBUTIL=${BASE}/opt/SUNWmail/lib/libimtautil.so.1" >> $TMP
     
  /usr/bin/cp -f $TMP ${CONFIGDIR}/imta_tailor
  (/usr/bin/chown root:sys ${CONFIGDIR}/imta_tailor) || echo "Permissions change failed for tailor file."
  (/usr/bin/chmod 755 ${CONFIGDIR}/imta_tailor) || echo "Permissions change failed for tailor file."

fi

#
# run iminitquota to clean up the message store quota files.
#
BASE=`/usr/bin/pkginfo -r SUNWimimu`

echo
echo "If the message store quota option is currently or has ever been turned"
echo "on, your message store may contain corrupted mail quota files.  You need"
echo "to run the message store utility 'iminitquota' with the -a option to fix"
echo "all of echo the quota files."
askyesno_default "Do you want to run this utility now" y
RC=$?
if [ $RC -eq 1 ]; then
	${BASE}/opt/SUNWmail/ims/sbin/iminitquota -a
else
	echo 
	echo "NOTE: You must run iminitquota -a to initialize the message"
	echo "store quotas before you enable the message store quota option."
	echo "For example: % ${BASE}/opt/SUNWmail/ims/sbin/iminitquota -a"
fi

echo
echo "You may run iminitquota -u <userid> or the incremental dirsync to"
echo "update the message store quota file after you update the user quota in"
echo "in the directory."
echo "You must run iminitquota -u <userid> to initialize the message store"
echo "quota file after you create a new user in the directory."
echo
echo

echo "---------------------------------------------------------------"
echo "You will have to restart im.server or reboot the system before"
echo "reusing SIMS."
echo "---------------------------------------------------------------"

exit 0
