#!/bin/sh
# $Id: t-ttm-1.sh,v 1.2 2007/08/02 04:57:40 ca Exp $
#
# ----------------------------------------
# test "talking to myself" error
# uses smtp1.sh
# ----------------------------------------
#
test -s stop && exit 1
#

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

ERRS=0
OK="t-ttm-1.ok"
OUT="t-ttm-1.out"

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

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

# create aliases
${CAT} > ${ALI} <<EOF
abuse:	local:
postmaster:	local:
user:	local:
sender: local:
EOF
# create map
rm -f ${ALIMAP}
${MM} < ${ALI}
rm -f ${MTMAP}

HOSTNAME=`../libmta/t-hostname -l -V 2>/dev/null`
GREET="250-${HOSTNAME}"

# ----------------------------------------
TEST=1
if echo "${SKIP} X" | ${GREP} -v " ${TEST} " > /dev/null
then
ERR=false
if ${SHELL} ${SD}/smtp1.sh -3 lmtpsock -Ssender@local.dom -Ruser@local.host -E 0 -X 0 -A 1 -Y "-g ${GREET}"
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:
<user@local.host>
Remote-MTA: 127.0.0.1

config error: mail loops back to me


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
  ERR=true
fi
if ${ERR}
then
   echo "$0: test ${TEST} failed"
   ERRS=`expr ${ERRS} + 1 `
   test X"${MTA_STOPONERROR}" != X && exit 1
   break
elif ${VERBOSE}
then
   echo "$0: test ${TEST} OK"
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