###############
# ezmlm-store #
###############

  prompt "ezmlm-store:          "

  SENDER="${SND}@$HOST"
  ${EZBIN}/ezmlm-sub "$DIR" mod "$SENDER"
  ${EZBIN}/ezmlm-sub "$DIR" "subscriber@$HOST"

# message from mod, normal use -> should queue
  qqclean
  { echo "X-num: mod1"; make_message; } > ${TMP};
	${EZBIN}/ezmlm-store "$DIR" >"$ERR" 2>&1 < ${TMP} || \
	fatal "failed to process message 1"
  checkenv mod1 "$LIST-return-@$HOST" "$SENDER"

  cat ${DIR}/mod/pending/* | grep "mod1" > /dev/null || \
	fatal "failed to queue message 1"

  REJ=`grep "From: $LIST-reject" "$QQMSG" | cut -d' ' -f2`
  if [ -z "$REJ" ]; then
	fatal "No From: ...-reject header in mod request for mod1"
  fi

  rm -f "${DIR}/modpost" 
#
# no modpost - should go directly to list
  qqclean
  { echo "X-num: mod2"; make_message; } > ${TMP};
	${EZBIN}/ezmlm-store "$DIR" >"$ERR" 2>&1 < ${TMP} || \
	{
	  grep -v "child" "$ERR" > /dev/null 2>&1
	  if [ "$?" != "0" ]; then
	    fatal "Failed to process message mod2"
	  else
	    EZFORK='no'
	  fi
	}
  checkenv mod2 "$LIST-return-.*@$HOST-@\\[\\]" "subscriber@$HOST"

  cat ${DIR}/mod/pending/* | grep "mod2" > /dev/null && \
	fatal "queued message 2 despite non-modpost"

  if [ -z "$EZFORK" ]; then
	cat ${DIR}/archive/0/* | grep "mod2" > /dev/null || \
		fatal "failed to archive message 2 (non-modpost)"
  fi

  touch "${DIR}/modpost"

# from moderator. Should be queued, even with -P
  qqclean
  { echo "X-num: mod3"; make_message; } > ${TMP};
	${EZBIN}/ezmlm-store -P "$DIR" >"$ERR" 2>&1 < ${TMP} || \
	fatal "-P failed to accept mods post 3"
  checkenv mod3 "$LIST-return-@$HOST" "$SENDER"

  cat ${DIR}/mod/pending/* | grep "mod3" > /dev/null || \
	fatal "failed to queue message 3"

  ACC=`grep "Reply-To: $LIST-accept" "$QQMSG" | cut -d' ' -f2`
  if [ -z "$ACC" ]; then
	fatal "No From: ...-accept header in mod request for mod3"
  fi

  qqclean
  touch "$DIR"/modpostonly
  { echo "X-num: mod4"; make_message; } > ${TMP};
	${EZBIN}/ezmlm-store  "$DIR" >"$ERR" 2>&1 < ${TMP} || \
	fatal "modpostonly failed to accept mods post 4"
  checkenv mod4 "$LIST-return-@$HOST" "$SENDER"
  rm "$DIR"/modpostonly

  ${EZBIN}/ezmlm-unsub "$DIR" mod "$SENDER"

# not from moderator, should be rejected directly with -P
  qqclean
  { echo "X-num: mod5"; make_message; } > ${TMP};
	${EZBIN}/ezmlm-store -P "$DIR" >"$ERR" 2>&1 < ${TMP} && \
	fatal "-P failed to reject non-mod message 5"

  test -s "$QQMSG" && \
	fatal "ezmlm-store: -P failed to reject message from non-mod"

# not from moderator, should be rejected directly with -P
  qqclean
  touch "$DIR"/modpostonly
  { echo "X-num: mod6"; make_message; } > ${TMP};
	${EZBIN}/ezmlm-store "$DIR" >"$ERR" 2>&1 < ${TMP} && \
	fatal "modpostonly failed to reject non-mod message 6"
  rm "$DIR"/modpostonly

  test -s "$QQMSG" && \
	fatal "ezmlm-store: modpostonly failed to reject message from non-mod"

  ${EZBIN}/ezmlm-unsub "$DIR" "subscriber@$HOST"

  echo "OK"
