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


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

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

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

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

case $1 in
start)
	LIBAUTHMODULES=""
	for f in `echo $AUTHMODULES`
	do
		LIBAUTHMODULES="$LIBAUTHMODULES /usr/local/libexec/courier-imap/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/courier-imap ;
		. /usr/local/etc/courier-imap/pop3d ; \
				. /usr/local/etc/courier-imap/pop3d-ssl ; \
		TLS_PROTOCOL=$TLS_STARTTLS_PROTOCOL ; \
		export TLS_PROTOCOL ;
		/usr/local/libexec/courier-imap/couriertcpd -address=$ADDRESS \
			-stderrlogger=${exec_prefix}/sbin/courierlogger \
			-stderrloggername=pop3d \
			-maxprocs=$MAXDAEMONS -maxperip=$MAXPERIP \
			-pid=$PIDFILE $TCPDOPTS \
			$PORT ${exec_prefix}/sbin/pop3login $LIBAUTHMODULES \
				${exec_prefix}/bin/pop3d ${MAILDIRPATH}"
	;;
stop)
	/usr/local/libexec/courier-imap/couriertcpd -pid=$PIDFILE -stop
	if test -x ${libexecdir}/authlib/authdaemond
	then
		${libexecdir}/authlib/authdaemond stop
	fi
	;;
esac
exit 0
