# $Id: 150-ezmlm-return 176 2005-01-04 19:18:37Z bruce $

################
# ezmlm-return #
################

if [ $SECT -eq 1 ]; then

  prompt "ezmlm-return:         "

  SENDER="${BNC}@$HOST"; export SENDER
  HOST="$HOST"; export HOST
  LOCAL="$LOC-return-1-$BNC=$HOST"; export LOCAL
  DEFAULT="1-$BNC=$HOST"; export DEFAULT
# we use 'du' because bounce handling is different in 0.31x and >=0.32
  BSIZE1=`${DU} "${DIR}/bounce"` || \
	{ ${ECHO} "du doesn't work"; exit 99; } 
  make_message | ${EZBIN}/ezmlm-return "${DIR}" || \
    [ "$?" -eq "99" ] || \
	{ ${ECHO} "failed to process normal bounce from non-sub" ; exit 100; }
  BSIZE2=`${DU} "${DIR}/bounce"`
  if [ "$BSIZE1" != "$BSIZE2" ]; then
	${ECHO} "failed to ignore non-subscriber bounce" ; exit 100
  fi
  ${EZBIN}/ezmlm-sub "${DIR}" "${BNC}@$HOST"
  make_message | ${EZBIN}/ezmlm-return "${DIR}" || \
    [ "$?" -eq "99" ] || \
	{ ${ECHO} "failed to process normal bounce from sub" ; exit 100; }
  BSIZE1=`${DU} "${DIR}/bounce"`
  if [ "$BSIZE1" = "$BSIZE2" ]; then
	${ECHO} "failed to note subscriber bounce" ; exit 100
  fi
  LOCAL="$LOC-digest-return-1-$BNC=$HOST"; export LOCAL
  DEFAULT="1-$BNC=$HOST"; export DEFAULT
  BSIZE1=`${DU} "${DIR}/digest/bounce"`
  make_message | ${EZBIN}/ezmlm-return $DLC "${DIR}" || \
    [ "$?" -eq "99" ] || \
	{ ${ECHO} "failed to process normal digest non-sub bounce" ; exit 100; }
  BSIZE2=`${DU} "${DIR}/digest/bounce"`
  if [ "$BSIZE1" != "$BSIZE2" ]; then
	${ECHO} "failed to ignore non-digest-subscriber bounce" ; exit 100
  fi
  ${EZBIN}/ezmlm-unsub "${DIR}" "${BNC}@$HOST"
  ${EZBIN}/ezmlm-sub "${DIR}/digest" "${BNC}@$HOST"
  make_message | ${EZBIN}/ezmlm-return $DLC "${DIR}" || \
    [ "$?" -eq "99" ] || \
	{ ${ECHO} "failed to proc. nl digest-subscriber bounce" ; exit 100; }
  BSIZE1=`${DU} "${DIR}/digest/bounce"`
  if [ "$BSIZE1" = "$BSIZE2" ]; then
	${ECHO} "failed to note digest-subscriber bounce" ; exit 100
  fi
  ${EZBIN}/ezmlm-sub "${DIR}" "${BNC}@$HOST"

  ${ECHO} "OK"

# as we exit, the bounce address is subscribed to both list and digest-list
# and is the SENDER

fi
