#!/bin/sh

. /etc/control.d/functions

CONFIG=/etc/dovecot/dovecot.conf
EXE=/etc/init.d/dovecot

sp="[[:space:]]"
start_section="${sp}\+client${sp}*{${sp}*#postfix${sp}*"
grep_section="${sp}*client${sp}+\{${sp}*#postfix${sp}*"
stop_section="${sp}*}${sp}*#postfix${sp}*"

new_summary "Dovecot auth server"

new_subst postfix \
	"^$grep_section$" \
	"/^#$start_section$/,/^#$stop_section$/ s,^#\(.*\),\1,"

new_subst none \
	"^#$grep_section$" \
	"/^$start_section$/,/^$stop_section$/ s,^\(.*\),#\1,"

new_help postfix "Enable auth socket for postfix, see smtpd(8)"
new_help none "Disable auth socket for postfix, see smtpd(8)"

is_builtin_mode "$*" ||
	[ "$*" != "`control_subst "$CONFIG" status`" ] || exit 0

control_subst "$CONFIG" "$*"

is_builtin_mode "$*" ||
	[ ! -x "$EXE" ] || "$EXE" condreload || exit 0
