#!/bin/sh
# $Id: t-rsad-1.sh,v 1.1 2007/02/10 18:27:48 ca Exp $
# ----------------------------------------
# test RSAD, 550 after dot
# ----------------------------------------
#
# host on which to listen/to which to send
H=localhost
# port number to use
P=${MTA_SRVPORT:-1235}
ERRS=0
SRVL="smtps.log"
CLTL="smtpc.log"
rm -f $SRVL $CLTL
#

SRV=./smtps2
CLT=./smtpc2

# start SMTP server
$SRV -d 5 -9 -F 550 -i -l . -b $H:$P > $SRVL 2>&1 &
status=$?
SRVPID=$!
if [ "x$status" != "x0" ]
then
  echo "FAIL: cannot start server $status"
  exit $status
fi
sleep 3
if grep "ERROR" $SRVL > /dev/null
then
  echo "found ERROR in $SRVL"
  ERRS=`expr $ERRS + 1 `
fi

# send messages
if ${CLT} -9 -d 4 -R'd250@example2.tld' -R'd450@example4.tld' -r $H:$P > $CLTL 2>&1
then

  for L in ${SRVL} ${CLTL}
  do
    C=`grep -c '250 deferred' ${L}`
    if test X"${C}" = "X2"
    then
      :
    else
      cat $CLTL
      ERRS=`expr $ERRS + 1 `
    fi

    # must not exist
    for i in '353 RCPT status follows' '450 whatever' '250 final'
    do
      if grep "$i" ${L} >/dev/null
      then
        cat ${L}
        ERRS=`expr $ERRS + 1 `
      fi
    done

    # must exist
    for i in '550 Hmm'
    do
      if grep "$i" ${L} >/dev/null
      then
        :
      else
        cat ${L}
        ERRS=`expr $ERRS + 1 `
      fi
    done

  done

else
  cat ${CLTL}
  ERRS=`expr $ERRS + 1 `
fi

# ----------------
kill -TERM $SRVPID


if [ "$ERRS" = "0" ]
then
  exit 0
else
  echo "$ERRS error(s)"
  exit ${ERRS}
fi


syntax highlighted by Code2HTML, v. 0.9.1