#!/bin/sh

if [ -z $SDDIR ]; then
    SDDIR=/etc/statusd
fi

# Number of messages
ERR1=100
ERR2=1000
ERR3=10000

DEFER=/var/spool/postfix-out/deferred

if [ -f $SDDIR/config/mailq-out.conf ]; then
    . $SDDIR/config/mailq-out.conf
fi

msgnum=`find $DEFER/ -type f |wc -l`

if [ $msgnum -gt $ERR1 ]; then

	if [ $msgnum -gt $ERR1 ]; then ERR=$ERR1; fi
	if [ $msgnum -gt $ERR2 ]; then ERR=$ERR2; fi
	if [ $msgnum -gt $ERR3 ]; then ERR=$ERR3; fi

	echo "$ERR+ deferred"
	exit 2
else
	echo "OK"
	exit 0
fi
