
# If using qmail, uncomment the following line
#QMAIL=1

VUTAB=/etc/mail/virtusertable.db 

error=0
err_accum () {
    newerr="$1"
    if test "$newerr" -gt "$error"; then
	error="$newerr"
    fi
}

if test -s "$QMAIL"; then
    aliascheck --qmail -- "$RECIPIENT_LOCAL" > /dev/null && exit 0
    err_accum $?

else # sendmal
    aliascheck -- "$RECIPIENT_LOCAL" > /dev/null && exit 0
    err_accum $?

    if test -f "$VUTAB"; then
	aliascheck --map -- "$RECIPIENT" "$VUTAB" && exit 0
	err_accum $?

	aliascheck --map -- "@$RECIPIENT_HOST" "$VUTAB" && exit 0
	err_accum $?
    fi

fi

case "$error" in
    1)
	   reject user unknown
	   ;;
    0)
	   # Shouldn't happen
	   ;;
    *)
	   # To defer mail when alias file not readable, uncomment the
	   # following line:
	   #defer Temporary error processing alias file
	   ;;
esac
