#! @SHELL@
#
# Copyright 1998 - 2005 Double Precision, Inc.
# See COPYING for distribution information.


prefix=@prefix@
exec_prefix=@exec_prefix@
sbindir=@sbindir@
bindir=@bindir@
sysconfdir=@sysconfdir@

if test ! -f @sysconfdir@/imapd
then
	echo "@sysconfdir@/imapd does not exist, forgot make install-configure?"
	exit 1
fi

if test ! -f @sysconfdir@/imapd-ssl
then
	echo "@sysconfdir@/imapd-ssl does not exist, forgot make install-configure?"
	exit 1
fi

. @sysconfdir@/imapd
. @sysconfdir@/imapd-ssl

case $1 in
start)
	umask $IMAP_UMASK
	@ULIMIT@ $IMAP_ULIMITD
	@SETENV@ -i @SHELL@ -c " set -a ;
		prefix=@prefix@ ; \
		exec_prefix=@exec_prefix@ ; \
		sbindir=@sbindir@ ; \
		bindir=@bindir@ ; \
		. @sysconfdir@/imapd ; \
		. @sysconfdir@/imapd-ssl ; \
		PROXY_HOSTNAME=$PROXY_HOSTNAME ; \
		IMAP_TLS=1; \
		@courierlogger@ -pid=$SSLPIDFILE -start $SSLLOGGEROPTS \
		@sbindir@/couriertcpd -address=$SSLADDRESS \
			-maxprocs=$MAXDAEMONS -maxperip=$MAXPERIP \
			$TCPDOPTS \
			$SSLPORT $COURIERTLS -server -tcpd \
				@libexecdir@/courier/imaplogin \
				@bindir@/imapd ${MAILDIRPATH}"
	;;
stop)
	@courierlogger@ -pid=$SSLPIDFILE -stop
	;;
esac
exit 0
