#! /bin/sh
# $Id: imapd.rc.in,v 1.12 2000/10/05 04:15:41 mrsam Exp $
#
# Copyright 1998 - 2000 Double Precision, Inc.
# See COPYING for distribution information.


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

. ${prefix}/etc/imapd.config
. ${prefix}/etc/imapd-ssl.config

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 - ${libexecdir}/authlib/authdaemond start
	fi

	ulimit -d $IMAP_ULIMITD
	/usr/bin/env - /bin/sh -c " . ${prefix}/etc/imapd.config ; \
				. ${prefix}/etc/imapd-ssl.config ; \
		IMAP_STARTTLS=$IMAPDSTARTTLS ; export IMAP_STARTTLS ; \
		`sed -n '/^#/d;/=/p' <${prefix}/etc/imapd.config | \
			sed 's/=.*//;s/^/export /;s/$/;/'`
		`sed -n '/^#/d;/=/p' <${prefix}/etc/imapd-ssl.config | \
			sed 's/=.*//;s/^/export /;s/$/;/'`
		/usr/local/libexec/courier-imap/couriertcpd -address=$ADDRESS \
			-stderrlogger=/usr/local/libexec/courier-imap/logger \
			-maxprocs=$MAXDAEMONS -maxperip=$MAXPERIP \
			-pid=$PIDFILE $TCPDOPTS \
			$PORT ${exec_prefix}/sbin/imaplogin $LIBAUTHMODULES \
				${exec_prefix}/bin/imapd Maildir"
	;;
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
