#!/bin/bash

#
# This add sieve to /etc/services
#

if [ `grep sieve /etc/services | wc -l` = 0 ]
then
	echo "#			AFP548.com Sieve" >> /etc/services
	echo "sieve		2000/tcp # sieve" >> /etc/services
fi

#
# This add saslauthd to /etc/watchdog.conf
#

if [ `grep saslauthd /etc/watchdog.conf | wc -l` = 0 ]
then
	echo "saslauthd:respawn:/usr/local/saslauthd -a PAM # saslauthd for use with sieve" >> /etc/watchdog.conf
fi

chown :mail /usr/lib/sasl2/pwauxprop*
chmod 705 /usr/lib/sasl2/pwauxprop*

if [ ! -d /usr/sieve ]
then
	mkdir /usr/sieve
fi

chown cyrus /usr/sieve

mkdir -p /var/state/saslauthd
chown cyrus /var/state/saslauthd

cp /etc/pam.d/sshd /etc/pam.d/sieve

killall saslauthd 2>/dev/null
/usr/local/saslauthd -a PAM 2>/dev/null
