#############
# ezmlm-get #
#############

prompt "ezmlm-get (index):    "

# blast digest recipient account with all these excerpts.
${EZBIN}/ezmlm-sub "$DIR" digest "${DIG}@$HOST"

# first ezmlm-get in the manager position:

# index1/get1/thread1 should bounce and will not be looked for
# index2 ... should be in DIG@HOST's inbox
# get3 - r format to DIG@HST
# get4 - n
# get5 - v
# get6 - x

qqclean
SENDER="${BNC}@$HOST"
LOCAL="$LIST-xxxx"
DEFAULT='xxxx'
echo "X-num: index1" > "$TMP"
${EZBIN}/ezmlm-get "$DIR" < "$TMP" >"$ERR" 2>&1 || \
	fatal " failed to exit 0 for non-recognized commands"
msgexists && \
	fatal " failed to abort on non-recognized commands"

# This should not give a digest
qqclean
LOCAL="$LIST-"
DEFAULT=''
${EZBIN}/ezmlm-get "$DIR" < "$TMP" >"$ERR" 2>&1 || \
	fatal " failed to exit 0 for list-@host"
msgexists && \
	fatal " failed to exit on list-@host"

# Make sure this address is not a subscriber
${EZBIN}/ezmlm-unsub "$DIR" "${SENDER}" >/dev/null 2>&1
${EZBIN}/ezmlm-unsub "$DIR" allow "${SENDER}" >/dev/null 2>&1
${EZBIN}/ezmlm-unsub "$DIR" digest "${SENDER}" >/dev/null 2>&1

qqclean
LOCAL="$LIST-index"
DEFAULT='index'
${EZBIN}/ezmlm-get -s "$DIR" < "$TMP" >"$ERR" 2>&1 && \
	fatal "-s failed to reject -index from non-sub"
msgexists && \
	fatal "-s delivered response to non-subscriber"

qqclean
${EZBIN}/ezmlm-get "$DIR" < "$TMP" >"$ERR" 2>&1
if [ "$?" -ne "99" ]; then
	fatal "failed to exit 99 after -index"
fi
msgexists || \
	fatal "No message delivered"
checkenv index "$LIST-return-@$HOST" "$SENDER"

qqclean
echo "X-num: index2" > "$TMP"
SENDER="${DIG}@$HOST"
${EZBIN}/ezmlm-get -s "$DIR" < "$TMP" >"$ERR" 2>&1
if [ "$?" -ne "99" ]; then
	fatal "-s failed to exit 99 after -index"
fi
msgexists || \
	fatal "No message delivered"
grep "index2" "$QQMSG" >/dev/null 2>&1 || \
	fatal "index2 failed to return"
checkenv index2 "$LIST-return-@$HOST" "$SENDER"

echo "OK"
