#!/bin/sh
# $Id: t-mts-discard-0.sh,v 1.3 2006/10/05 01:41:51 ca Exp $
# Copyright (c) 2006 Claus Assmann
#
# By using this file, you agree to the terms and conditions set
# forth in the license/LICENSE.3C file which can be found at the
# top level of this source code distribution.
#
# ----------------------------------------
# test access map restrictions: discard
# uses smtp1.sh.
# ----------------------------------------
#
test -s stop && exit 1
#

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

SCRIPTS=`cd ${SD} && pwd`
SRCOK="../qmgr/t-mts-discard-0.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 right directory (where the programs will be executed).
cd ../qmgr || exit 1

# create restrictions
${CAT} > ${ACC} <<EOF
to:no@such.dom	discard
from:@.biz	discard
EOF
# create map
rm -f ${ACCMAP}
${MM} -t'	' -F ${ACCMAP} < ${ACC}

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

${CAT} > ${MT} <<EOF
local.host	lmtp:
other.host	[127.0.0.1]
EOF

# ----------------------------------------
# from biz
TEST=1
if echo "${SKIP} X" | ${GREP} -v " ${TEST} " > /dev/null
then
if ${SHELL} ${SCRIPTS}/smtp1.sh -Z 'smtpc2' -c '-E' -V '-a' -E 0 -A 1 -X 0 $@ -S"a@b.biz" -R"user@other.host"
then
    ERR=false
    ${VERBOSE} && echo "test ${TEST} succeeded"
else
    echo "$0: test ${TEST} failed"
    ERR=true
    test X"${MTA_STOPONERROR}" != X && exit 1
fi
if ${ERR}
then
    echo "$0: test ${TEST} check failed"
    ERRS=`expr ${ERRS} + 1 `
    test X"${MTA_STOPONERROR}" != X && exit 1
fi
fi

# ----------------------------------------
# to no@such.dom
TEST=2
if echo "${SKIP} X" | ${GREP} -v " ${TEST} " > /dev/null
then
if ${SHELL} ${SCRIPTS}/smtp1.sh -Z 'smtpc2' -c '-E' -V '-a' -E 0 -A 1 -X 0 $@ -S"user@other.host" -R"no@such.dom"
then
    ERR=false
    ${VERBOSE} && echo "test ${TEST} succeeded"
else
    echo "$0: test ${TEST} failed"
    ERR=true
    test X"${MTA_STOPONERROR}" != X && exit 1
fi
if ${ERR}
then
    echo "$0: test ${TEST} check failed"
    ERRS=`expr ${ERRS} + 1 `
    test X"${MTA_STOPONERROR}" != X && exit 1
fi
fi


# ----------------------------------------
rm -f ${ACCMAP}

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


syntax highlighted by Code2HTML, v. 0.9.1