###############
# ezmlm-clean #
###############

  prompt "ezmlm-clean:          "

# clean1 should be silently removed (no -x).
# clean2 should result in a message
# clean3 should not since it's time hasn't come
# clean4 should be removed, but not result in a message since we use -R

  echo "Return-Path: <${DIG}@$HOST>" > "${DIR}/mod/pending/1"
  echo "X-num: clean1" >> "${DIR}/mod/pending/1"
  echo "Return-Path: <${DIG}@${HOST}>" > "${DIR}/mod/pending/2"
  echo "X-num: clean2" >> "${DIR}/mod/pending/2"
  echo "Return-Path: <${DIG}@$HOST>" > "${DIR}/mod/pending/1999999999"
  echo "X-num: clean3" >> "${DIR}/mod/pending/1999999999"

  chmod +x "${DIR}/mod/pending/2" "${DIR}/mod/pending/1999999999"

  qqclean
  ${EZBIN}/ezmlm-clean "$DIR" >"$ERR" 2>&1 ||
	fatal "failed first invocation"
  checkenv clean1 "$LIST-return-@$HOST" "$DIG@$HOST"
  if [ -r "${DIR}/mod/pending/1" ]; then
	fatal "failed to remove non-x moderation queue entry 1"
  fi
  if [ -r "${DIR}/mod/pending/2" ]; then
	fatal "failed to remove moderation queue entry 2"
  fi
  if [ ! -r "${DIR}/mod/pending/1999999999" ]; then
	fatal "removed mod queue entry 3 that wasn't due"
  fi

echo <<EOF > "${DIR}/mod/pending/4"
Return-Path: <${DIG}@$HOST>
X-num: clean4
EOF
  chmod +x "${DIR}/mod/pending/4"
  rm -f "$QQENV"
  ${EZBIN}/ezmlm-clean -R "$DIR" >"$ERR" 2>&1 ||
	fatal "-R failed"
  if [ -r  "${DIR}/mod/pending/4" ]; then
	fatal "failed to remove moderation queue entry 4"
  fi
  exists "$QQENV" \
  && fatal "second invocation of ezmlm-clean sent a message"

  grep "clean1" "$QQMSG".* >/dev/null 2>&1 && \
	fatal "removal of non-x mod queue entry 1 wasn't silent"
  grep "clean2" "$QQMSG".* >/dev/null 2>&1 || \
	fatal "failed to notify sender of mod queue entry 2 time out"
  grep "clean3" "$QQMSG".* >/dev/null 2>&1 && \
	fatal "notified sender about entry 3 even though it wasn't rejected"
  grep "clean4" "$QQMSG".* >/dev/null 2>&1 && \
	fatal "-R failed: notified sender about entry 3 rejection"

echo <<EOF > "${DIR}/mod/pending/5"
Return-Path: <${DIG}@$HOST>
X-num: clean5
EOF
  chmod +x "${DIR}/mod/pending/5"
  rm -f "$QQENV"
  echo > "$DIR"/noreturnposts
  ${EZBIN}/ezmlm-clean "$DIR" >"$ERR" 2>&1 ||
	fatal "-R failed"
  if [ -r  "${DIR}/mod/pending/5" ]; then
	fatal "failed to remove moderation queue entry 5 with noreturnposts"
  fi
  exists "$QQENV" \
  && fatal "third invocation of ezmlm-clean sent a message"

  echo "OK"
