#! /bin/sh
# $Id: pop3d-ssl.rc.in,v 1.11 2004/04/18 15:54:38 mrsam Exp $
#
# Copyright 1998 - 2003 Double Precision, Inc.
# See COPYING for distribution information.


prefix=/usr/local
exec_prefix=/usr/local
bindir=${exec_prefix}/bin
libexecdir=/usr/local/libexec

if test ! -f /etc/courier-imap/pop3d
then
	echo "/etc/courier-imap/pop3d does not exist, forgot make install-configure?"
	exit 1
fi

if test ! -f /etc/courier-imap/pop3d-ssl
then
	echo "/etc/courier-imap/pop3d-ssl does not exist, forgot make install-configure?"
	exit 1
fi


. /etc/courier-imap/pop3d
. /etc/courier-imap/pop3d-ssl

case $1 in
start)
	LIBAUTHMODULES=""
	for f in `echo $AUTHMODULES`
	do
		LIBAUTHMODULES="$LIBAUTHMODULES /usr/local/libexec/authlib/$f"
	done

	if test -x ${libexecdir}/authlib/authdaemond
	then
		/usr/bin/env - DEBUG_LOGIN="$DEBUG_LOGIN" ${libexecdir}/authlib/authdaemond start
	fi

	/usr/bin/env - /bin/sh -c " set -a ;
		prefix=/usr/local ;
		exec_prefix=/usr/local ;
		bindir=${exec_prefix}/bin ;
		libexecdir=/usr/local/libexec ;
		. /etc/courier-imap/pop3d ; \
		. /etc/courier-imap/pop3d-ssl ; \
		POP3_TLS=1; export POP3_TLS; \
		POP3_STARTTLS=NO; export POP3_STARTTLS; \
		POP3_TLS_REQUIRED=0; export POP3_TLS_REQUIRED; \
		/usr/local/libexec/couriertcpd -address=$SSLADDRESS \
			-stderrlogger=${exec_prefix}/sbin/courierlogger \
			-stderrloggername=pop3d-ssl \
			-maxprocs=$MAXDAEMONS -maxperip=$MAXPERIP \
			-pid=$SSLPIDFILE $TCPDOPTS \
			$SSLPORT $COURIERTLS -server -tcpd \
				${exec_prefix}/sbin/pop3login $LIBAUTHMODULES \
				${exec_prefix}/bin/pop3d ${MAILDIRPATH}"
	;;
stop)
	/usr/local/libexec/couriertcpd -pid=$SSLPIDFILE -stop
	if test -x ${libexecdir}/authlib/authdaemond
	then
		${libexecdir}/authlib/authdaemond stop
	fi
	;;
esac
exit 0
