#! /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
exec_prefix=/usr
bindir=${exec_prefix}/bin
libexecdir=/usr/libexec/courier-imap

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-ssl
. /etc/courier-imap/pop3d

case $1 in
start)
	LIBAUTHMODULES=""
	for f in `echo $AUTHMODULES`
	do
		LIBAUTHMODULES="$LIBAUTHMODULES /usr/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 ;
		exec_prefix=/usr ;
		bindir=${exec_prefix}/bin ;
		libexecdir=/usr/libexec/courier-imap ;
		. /etc/courier-imap/pop3d ; \
				. /etc/courier-imap/pop3d-ssl ; \
		TLS_PROTOCOL=$TLS_STARTTLS_PROTOCOL ; \
		export TLS_PROTOCOL ;
		/usr/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/libexec/courier-imap/couriertcpd -pid=$PIDFILE -stop
	if test -x ${libexecdir}/authlib/authdaemond
	then
		${libexecdir}/authlib/authdaemond stop
	fi
	;;
esac
exit 0
