#! /bin/sh
#
# Copyright 1998 - 2005 Double Precision, Inc.
# See COPYING for distribution information.


prefix=/usr/local
exec_prefix=/usr/local
libexecdir=/usr/local/libexec
sbindir=${exec_prefix}/sbin
bindir="/usr/local/bin"
sysconfdir="/usr/local/etc/courier"

if test ! -f ${sysconfdir}/pop3d
then
	echo "${sysconfdir}/pop3d does not exist, forgot make install-configure?"
	exit 1
fi

if test ! -f ${sysconfdir}/pop3d-ssl
then
	echo "${sysconfdir}/pop3d-ssl does not exist, forgot make install-configure?"
	exit 1
fi

. /usr/local/etc/courier/pop3d
. /usr/local/etc/courier/pop3d-ssl

case $1 in
start)
	if test "$TLS_CACHEFILE" != ""
	then
		rm -f "$TLS_CACHEFILE"
		touch "$TLS_CACHEFILE"
		/usr/sbin/chown courier "$TLS_CACHEFILE"
		chgrp courier  "$TLS_CACHEFILE"
		chmod 600  "$TLS_CACHEFILE"
	fi
	exec /usr/bin/env -i PATH="$PATH" SHELL="$SHELL" \
		/bin/sh -c " set -a ; \
		prefix=/usr/local ; \
		exec_prefix=/usr/local ; \
		sbindir=${exec_prefix}/sbin ; \
		bindir=/usr/local/bin ; \
		libexecdir=/usr/local/libexec ; \
		. /usr/local/etc/courier/pop3d ; \
		. /usr/local/etc/courier/pop3d-ssl ; \
		PROXY_HOSTNAME=$PROXY_HOSTNAME; \
		POP3_TLS=1; \
                POP3_STARTTLS=NO; \
                POP3_TLS_REQUIRED=0; \
		/bin/mkdir -p `dirname $SSLPIDFILE` ; \
		/usr/local/sbin/courierlogger -pid=$SSLPIDFILE -start $SSLLOGGEROPTS \
		${exec_prefix}/sbin/couriertcpd -address=$SSLADDRESS \
			-maxprocs=$MAXDAEMONS -maxperip=$MAXPERIP \
			$TCPDOPTS \
			$SSLPORT $COURIERTLS -server -tcpd \
			        -user=courier \
				$libexecdir/courier/courierpop3login \
				$libexecdir/courier/courierpop3d ${MAILDIRPATH}"
	;;
stop)
	/usr/local/sbin/courierlogger -pid=$SSLPIDFILE -stop
	;;
restart)
	/usr/local/sbin/courierlogger -pid=$SSLPIDFILE -restart
	;;
esac
exit 0
