#!/bin/sh

if [ -z "$2" ]; then
  echo "Usage: $0 host port [flood_count] [client_address]"
  echo "       Use flood_count=-1 for infinite loops."
  exit
fi

test() {
if [ "$1" ]; then
  IP="$1"
else
  IP="10.20.$(($RANDOM/256)).$(($RANDOM/256))"
fi
#echo $IP >&2
cat << EOF
request=smtpd_access_policy
protocol_state=RCPT
protocol_name=SMTP
helo_name=some.domain.tld
queue_id=8045F2AB23
sender=foo@bar.tld
recipient=bar@foo.tld
recipient_count=0
client_address=$IP
client_name=another.domain.tld
reverse_client_name=another.domain.tld
instance=123.456.7

EOF
}

if [ "$3" ]; then
  cntr=$3
else
  cntr=1
fi

while [ $cntr -ne 0 ]; do
  test $4
  cntr=`expr $cntr - 1`
done \
  | nc $1 $2 \
  #| grep -v -e '^$' -e '^action=dunno'
