#!/bin/sh
# $Id: t-rsad-2.sh,v 1.1 2007/02/11 03:57:38 ca Exp $
#
# ----------------------------------------
# test RSAD in smtpc; "global" status
# run smtp1.sh with different parameters
# ----------------------------------------
#
test -s stop && exit 1
#

SD=`dirname $0`
if test "${SD}" = "."
then
   SD=../chkmts
fi
. ${SD}/common.sh

I=""
ERRS=0
OK="t-rsad-2.ok"
OUT="t-rsad-2.out"
EDBROK="t-rsad-2.edbr.ok"

if test X"`uname`" != "XOSF1"
then
while getopts s:V FLAG
do
  case "${FLAG}" in
    s) SKIP="${SKIP} ${OPTARG}";;
    V) VERBOSE=true;;
  esac
done
shift `expr ${OPTIND} - 1`
fi

# cd to working directory for alias file!
cd ../qmgr || exit 1

if ../smtpc/smtpc -VVV | ${GREP} MTA_USE_RSAD >/dev/null
then
  :
else
  echo "SKIPPED: $0: smtpc not compiled with MTA_USE_RSAD"
  exit 0
fi

# create aliases
${CAT} > ${ALI} <<EOF
abuse:	local:
postmaster:	local:
user:	local:
sender: local:
alias1: user+alias1
aliase3: <553@local.dom>
553: local:
EOF
# create map
rm -f ${ALIMAP}
${MM} < ${ALI}
rm -f ${MTMAP}

# run some test programs

# ----------------------------------------
# temporary failure from SMTP sink for final dot
TEST=1
if echo "${SKIP} X" | ${GREP} -v " ${TEST} " > /dev/null
then

${CAT} > ${EDBROK} <<EOF
got transaction
	mail=<sender@local.dom>
	rcpts_tot=2
	rcpts_left=2
	rcpts_temp=2
	rcpts_perm=0
	state=451
	aqt_rcpts_ar=0
got recipient
	rcpt=<d551@local.host>
	aqr_rcpt_idx=0
	aqr_da_idx=0
	aqr_status=451
got recipient
	rcpt=<d452@local.host>
	aqr_rcpt_idx=1
	aqr_da_idx=0
	aqr_status=451
EOF

ERR=false
if ${SHELL} ${SD}/smtp1.sh -O ${EDBROK} -3 lmtpsock -Ssender@local.dom -Rd551@local.host -Rd452@local.host -i 10 -E 2 -X 0 -A 1 -s 10 -v 20 -Y '-9 -d 6 -F 451'
then
  if test -s ${B1}
  then
    ${VERBOSE} && echo "$0: test ${TEST}: ${B1} exists"
    ERR=true
  fi
else
  ${VERBOSE} && echo "$0: test ${TEST}: smtp1.sh failed"
  ERR=true
fi
if ${ERR}
then
   echo "$0: test ${TEST} failed"
   ERRS=`expr ${ERRS} + 1 `
   test X"${MTA_STOPONERROR}" != X && exit 1
fi
fi


# ----------------------------------------
# end
if test "${ERRS}" = "0"
then
  rm -f ${OK} ${OUT} ${EDBROK}
  exit 0
else
  echo "${ERRS} error(s)"
  exit 1
fi


syntax highlighted by Code2HTML, v. 0.9.1