#! /bin/sh
# $Id: imapd.rc.in,v 1.14 2001/01/28 18:52:49 mrsam Exp $
#
# Copyright 1998 - 2000 Double Precision, Inc.
# See COPYING for distribution information.


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

. /etc/courier-imap/imapd
. /etc/courier-imap/imapd-ssl

case $1 in
start)
	LIBAUTHMODULES=""
	for f in `echo $AUTHMODULES`
	do
		LIBAUTHMODULES="$LIBAUTHMODULES ${exec_prefix}/libexec/authlib/$f"
	done

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

	ulimit -d $IMAP_ULIMITD
	/usr/bin/env - /bin/sh -c " . /etc/courier-imap/imapd ; \
				. /etc/courier-imap/imapd-ssl ; \
		IMAP_STARTTLS=$IMAPDSTARTTLS ; export IMAP_STARTTLS ; \
		`sed -n '/^#/d;/=/p' </etc/courier-imap/imapd | \
			sed 's/=.*//;s/^/export /;s/$/;/'`
		`sed -n '/^#/d;/=/p' </etc/courier-imap/imapd-ssl | \
			sed 's/=.*//;s/^/export /;s/$/;/'`
		${exec_prefix}/libexec/couriertcpd -address=$ADDRESS \
			-stderrlogger=${exec_prefix}/libexec/logger \
			-stderrloggername=imapd \
			-maxprocs=$MAXDAEMONS -maxperip=$MAXPERIP \
			-pid=$PIDFILE $TCPDOPTS \
			$PORT ${exec_prefix}/sbin/imaplogin $LIBAUTHMODULES \
				${exec_prefix}/bin/imapd Maildir"
	;;
stop)
	${exec_prefix}/libexec/couriertcpd -pid=$PIDFILE -stop
	if test -x ${libexecdir}/authlib/authdaemond
	then
		${libexecdir}/authlib/authdaemond stop
	fi
	;;
esac
exit 0
