#!/bin/sh
# $Id: t-rsad-1.sh,v 1.1 2007/02/11 03:57:38 ca Exp $
#
# ----------------------------------------
# test RSAD in smtps; doesn't work (yet)
# 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-1.ok"
OUT="t-rsad-1.out"
EDBROK="t-rsad-1.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

# ----------------------------------------
# permanent failure from SMTP sink for final dot; create a bounce; check content
TEST=1
if echo "${SKIP} X" | ${GREP} -v " ${TEST} " > /dev/null
then
ERR=false
if ${SHELL} ${SD}/smtp1.sh -3 lmtpsock -Ssender@local.dom -Rd551@local.host -Rd552@local.host -i 10 -E 2 -X 0 -A 1 -s 10 -v 20 -Y '-9 -d 6 -F 550'
then
  if test -s ${B1}
  then
     ${EGREP} -v '^Date: ' ${B1} |\
	 ${SED} -e '/^Received:/,$d' \
		-e 's/
$//' -e 's/Mailer-Daemon@.*/Mailer-Daemon@/' > ${OUT}

     ${CAT} > ${OK} <<EOF
Return-Path: <>
From: Mailer-Daemon@
Subject: Undeliverable mail
To: <sender@local.dom>

${DSN_ERR}

Recipient:
<d551@local.host>
Remote-MTA: 127.0.0.1
Reason:
550 Hmm
during final dot

Recipient:
<d552@local.host>
Remote-MTA: 127.0.0.1
Reason:
550 Hmm
during final dot


Your original mail follows:
EOF
    if ${DIFF} -w ${OK} ${OUT} >/dev/null
    then
      :
    else
      ${VERBOSE} && echo "$0: test ${TEST}: diff"
      ERR=true
    fi
  else
      ${VERBOSE} && echo "$0: test ${TEST}: missing ${B1}"
     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
  exit 0
else
  echo "${ERRS} error(s)"
  exit 1
fi


syntax highlighted by Code2HTML, v. 0.9.1