#!/usr/pkg/bin/bash
PATH=/usr/pkg/bin:/bin:/usr/bin:/usr/local/bin
[ "$DKQUEUE" ] || DKQUEUE=/var/qmail/bin/qmail-queue
# Check to see if DKVERIFY is defined
if [ "${DKVERIFY+x}" ] ; then
	tmp=`mktemp -t dk.verify.XXXXXXXXXXXXXXXXXXX`
	cat - >"$tmp"
	# dktest -v <"$tmp" 2>/dev/null | awk 'NR==2';
	( \
	dkimverify.pl <"$tmp" 2>/dev/null | sed 's/\r//'; \
	[ "$TCPREMOTEIP" ] && printf 'X-Originating-IP: '$TCPREMOTEIP'\n' ; \
	cat "$tmp" ) | \
		$DKQUEUE "$@"
	retval=$?
	rm "$tmp"
	exit $retval
else
	# No verification done
	exec $DKQUEUE "$@"
fi
