! 30 Mar 89
!
! 30 Mar 89	Fixed message base creation to set 755 for new message
!		bases to get around SysV access() library routine bug.
!
!	Written by Terry R. Lambert
!
! bbsmail.cmd	The mail system for the bbs in bbs.cmd.  Messages
!		live at /usr/term/message/*/m.### where * is the
!		message base directory and ### is the message
!		number. on dos it is limited to 1000 (000-999) per
!		message base.  Messages take the folloing forms:

!		o	General messages	-to everyone
!		o	Sysop messages		-any with M_sysop|M_admin
!		o	Private messages	-specific person
!		o	multiple bases		-default is /general

!		Default "to" is general.  Private messages may be
!		protected from receipt by the general populace.  It
!		is suggested that private messages be sent only to
!		a persons full name, as aliases are not currently
!		required to be unique.


! Name:		retcan
! Parameters:	none
! Purpose:	give a "hit return to continue ,^C to cancel message"
!		returns the value entered in the variable x
proc retcan
	? "     [ Hit RETURN to continue, \^C to cancel ]"
	repeat
		setvar x chrin()
	until x="\r" | x="^c"
endproc

! Name:		send
! Parameters:	destination name
! Purpose:	allow generic "name only" interface to message base... the
!		flags "private" and "protected" (priv,prot) can be set or
!		passed to this routine, but are currently set here.  Note
!		that the "read" and "list" and "quick scan" options are
!		required to parse protection in any case.
proc send
	setvar isto "$1"
	setvar mfirst ""
	setvar mbpat mbase+"/m.*"
	setvar count 0
	setvar i ""
	for i in ($mbpat) do
		setvar count count+1
		if mfirst=""
			setvar mfirst right(i,len(i)-(len(mbpat)-1))
		endif
	endfor
	if count>=0
		if i=""
			setvar mlast ""
		else
			setvar mlast right(i,len(i)-(len(mbpat)-1))
		endif
		setvar this val(mlast)+1
		if this>999
			? "Message base full.  Contact sysop"
			? "by message in another base.  Thanks."
			return
		endif
		setvar thisun mbase+"/m."
		! add leading 0's (very important!)
		if len(str(this))<3
			setvar thisun thisun+left("000",3-len(str(this)))
		endif
		setvar thisun thisun+str(this)
		setvar isfrom alias
		if (access & (M_admin | M_sysop)) > 0
			? "Is this a message from SYSOP? (Y/N) ";
			do bbsio@yesno prot
			if prot
				setvar isfrom "SYSOP"
			endif
		endif

		setvar prot false
		if isto!="ALL"
			? "Is this a private message? (Y/N) ";
			do bbsio@yesno prot
			?
		endif
		if prot
			? "Password? (6 chars, will not echo) ";
			setvar llimit 6
			do bbsio@echoin passw false false
			setvar llimit dlimit
			?
		endif
		setvar date cdate(time())
		? "Subject? ";
		setvar llimit 60
		do bbsio@echoin subj true false
		setvar llimit dlimit
		?
		? "Message $(this)        Sent $(date)"
		? "From    $(isfrom)"
		? "To      $(isto)"
		? "Subject $(subj)"
		?
		fcreate 1,thisun
! message header (1st 3 lines) format:
! "-        subject8901234567890123456789012345678901234567890123456(60)"
! "MMM DD YY From-name01234567890123456(30)"
! "          to-name8901234567890123456(30)"
		if prot
			setvar x "+ $(passw) $(subj)"
		else
			setvar x "-        $(subj)"
		endif
		fwriteln 1,x
		setvar x "$(date)  $(isfrom)"
		fwriteln 1,x
		setvar x "          $(isto)"
		fwriteln 1,x
		? "Type your message, hit return on a blank line to end"
		repeat
			do bbsio@echoin mesg true false
			?
			if mesg!=""
				fwriteln 1,mesg
			endif
		until mesg=""
		fclose 1
	else
		? "Invalid operation"
	endif
endproc

! Name:		read
! Parameters:	message number
! Purpose:	provide a non-"front-ended" mail reading utility.  This
!		allows the specification or looping to this routine of
!		single, multiple, or wildcarded messages.  Note that the
!		default mbase (message base) *MUST* be set, so if this
!		routine is called prior to first entering the message base
!		normally (by "do mail"), then this variable must be set.
!		Although checking is done, you may not want the routine
!		reporting "no such message" if you forget to, or improperly,
!		specify which message base is to be called, so check FIRST!
proc read
	setvar flname "$1"
	?
	setvar num str(val(midstr(flname,pos(".",flname,1)+1,3)))
	if len(num)<3
		setvar num left("   ",3-len(num))+num
	endif
	if exists(flname)
		fopen 1,"$(flname)"
! message header (1st 3 lines) format:
! "-        subject8901234567890123456789012345678901234567890123456(60)"
! "MMM DD YY From-name01234567890123456(30)"
! "          to-name8901234567890123456(30)"
		freadln 1,x
		setvar prot left(x,1)
		setvar pass trim(midstr(x,3,6))
		setvar subj midstr(x,10,80)
		freadln 1,x
		setvar date left(x,9)
		setvar from trim(midstr(x,11,80))
		freadln 1,x
		setvar isto trim(toupper(midstr(x,11,80)))
		setvar flnm "$(fname) $(lname)"
		setvar count 4
		? "Message $(num)        Sent $(date)"
		if from=alias | from=flnm | from=fname | from=lname
			? "From    $(from) (You)"
		else
			? "From    $(from)"
		endif
		if isto=alias | isto=flnm | isto=fname | isto=lname | isto="ALL"
			? "To      $(isto) (You)"
		elseif isto="SYSOP" & (access & (M_sysop | M_admin)) > 0
			? "To      $(isto) (SYSOP)"
		elseif (access & (M_admin | M_sysop | M_ukill)) > 0
			? "To      $(isto)"
		else
			if prot="+" & (access & (M_admin | M_sysop | M_ukill)) = 0
		   ? "Not addressed to you.  What is the password? ";
				do bbsio@echoin pswr false false
				?
				if pswr!=pass
			    ? "Password incorrect... message skipped"
					fclose 1
					return
				endif
				setvar   count count+2
			endif
			? "To      $(isto)"
		endif
		? "Subject $(subj)"
		?
		freadln 1,x
		repeat
			? x
			setvar x chrdy()
			if x!=""
				switch
				case x="^C"
					?
					? "%%% CANCEL"
					setvar rd false
					fclose 1
					return
				case x="^N"
					?
					? "%%% NEXT MESSAGE"
					fclose 1
					return
				case x="^S"
					?
					? "%%% WAIT (\^Q to continue)"
					repeat
					until chrin()="^Q"
				endswitch
			endif
			setvar count count+1
			freadln 1,x
			if count>lcount and len(x)>0
				setvar count 0
				do bbsio@hitret
			endif
		until feof(1)
		fclose 1
	else
		? "No such message: $(msgno)"
	endif
endproc

! Name:		list
! Parameters:	selected single message number, as string
! Purpose:	list the headers of selected messages in default base "mbase"
!		excepting passworded messages, whose subject will appear as
!		"*PRIVATE*"
proc list
	if count+5>lcount
		setvar count 0
		do bbsio@hitret
		if x="^c"
			setvar rd false
			return
		endif
	endif
	setvar flname "$1"
	setvar num str(val(midstr(flname,pos(".",flname,1)+1,3)))
	if len(num)<3
		setvar num left("   ",3-len(num))+num
	endif
	if exists(flname)
		fopen 1,"$(flname)"
! message header (1st 3 lines) format:
! "-        subject8901234567890123456789012345678901234567890123456(60)"
! "MMM DD YY From-name01234567890123456(30)"
! "          to-name8901234567890123456(30)"
		freadln 1,x
		setvar prot left(x,1)
		setvar pass midstr(x,3,6)
		setvar subj midstr(x,10,80)
		freadln 1,x
		setvar date left(x,9)
		setvar from trim(midstr(x,11,80))
		freadln 1,x
		setvar isto trim(toupper(midstr(x,11,80)))
		setvar flnm "$(fname) $(lname)"
		? "Message $(num)        Sent $(date)"
		if from=alias | from=flnm | from=fname | from=lname
			? "From    $(from) (You)"
		else
			? "From    $(from)"
		endif
		if isto=alias | isto=flnm | isto=fname | isto=lname | isto="ALL"
			? "To      $(isto) (You)"
			? "Subject $(subj)"
		elseif isto="SYSOP" & (access & (M_sysop | M_admin)) > 0
			? "To      $(isto) (SYSOP)"
			? "Subject $(subj)"
		else
			if prot="+" & !(from=alias | from=flnm | from=fname | from=lname) & (access & (M_admin | M_sysop | M_ukill))=0
				? "To      *PRIVATE*"
				? "Subject *PRIVATE*"
			else
				? "To      $(isto)"
				? "Subject $(subj)"
			endif
		endif
		?
		fclose 1
		setvar count count+5
	else
		? "$x No such message."
		?
		setvar count count+2
	endif
endproc

! Name:		qlist
! Parameters:	selected single message number, as string
! Purpose:	list number and subject information for each message in "mbase"
!		...subject on passworded messages will appear "*PRIVATE*"
proc qlist
	if count>lcount
		setvar count 0
		do @retcan
		if x="^c"
			setvar rd false
			return
		endif
	endif
	setvar flname "$1"
	setvar num str(val(midstr(flname,pos(".",flname,1)+1,3)))
	if len(num)<3
		setvar num left("   ",3-len(num))+num
	endif
	if exists(flname)
		fopen 1,"$(flname)"
! message header (1st 3 lines) format:
! "-        subject8901234567890123456789012345678901234567890123456(60)"
! "MMM DD YY From-name01234567890123456(30)"
! "          to-name8901234567890123456(30)"
		freadln 1,x
		setvar prot left(x,1)
		setvar pass midstr(x,3,6)
		setvar subj midstr(x,10,80)
		freadln 1,x
		setvar date left(x,9)
		setvar from trim(midstr(x,11,80))
		freadln 1,x
		setvar isto trim(toupper(midstr(x,11,80)))
		setvar flnm "$(fname) $(lname)"
		fclose 1
		setvar x left(num+"   ",3)+":"
		if prot="+" & !(from=alias | from=flnm | isto=alias | isto=flnm | isto=fname | isto=lname) & (access & (M_admin | M_sysop | M_ukill))=0
			? "  $x *PRIVATE*"
		else
			if isto=alias | isto=flnm | isto=fname | isto=lname
				? "<";
			elseif isto="SYSOP" & (access & (M_sysop | M_admin)) > 0
				? "*";
			else
				? " ";
			endif
			if from=alias | from=flnm | from=fname | from=lname
				? ">";
			else
				? " ";
			endif
			? "$x $(subj)"
		endif
	else
		? "$(num) No such message."
	endif
	setvar count count+1
endproc

! Name:		getlims
! Parameters:	none
! Purpose:	Get string msgno with prompt for range/type/number as to
!		first and last and existance of messages
proc getlims
	setvar mfirst ""
	setvar mbpat mbase+"/m.*"
	setvar count 0
	setvar i ""
	for i in ($mbpat) do
		setvar count count+1
		if mfirst=""
			setvar mfirst right(i,len(i)-(len(mbpat)-1))
		endif
	endfor
	if count>0
		setvar mlast right(i,len(i)-(len(mbpat)-1))
	? "Message # $(str(val(mfirst)))-$(str(val(mlast))), range or *: ";
		setvar llimit 15
		do bbsio@echoin msgno true true
		setvar llimit dlimit
	else
		? "No messages are in this message base"
		setvar msgno ""
	endif
endproc

! Message menu... assumes the existance of a callin script or program... if
! none is present, then "return to main menu" option return to CLI (as with
! "term -x mail"

! This menu is reentrant, but not file-locked, therefore it should not be run
! in the same base by two processes on multi-user systems.

repeat
if !expert
	?
	?
	? "            [ Grapevine $(revno)                    Message Base ]"
	?
	setvar grk right(mbase,len(mbase)-8)	! remove 'message/'
	? "                Active base is $(grk)"
	?
	if !exists("$(mbase)/bulletin")
		? "            No bulletins this message base"
	else
		setvar fsec filedate("$(mbase)/bulletin")
		? "            Bulletins updated $(ctime(fsec)) $(cdate(fsec))"
	endif
	?
	? "             <B> Bulletins             <C> Change bases"
	? "             <K> Kill a message        <L> List message headers"
	? "             <N> New messages          <Q> Quick scan messages"
	? "             <R> Read messages         <S> Send messages"
	? "             <X> Exit to main menu"
! Next several lines are special case and must be accounted for in proc chkper
! as they allow for fully hidden commands.  Unless the user has permission, the
! following lines should not be executed.  Chkper should be called prior to the
! function title being displayed, and NONE of the function should be executed
! if auth or whatever boolean used is not true.  Current implimentation beeps,
! although this is easily forced by not allowing the "goodcmd" to be set, it
! may cause a user noticible lag, so best to do it this way if the bbs gets
! large enough for that to happen.
   if (access & (M_sysop | M_admin)) > 0
     ?
     ? "              Sysop functions only:"
     ?
     ? "If you are not Administrator, the following require ukill privileges"
     ? "             <M> Make a base           <D> Delete a base"
   endif
endif
?
if (access & (M_sysop | M_admin)) > 0
	? "B,C,K,L,N,Q,R,S,X, M,D: ";
else
	? "B,C,K,L,N,Q,R,S,X: ";
endif
repeat
	setvar count 0
	setvar goodcmd false
	setvar cmd toupper(chrin())
	switch
	case cmd="M"
		if (access & (M_admin))>0 | (access & (M_sysop | M_ukill))=(M_sysop | M_ukill)
			setvar goodcmd true
			? "Make a base"
			dimstr bses maxbase
			setvar bsnm 0
			setvar i ""
			for i in (message/*) do
				if isdir(i)
					setvar bsnm bsnm+1
					if bsnm<maxbase+1
						setvar bses[bsnm] i
						setvar grk str(bsnm)+" "+right("$i",len("$i")-8)
					endif
				endif
			endfor
			if bsnm>=maxbase
	? "You have $(maxbase) bases; You must delete one before adding another"
			else
				setvar llimit 16
				? "New message base name: ";
				do bbsio@echoin nbase true false
				setvar llimit dlimit
				if len(nbase)>0
					if exists("message/$(nbase)") | isdir("message/$(nbase)")
						?
						? "Cannot create\007"
					else
						mkdir message/$(nbase)
! System 5 won't let us read our own directories unless we have execute
! access.  This is due to standard library calling buggy access() routine.
						run chmod 755 message/$(nbase)
					endif
				endif
			endif
		endif
	case cmd="D"
		if (access & (M_sysop)) > 0 | (access & (M_sysop | M_ukill))=(M_sysop | M_ukill)
			? "Delete a base"
			dimstr bses maxbase
			setvar bsnm 0
			setvar i ""
			for i in (message/*) do
				if isdir(i)
					setvar bsnm bsnm+1
					if bsnm<maxbase+1
						setvar bses[bsnm] i
						setvar grk str(bsnm)+" "+right("$i",len("$i")-8)
						? "$(grk)"
					endif
				endif
			endfor
			if bsnm=0
				? "No message bases"
				do bbsio@hitret
			elseif bsnm=1
				? "Cannot delete last base"
				do bbsio@hitret
			else
				? "Which messages base to delete: ";
				repeat
					setvar llimit 2
					do bbsio@echoin mbs true true
					setvar llimit dlimit
					?
				until val(mbs)>0 & val(mbs)<=bsnm
				setvar num val(mbs)
				if opsys()>1		! All UNIX/Xenix
					run rm $(bses[num])/*.*
				elseif opsys()=1	! All MS-DOS
					run del $(bses[num])\*.*
				endif
				rmdir $(bses[num])
! change bases to lowest one left to avoid removing one we're in
				if num=1
					setvar num 2
				else
					setvar num 1
				endif
				setvar mbase bses[num]
			endif
			setvar goodcmd true
		endif
	case cmd="B"
		? "Bulletins"
		?
		if !exists("$(mbase)/bulletin")
			? "No bulletins this base"
			do bbsio@hitret
		else
			do bbsio@paginate "$(mbase)/bulletin"
			do bbsio@hitret
		endif
		setvar goodcmd true
!
!	Due to the "fast array" lookup table size (maxbase), system is limited
!	to maxbase message bases (forsale,etc), indicating a maximum of
!	maxbase * 1000 messages (a moderate amount, por que?)
!
	case cmd="C"
		? "Change bases"
		dimstr bses maxbase
		setvar dfltbase 1
		setvar bsnm 0
		setvar i ""
		for i in (message/*) do
			if isdir(i)
				setvar bsnm bsnm+1
				if bsnm<maxbase+1
					setvar bses[bsnm] i
					if toupper(right("$i",len("$i")-8))="GENERAL"
						setvar dfltbase bsnm
					endif
					setvar grk str(bsnm)+" "+right("$i",len("$i")-8)
					? "$(grk)"
				endif
			endif
		endfor
		if bsnm=0
			? "No message bases"
			do bbsio@hitret
		else
			? "Which messages base to goto (default = $(dfltbase))";
			repeat
				? ": ";
				setvar llimit 2
				do bbsio@echoin mbs true true
				if mbs=""
					setvar mbs "$(dfltbase)"
				endif
				setvar llimit dlimit
				?
			until val(mbs)>0 & val(mbs)<=bsnm
			setvar mbase bses[val(mbs)]
		endif
		setvar goodcmd true
	case cmd="K"
		? "Kill a message"
		setvar mfirst ""
		setvar mbpat mbase+"/m."
		setvar mbpat2 mbpat+"*"
		setvar count 0
		setvar i ""
		for i in ($mbpat2) do
			setvar count count+1
			if mfirst=""
			setvar mfirst right(i,len(i)-(len(mbpat2)-1))
			endif
		endfor
		if count>0
			setvar mlast right(i,len(i)-(len(mbpat2)-1))
			? "Which message? ($(mfirst)-$(mlast)) ";
			setvar llimit 3
			do bbsio@echoin msg true true
			setvar llimit dlimit
			?
			if len(msg)>0
				setvar msg mbpat+msg
				if exists(msg)
! message header (1st 3 lines) format:
! "-        subject8901234567890123456789012345678901234567890123456(60)"
! "MMM DD YY From-name01234567890123456(30)"
! "          to-name8901234567890123456(30)"
	fopen 1,"$msg"
	freadln 1,x
	setvar prot left(x,1)
	setvar pass midstr(x,3,6)
	setvar subj midstr(x,10,80)
	freadln 1,x
	setvar date left(x,9)
	setvar from trim(midstr(x,11,80))
	freadln 1,x
	setvar isto trim(toupper(midstr(x,11,80)))
	setvar flnm "$(fname) $(lname)"
	fclose 1
	if from=alias | from=flnm | from=fname | from=lname
		erase $msg
		? "Message killed."
	elseif isto=alias | isto=flnm | isto=fname | isto=lname
		erase $msg
		? "Message killed."
	elseif (access & (M_admin|M_ukill)) > 0
		erase $msg
		? "Message killed."
	elseif prot="+"
		? "...Not yours:  What is the password? ";
			do bbsio@echoin pswr false false
			?
			if left(pswr+"      ",6)!=pass
				? "Password incorrect... message intact"
				return
			endif
		erase $msg
		? "Message killed."
	else
		? "Only the sender or recipient may delete"
	endif	
					
				else
					? "No such message"
				endif
			endif
		endif
		setvar goodcmd true
	case cmd="L"
		? "List message headers"
		setvar count 0
		repeat
			?
			do @getlims
			setvar mbpat mbase+"/m."
			if msgno!=""
				?
				?
				if msgno="*"
					setvar mbpat2 mbpat+"*"
					setvar rd true
					setvar i ""
					for i in ($mbpat2) do
						if rd
							do @list "$i"
						endif
					endfor
				elseif pos("-",msgno,1)!=0
					setvar mbpat2 mbpat+"*"
		setvar mlo mbpat
		setvar mlo1 str(val(msgno))
		if len(mlo1)<3
			setvar mlo1 left("000",3-len(mlo1))+mlo1
		endif
		setvar mlo mlo+mlo1
		setvar mhi mbpat
		setvar mhi1 str(val(midstr(msgno,pos("-",msgno,1)+1,10)))
		if len(mhi1)<3
			setvar mhi1 left("000",3-len(mhi1))+mhi1
		endif
		setvar mhi mhi+mhi1
					setvar rd true
					setvar i ""
					for i in ($mbpat2) do
						if i>=mlo and i<=mhi and rd
							do @list "$i"
						endif
					endfor
				else
					if len(msgno)<3
						setvar msgno left("000",3-len(msgno))+msgno
					endif
					setvar mbpat2 mbpat+msgno
					setvar rd true
					setvar i ""
					for i in ($mbpat2) do
						do @list "$i"
					endfor
				endif
			endif
		until msgno=""
		setvar goodcmd true
	case cmd="N"
		? "List new messages"
		setvar count 0
		?
		setvar mbpat2 mbase+"/m.*"
		repeat
			? "Since? (MM/DD/YY) ";
			setvar llimit 8
			do bbsio@echoin since true true
			setvar llimit dlimit
			setvar v1 val(left(since,2))
			setvar v2 val(midstr(since,4,2))
			setvar v3 val(midstr(since,7,2))
			setvar gd true
			if len(since)<>8
				setvar gd false
			elseif midstr(since,3,1)!="/" | midstr(since,6,1)!="/"
				setvar gd false
			elseif v1<1 | v1>12
				setvar gd false
			elseif v2<1 | v2>31
				setvar gd false
			elseif v3<1 | v3>99
				setvar gd false
			endif
			if !gd
				?
				? "\007Bad date format.  Please re-enter"
			endif
		until gd
		?
		?
		setvar tnum atod(since+".00:00:00")
		setvar rd true
		setvar i ""
		for i in ($mbpat2) do
			if filedate("$i")>=tnum and rd
				do @list "$i"
			endif
		endfor
		do bbsio@hitret
		setvar goodcmd true
	case cmd="Q"
		? "Quick scan messages"
		setvar count 0
		repeat
			?
			do @getlims
			?
			setvar mbpat mbase+"/m."
			if msgno!=""
				setvar count 0
				? ">=from you, <=to you"
				?
				?
				if msgno="*"
					setvar mbpat2 mbpat+"*"
					setvar rd true
					setvar i ""
					for i in ($mbpat2) do
						if rd
							do @qlist "$i"
						endif
					endfor
				elseif pos("-",msgno,1)!=0
					setvar mbpat2 mbpat+"*"
		setvar mlo mbpat
		setvar mlo1 str(val(msgno))
		if len(mlo1)<3
			setvar mlo1 left("000",3-len(mlo1))+mlo1
		endif
		setvar mlo mlo+mlo1
		setvar mhi mbpat
		setvar mhi1 str(val(midstr(msgno,pos("-",msgno,1)+1,10)))
		if len(mhi1)<3
			setvar mhi1 left("000",3-len(mhi1))+mhi1
		endif
		setvar mhi mhi+mhi1
					setvar rd true
					setvar i ""
					for i in ($mbpat2) do
						if i>=mlo and i<=mhi and rd
							do @qlist "$i"
						endif
					endfor
				else
					if len(msgno)<3
						setvar msgno left("000",3-len(msgno))+msgno
					endif
					setvar mbpat2 mbpat+msgno
					setvar rd true
					setvar i ""
					for i in ($mbpat2) do
						do @qlist "$i"
					endfor
				endif
			endif
		until msgno=""
		setvar goodcmd true
	case cmd="R"
		? "Read messages"
		repeat
			?
			do @getlims
			setvar mbpat mbase+"/m."
			if msgno!=""
				?
				? "\^S=stop, \^Q=go, \^C=cancel, \^N=next"
				if msgno="*"
					setvar mbpat2 mbpat+"*"
					setvar rd true
					setvar i ""
					for i in ($mbpat2) do
						if rd
							do @read "$i"
						endif
					endfor
				elseif pos("-",msgno,1)!=0
					setvar mbpat2 mbpat+"*"
		setvar mlo mbpat
		setvar mlo1 str(val(msgno))
		if len(mlo1)<3
			setvar mlo1 left("000",3-len(mlo1))+mlo1
		endif
		setvar mlo mlo+mlo1
		setvar mhi mbpat
		setvar mhi1 str(val(midstr(msgno,pos("-",msgno,1)+1,10)))
		if len(mhi1)<3
			setvar mhi1 left("000",3-len(mhi1))+mhi1
		endif
		setvar mhi mhi+mhi1
					setvar rd true
					setvar i ""
					for i in ($mbpat2) do
						if i>=mlo and i<=mhi and rd
							do @read "$i"
						endif
					endfor
				else
					if len(msgno)<3
						setvar msgno left("000",3-len(msgno))+msgno
					endif
					setvar mbpat2 mbpat+msgno
					setvar rd true
					setvar i ""
					for i in ($mbpat2) do
						if rd
							do @read "$i"
						endif
					endfor
				endif
			endif
		until msgno=""
		setvar goodcmd true
	case cmd="S"
		? "Send messages"
		? "Who is the message to? (return to cancel)"
		setvar llimit 30
		do bbsio@echoin who true true
		setvar llimit dlimit
		?
		if len(who)>0
			do @send "$(who)"
		endif
		setvar goodcmd true
	case cmd="X"
		? "Exit to main menu"
		? "Exiting..."
		return 0
	endswitch
	if !goodcmd & !quiet
		? "\007";
	endif
until goodcmd
until false
? "mail.cmd: fatal error... you should NEVER get this far!"
quit
