/* NVX REAL E-MAIL (REM) Fame/Ami-Express door V1.2a */
/* (c)1997 Jeremy Hagon */

/* ***************************************************************** */
/* ************************* CONFIGURATION PART ******************** */
/* ***************************************************************** */
parse arg node
options results
address value 'AERexxControl'node
r=d2c('10'); c=d2c('13'); cr=r||c
tr=transmit;qu=query;sm=sendmessage;gc=getchar;gu=getuser
signal on ioerr; signal on halt; signal on error; signal on syntax; signal on BREAK_C
cls  = d2c('12'); lok=0
back = '08'x; d=0
getuser 131; type=upper(result)
getuser 11; bbstitle=result
getuser 12; sysopname=upper(result)
getuser 149; nodeid=result
getuser 100; username=result
fop=0
klooper=0

/* ***************************************************************** */
/* ******************** MAIN PART / MENU SELECTION ***************** */
/* ***************************************************************** */
main:
if ~exists("remail:bbsaddress.cfg") then do
	tr "ERROR!!! REMAIL:bbsaddress.cfg file is missing!"
	tr "Should contain your internet address ie: @laluna.keme.co.uk"
	tr ""
	shutdown; exit; end
open(y,"remail:bbsaddress.cfg","R")
bbsemail=readln(y)
close(y)
start:
if ~exists("remail:user.num") then do
	open(i,"remail:user.num","W")
	y=writeln(i,"0")
	close(i); end
open(cfg,"remail:user.num","R")
	n=readln(cfg)
close(cfg)
if ~exists("remail:user.list") then do 
	open(i,"remail:user.list","W")
	y=writeln(i)
	close(i); end
open(cfg,"remail:user.list","R")
do a=1 to n
	o.a=readln(cfg)
	emailname.a=readln(cfg)
	if o.a=username then do; close(cfg); signal ok; end
	if a=n & o.a~=username then do; close(cfg); signal makenew; end
end
close(cfg)

/* ***************************************************************** */
/* ****************** SHOW ADDRESS NAME & GIVE OPTIONS ************* */
/* ***************************************************************** */
ok:
emailname=emailname.a
open(tag,"remail:"emailname"/tagline.dat","R")
	nik=readln(tag)
	tagline=readln(tag)
close(tag)
if ~exists("remail:"emailname"/sent.dat") then do; open(loo,"remail:"emailname"/sent.dat","W"); o=writeln(loo,0); close(loo); end
open(loo,"remail:"emailname"/sent.dat","R")
	st=readln(loo)
	snt=right(st,4,0)
close(loo)
if ~exists("remail:"emailname"/rec.dat") then do; open(loo,"remail:"emailname"/rec.dat","W"); o=writeln(loo,0); close(loo); end
open(loo,"remail:"emailname"/rec.dat","R"); o=readln(loo); close(loo)
rcvd=right(o,4,0)

if ~exists("remail:"emailname"/expert.dat") then do; open(loo,"remail:"emailname"/expert.dat","W"); o=writeln(loo,0); close(loo); end
open(loo,"remail:"emailname"/expert.dat","R"); expert=readln(loo); close(loo)

if type="EMAILS" then do; klooper=1; mailscan=0; signal check; end
mailscan=1
call check
mailscan=0
oldmail=0
m=1
if fop=1 then do; signal read; end
if fop=2 then do; tr ""||cr; shutdown; exit; end
reload:
if expert="1" then do; signal yule; end
reloadi:
SHOWFILE "remail:TITLE.TXT"
tr "              [34m([0;33m1[34m) [36mEnter E-Mail Message[0m      [44m[33m  Mail Waiting: "||right(cnt,4,0)"  [0;0m"
tr "              [34m([0;33m2[34m) [36mRead E-Mail[0m"
tr "              [34m([0;33m3[34m) [36mAdd To Address Book[0m       [44m[33m  Mail Sent:    "||snt||"  [0;0m"
tr "              [34m([0;33m4[34m) [36mEdit Personal Details[0m"
tr "              [34m([0;33m5[34m) [36mShow User List[0m            [44m[33m  Mail Read:    "||rcvd||"  [0;0m"
tr ""
tr "              [34m([0;33mX[34m) [36mToggle Expert Mode[0m"
tr "              [34m([0;33mI[34m) [36mVersion Info[0m"
tr "              [34m([0;33mQ[34m) [36mQuit![0m"
tr ""
tr center("[44;32m Your EMail address is: [33m"||nik||" <"emailname""bbsemail"> [0;0m",98)||cr
tr center("[44;32m Your tag line reads: [33m"tagline" [0;0m",98)||cr
yule:
tr ""
receive 1; query "[35m"bbstitle" Node "nodeid"[33m << [0mInternet Email [33m>> [0m"; where=upper(result)
if where=1 then do; signal enter; end
if where=2 then do; signal read; end
if where=3 then do; signal addressedit; end
if where=4 then do; signal edittagline; end
if where=5 then do; signal showlist; end
if where="Q" then do; tr ""; tr "[0mThank you for using the "bbstitle" EMail service."; tr ""; shutdown; exit; end
if where="G" then do; tr ""; tr "[0mThank you for using the "bbstitle" EMail service."; tr ""; shutdown; exit; end
if where="" then do; signal reload; end
if where="?" then do; signal reloadi; end
if where="#" then do; signal reloadi; end
if where="X" then do; signal swapover; end
if where="I" then do; signal infoscreen; end
tr cr||"Unknown Command. Use [33m?[0m/[33m#[0m to list available Commands!"
signal yule
end

infoscreen:
tr cls
tr "REM: ""REAL E-MAIL"" door for Fame/Ami-Express BBS systems Version 1.2a"
tr "[33m"
tr " -REM (c)1996, Jeremy Hagon. (nEELIx - La Luna BBS/NVX)"
tr " -YAM (c)1995, Marcel Beck."
tr " -MUI (c)1996, Stefan Stuntz."
tr "[35m"
tr "For further information please leave E-Mail: neelix@laluna.keme.co.uk"
tr "or leave the SysOp a comment by using the door command ""C""!"
tr "[0m"
signal yule

swapover:
if expert=0 then do; ex=1; tr cr||"Expert mode on!"; end
if expert=1 then do; ex=0; tr cr||"Expert mode off!"; end
open(loo,"remail:"emailname"/expert.dat","W")
oo=writeln(loo,ex)
close(loo)
expert=ex
signal reload

showlist:
tr cls
tr "[36m"bbstitle" Internet E-Mail addresses.[0m"
tr ""
open(yh,"remail:user.list","R")
do until ut=""
	ut=left(readln(yh),15)
	if ut=" " then do; signal juice; end
	utt=readln(yh); in=utt||bbsemail
sm "    [33mUser: [35m"||ut||"  [33mEMail Adr.: [35m"||left(in,40, )||cr
end
juice: 
close(yh)
pause:
sm "                                                                     "||cr
sm "[33m<[32mPress a Key to Continue[0m![33m>"; getchar; tr cr; signal reload

/* ***************************************************************** */
/* ****************** ADD A NEW USER TO THE EMAIL LIST ************* */
/* ***************************************************************** */
makenew:
tr username||", your EMail account is not set up..."
receive 20; query "[33mPlease enter a nik name[34m: [0m";nikname=(result)
if nikname="" then signal makenew
receive 20; query "[33mPlease enter an EMail name[34m: [0m"; emailname=(result)
if emailname="" then signal makenew
tagen:
receive 45; query "[33mPlease enter a Tag Line   [34m: [0m"; tagline=(result)
if tagline="" then signal tagen
address command "makedir remail:"emailname""
open(cfg,"remail:user.list","A")
	x=writeln(cfg,username)
	x=writeln(cfg,emailname)
close(cfg)
open(tag,"remail:"emailname"/tagline.dat","W")
	t=writeln(tag,nikname)
	t=writeln(tag,tagline)
close(tag)
open(cfg,"remail:user.num","R")
	yy=readln(cfg)
close(cfg)
open(cfg,"remail:user.num","W")
	xx=writeln(cfg,(yy+1))
close(cfg)
open(loo,"remail:"emailname"/sent.dat","W"); o=writeln(loo,0); close(loo)
open(loo,"remail:"emailname"/rec.dat","W"); o=writeln(loo,0); close(loo)
signal main

/* ***************************************************************** */
/* **************** ENTER MAIL ROUTINE AND SAVE TO SENDER ********** */
/* ***************************************************************** */
enter:
noaddress=0
poop=0
tr ""
SHOWFILE "remail:TITLE.TXT"
tr "                                 [36m[[0m-----------------------------------------(45)[36m][0m"
receive 45; query "Enter Msg To? [32m([36m?[32m)[0m=>[33mAddress Book[36m>[0m: "; towho=result
if towho="?" then call address
if noaddress="1" then do; signal enter; end
if towho="" then do; signal reload; end
if poop=1 then do
	tr ""
	tr "                                 [36m[[0m--------------------------------------------(45)[36m][0m"
	tr "Enter Msg To? [32m([36m?[32m)[0m=>[33mAddress Book[36m>[0m: "||towho
end
receive 45; query "Msg Subject?  [32m([36mEnter[32m)[0m=>[33mAbort...[36m>[0m: "; subject=result
if subject="" then do; signal reload; end
sm "Upload Msg?   [32m([36my[32m/[36mN[32m)            [36m>[0m: "; getchar; upload=upper(result)
if upload="Y" then do; sm "Yes!"; tr ""||cr; 
tr "                                  WARNING!!! "||cr
tr "                    MAKE SURE the file is called [35mEMAIL.TXT[0m"
tr "                       otherwise mail will not be sent!"
tr ""
sm "[33m<[32mPress a Key to Continue[0m![33m>"; getchar; tr cr
putustr "T:"; putuser 138
	if ~exists("t:email.txt") then do; signal reload; end
	address command "rename t:email.txt t:"username""
	signal flamer
end
if upload~="Y" then do; sm "NO!"; putustr "t:"username""; putuser 9; end

flamer:
	getuser 144; timex=result
open(c,"t:tempfile","W")
	u=writeln(c,"To: "towho)
	u=writeln(c,"From: "||nik||" <"||emailname||bbsemail||">")
	u=writeln(c,"Reply-To: "||nik||" <"||emailname||bbsemail">")
	u=writeln(c,"Date: "timex)
	u=writeln(c,"Subject: "subject)
	u=writeln(c,"Organisation: "bbstitle"")
	u=writeln(c,"X-Mailer: REM V1.2a (Real E-Mail) for FAME/Ami-Express (c)NVX 1997")
	u=writeln(c,"")
	u=writeln(c,"On "||timex||" a friend called "||username||" punched this out...")
	u=writeln(c,"")
close(c)
address command "type t:"username" >>t:tempfile"
address command "echo " " >>t:tempfile"
address command "echo "tagline" >>t:tempfile"
address command "type remail:bbstag.txt >>t:tempfile"

daft=right(date(I),5,0)

p=100
direc="outgoing"

loop:
if ~exists("yam:"||direc"/"daft||"."||p"") then do; signal ko; end
if exists("yam:"||direc"/"daft||"."||p"") then p=p+1
signal loop: 

ko:
address command "copy t:tempfile yam:"||direc||"/"||daft||"."||p""
address command "delete T:tempfile"
address command "delete t:"username""
if ~exists("remail:"emailname"/sent.dat") then do; open(loo,"remail:"emailname"/sent.dat","W"); o=writeln(loo,0); close(loo); end
open(sent,"remail:"emailname"/sent.dat","R")
	snt=readln(sent)
close(sent)
snt=snt+1
open(sent,"remail:"emailname"/sent.dat","W")
	st=writeln(sent,snt)
close(sent)
if hoho=1 then return
signal main

uploadmail:
putustr "t:"; putuser 138
return

edittagline:
/* ***************************************************************** */
/* *************************** EDIT TAG LINE *********************** */
/* ***************************************************************** */
open(tag,"remail:"emailname"/tagline.dat","R")
	nik=readln(tag)
	tagline=readln(tag)
close(tag)
tr ""
tr "Edit nik name and tag line:"
tr "---------------------------"
tr ""
changenik:
tr center("Your nik name reads: [33m"nik"[0m",88, )||cr
tr ""
sm "Change Nik name? (Y/N) "; getchar; u=upper(result)
	if u~="Y" then do; sm "NO!"; signal changetag; end
sm "Yes!"||cr
receive 20; query "     [33mPlease enter a new nik name  : [0m"; nik=(result)

changetag:
tr cr||cr
tr center("Your tag line reads: [33m"tagline"[0m",88, )||cr
tr ""
sm "Change Tagline? (Y/N) "; getchar; u=upper(result)
	if u~="Y" then do; sm "NO!"; signal writeback; end
sm "Yes!"||cr
tr ""
receive 45; query "     [33mPlease enter a Tag Line   [34m: [0m"; tagline=(result)
if tagline="" then do; sm "Abort!"; signal main; end

writeback:
open(tag,"remail:"emailname"/tagline.dat","W")
	t=writeln(tag,nik)
	t=writeln(tag,tagline)
close(tag)
signal main

check:
/* ***************************************************************** */
/* ***************************** MAIL CHECK ************************ */
/* ***************************************************************** */
info=emailname||bbsemail
m=0
mo=0
cnt=0
if mailscan=0 then do; tr "[0;0H"||cls; sm "[32mScanning for new E-Mail[0m "; end
if mailscan=1 then do; sm cr||"[36mChecking your E-Mail account "username" "; end
address command "dirsizer yam:incoming/ >ram:"||username||amount
sm "."
address command "list files nohead quick yam:incoming/ >ram:"username||xxx
open(am,"ram:"||username||amount,"R")
sm "."
	sexy=readln(am)
sm "."
if sexy="" then do; close(am); signal bye; end
if sexy="0" then do; close(am); signal bye; end
sm "."
close(am)
call open(i,"ram:"||username||xxx,"R")
sm "."
counter=1
dj:
	pp.q=readln(i)
	filex=pp.q
	call open(u,"yam:incoming/"filex"","R")
	do until lok.ii=""
		lok.ii=readln(u)
		qq=find(lok.ii,"<"||info||">")
		if qq~="0" & left(lok.ii,3)="To:" then do; type="Private"; m=1; call showdetails; end
		qr=lok.ii
		qt=find(qr,info",")
		if qt~="0" then do; type="Private"; m=1; call showdetails; end
		qtt=find(qr,"<"info">,")
		if qtt~="0" then do; type="Private"; m=1; call showdetails; end
		fileb=lok.ii
		if fileb="To: "||info||"" then do; type="Private"; m=1; call showdetails; end
		qqq=find(lok.ii,info)
		if qqq~="0" & left(fileb,3)="To:" then do; type="Private"; m=1; call showdetails; end
		filebb=lok.ii
		qqqq=find(filebb,"<"||info||">")
		if qqqq~="0" & left(filebb,1)=" " then do; type="Private"; m=1; call showdetails; end
		filebbb=lok.ii
		qqqqq=find(filebbb,info)
		if qqqqq~="0" & left(filebbb,1)=" " then do; type="Private"; m=1; call showdetails; end
		pqr=fileb
		pqrr=find(pqr,info||",")
		if pqrr~="0" then do; type="Private"; m=1; call showdetails; end
		pqrs=fileb
		pqrrr=find(pqrs,info)
		if pqrrr~="0" then do; type="Private"; m=1; call showdetails; end
		
end
	call close(u)
if counter=sexy then do; close(i); signal bye; end
counter=counter+1; signal dj

showdetails:
if mo=0 & mailscan=0 then do; sm "[0mfound!"; tr""; tr ""; tr "[36mType    From                      Subject                        Msg Number"
		 tr "[0m------- ------------------------- ------------------------------ ----------"
mo=1
end
	open(uu,"yam:incoming/"filex"","R")
	do until lok.ii=""
		lok.ii=readln(uu)
		fileb=lok.ii
		if left(fileb,6)="From: " then do; filed=right(left(fileb,31),25); ci=1; end
		if left(fileb,9)="Subject: " then do; filee=right(left(fileb,39),30); ci=ci+1; end
		if mailscan=0 & ci=2 then do; m=1; tr ""||type" [0m"||filed" "||filee||" "||right(counter,4,0); ci=0; end
	end
	close(uu)
	cnt=cnt+1
return


read:
/* ***************************************************************** */
/* *********************** MAIL READER & MAIL CHECK **************** */
/* ***************************************************************** */
rec=0
delete=0
tr ""
if cnt="0" & oldmail="0" then do; tr "Sorry, there is no new mail to read!"; signal pause; end
info=emailname||bbsemail
if oldmail=0 then do;
	address command "dirsizer yam:incoming/ >ram:"||username||amount
	address command "list files nohead quick yam:incoming/ >ram:"||username||xxx
end
if oldmail=1 then do;
	address command "dirsizer remail:"emailname"/oldmail/ >ram:"||username||amount
	address command "list files nohead quick remail:"emailname"/oldmail/ >ram:"||username||xxx
end

open(am,"ram:"||username||amount,"R")
	sexy=readln(am)
	if sexy="" then do; signal nothere; end
	if sexy="0" then do; signal nothere; end
close(am)

q=0

open(i,"ram:"||username||xxx,"R")
starthere:
pp.q=readln(i); filex=pp.q

if oldmail=1 then filename="remail:"||emailname||"/oldmail/"||filex
if oldmail=0 then filename="yam:incoming/"||filex
open(u,filename,"R")
if q=sexy then do; close(i); close(u); signal nothere; end
do until lok.ii=""
	lok.ii=readln(u)
	qq=find(lok.ii,"<"||info||">")
	fileb=lok.ii
	qqq=find(lok.ii,info)
	filebb=lok.ii
	qqqq=find(filebb,"<"||info||">")
	filebbb=lok.ii
	qqqqq=find(filebbb,info)
	filebbbb=lok.ii
	qqqqqq=find(filebbbb,"<"||info||">")
	filebbbbb=lok.ii
	qqqqqqq=find(filebbbbb,info||",")
	if left(fileb,5)="From: " then do; filed=right(left(fileb,40),34); end
	if fileb="To: "info"" then do; close(u); rcvd=rcvd+1; jolly=1; signal showmail; end
	if qq~="0" & left(fileb,3)="To:" then do; close(u); rcvd=rcvd+1; jolly=1; signal showmail; end
	if qqq~="0" & left(fileb,3)="To:" then do; close(u); rcvd=rcvd+1; jolly=1; signal showmail; end
	if qqqq~="0" & left(filebb,1)=" " then do; close(u); rcvd=rcvd+1; jolly=1; signal showmail; end
	if qqqqq~="0" & left(filebbb,1)=" " then do; close(u); rcvd=rcvd+1; jolly=1; signal showmail; end
	if qqqqqq~="0" then do; close(u); rcvd=rcvd+1; jolly=1; signal showmail; end
	if qqqqqqq~="0" then do; close(u); rcvd=rcvd+1; jolly=1; signal showmail; end
end
close(u)
q=q+1
signal starthere

x:
if delete=1 then do; address command "delete "filename""; end
delete=0
q=q+1
if q=sexy then do; close(i); close(u); signal nothere; end
signal starthere

nothere:
address command "delete ram:"||username||xxx
if klooper=1 then do; fop=2; end; 
signal main

showmail:
if oldmail=0 then do; open(loo,"remail:"emailname"/rec.dat","W"); o=writeln(loo,rcvd); close(loo); end
gu 526; linecount=result
ppw=12
tr cls||"[33m"
ty="Private Message"
fileyn="Msg only!!"

open(yuip,filename,"R")
do until eof(yuip)
	fgh=readln(yuip)
	if left(fgh,5)="begin" then fileyn="File & Msg!!"
end
close(yuip)

open(uip,filename,"R")
do until endofheader=""
	endofheader=readln(uip)
	if left(endofheader,4)="To: " then linea=left(endofheader,38)
	if left(endofheader,6)="From: " then lineb=left(endofheader,47)
	if left(endofheader,9)="Subject: " then linec=left(endofheader,49)
	if left(endofheader,6)="Date: " then lined=left(endofheader,32)
	if oldmail=0 then type="New Mail        "
	if oldmail=1 then type="Old Saved Mail  "
end
tr "[36mDate   [32m: [0m"||right(lined,26)||"                [36mNumber  [32m: [0m"||right((q+1),3,0)"/"right(sexy,3,0)
tr "[36mTo     [32m: [0m"||right(linea,34)||"        [36mStatus  [32m:[0m "||type
tr "[36mFrom   [32m: [0m"||right(lineb,41, )||" [36mFiles   [32m:[0m "||fileyn
tr "[36mSubject[32m: [0m"||right(linec,40)||"  [36mMsg Type[32m:[0m "||ty
tr "[0m"

do until EOF(uip)
fast=readln(uip)
ppw=ppw+1
if ppw=linecount then do; call opts; end
if fast="" then do; tr "[0m"; end
if left(fast,5)="begin" then do
	sm "WARNING!!: File could contain a file! Continue?? (Y/N) "; getchar; uuen=upper(result)
	if uuen="N" then do; sm "                                                               "; close(uip); signal options; jolly=0; end; end
sm fast||cr
end
close(uip)
signal round

opts:
sm ||cr"[36mPause, More? [32m([36mY[32m/[36mN[32m)[36m? "
getchar; h=upper(result)
if h="N" then do; sm c||"                    [0m"||c; close(uip); signal round; end
if h~="N" then do; sm c||"                    [0m"||c; ppw=12; return; end


round:
options:
if oldmail=0 then do;
sm c||"[36mMsg. Options[0m: [32mA[36m,[32mD[36m,[32mR[36m,[32mT[36m,[32mN[36m,[32mX[36m,[32mQ[36m,[32m? [36m>[0m: "
end
if oldmail=1 then do;
sm c||"[36mMsg. Options[0m: [32mA[36m,[32mD[36m,[32mN[36m,[32mX[36m,[32mQ[36m,[32m? [36m>[0m: "
end
receive 1; query ""; h=upper(result)
if h="X" then do; sm cr||"[31mDownload Message? [34m([32mY[34m/[32mN[34m)[33m: "; getchar; h=upper(result); if h~="Y" then do; sm "[0mNO!"; signal showmail; end; sm "[0mYes!"; putustr "yam:incoming/"||pp.q; putuser 137; signal showmail; end
if h="N" then do; tr ""; signal erasemail; end
if h="A" then do; signal showmail; end
if h="Q" then do; close(i); address command "delete ram:"||username||xxx; address command "delete ram:"||username||amount; if klooper=1 then do; fop=2; end; signal main; end
if h="D" then do; signal erasemail; end
if h="T" & oldmail=0 then do; signal transfer; end
if h="T" & oldmail=1 then do; signal options; end
if h="R" & oldmail=0 then do; signal reply; end
if h="R" & oldmail=1 then do; signal options; end
if h="?" then do; signal listoptions; end
if h="P" & upper(username)=sysopname then do; address command "type yam:incoming/"filex" >prt:"; end
if h="P" & upper(username)~=sysopname then do; signal options; end
if h="" then do; tr ""; signal deletemail; end
signal options:

listoptions:
tr ""
tr "[36m([32mA[36m)[0mgain"
tr "[36m([32mX[36m)[0mdownload Msg"
if oldmail=0 then do; tr "[36m([32mR[36m)[0meply to Msg";end
tr "[36m([32mN[36m)[0mext Msg"
tr "[36m([32mD[36m)[0melete Msg"
if oldmail=0 then do; tr "[36m([32mT[36m)[0mransfer / Forward Msg"; end
tr "[36m([32mQ[36m)[0muit"
tr ""
signal options


transfer:
towho=""
tr ""
receive 45; query "Forward Msg To? [32m([36m?[32m)[0m=>[33mAddress Book  [36m>[0m: "; towho=result
if towho="?" then do; call address; end
if noaddress=1 then do; signal showmail; end
open(makefile,"t:"username"","W"); close(makefile)
open(tempfile,filename,"R")
do until enter=""
	enter=readln(tempfile)
	if left(enter,6)="From: " then replyto=right(left(enter,45),34)
	if left(enter,9)="Subject: " then subject=right(left(enter,45),31)
end
do until eof(tempfile)
	hh=readln(tempfile)
		call open(fuck,"t:"username"","A")
			hi=writeln(fuck,">"||hh)
		call close(fuck)
end
close(tempfile)
hoho=1
call flamer
tr ""
sm "[0mDelete original message? [34m([32mY[34m/[32mN[34m)[33m:[0m "; getchar; o=upper(result)
if o="Y" then do; sm "Yes!!"; delete=1; signal x; end
if o~="Y" then do; sm "NO!!"; signal showmail; end

reply:
open(makefile,"t:"username"","W"); close(makefile)
open(tempfile,filename,"R")
do until enter=""
	enter=readln(tempfile)
	if left(enter,6)="From: " then towho=right(left(enter,46),40)
	if left(enter,9)="Subject: " then subject=right(left(enter,49),43)
end
do until eof(tempfile)
	hh=readln(tempfile)
		call open(fuck,"t:"username"","A")
			hi=writeln(fuck,">"||hh)
		call close(fuck)
end
close(tempfile)
tr ""
putustr "t:"username""; putuser 9
hoho=1
call flamer
tr ""
sm "[0mDelete original message? [34m([32mY[34m/[32mN[34m)[33m:[0m "; getchar; o=upper(result)
if o="Y" then do; sm "Yes!!"; delete=1; signal x; end
if o~="Y" then do; sm "NO!!"; signal showmail; end

deletemail:
delete=0
sm "[0mDelete this message? [34m([32mY[34m/[32mN[34m)[33m:[0m "; getchar; o=upper(result)
if o="Y" then do; sm "Yes!"; delete=1; signal x; end
if o="N" then do; sm "No!"; tr cr||cr; signal showmail; end
if o="" then do; sm "No!"; tr cr||cr; signal showmail; end
signal x:

erasemail:
delete=0
sm "[0mDelete this message? [34m([32mY[34m/[32mN[34m)[33m:[0m "; getchar; o=upper(result)
if o="Y" then do; sm "Yes!"; delete=1; signal x; end
if o="N" then do; sm "No!"; tr cr||cr; signal showmail; end
if o="" then do; sm "No!"; tr cr||cr; signal showmail; end
signal erasemail

address:
/* ***************************************************************** */
/* ********************** ADDRESS BOOK SELECT ********************** */
/* ***************************************************************** */
poop=1
tr ""
if ~exists("remail:phonebooks/"emailname".bk") then do
	open(g,"remail:phonebooks/"emailname".bk","W")
	close(g)
end

h=0; lin=1
do p=1 to 40
	sm "["lin";"h"H[33m"p"[34m: "
lin=lin+1
if p=20 then do; h=40; lin=p-19; end
end

open(g,"remail:phonebooks/"emailname".bk","R")
h=4; lin=0
	do n=1 to 40
	nam.n=readln(g)
	adr.n=readln(g)
	lin=lin+1
if n=21 then do; h=44; lin=n-20; end
	sm "["lin";"h"H [0m"left(nam.n,9, ) 
	if nam.n~="" then do; sm " [34m<[33m"left(adr.n,22, )"[34m>[0m"; end
	if nam.n="" then do; sm " [33m"left(adr.n,22, ); end
	end

transmit "[22;0H"
receive 2; query "[33mEnter a number for the address[34m: [0m"; nu=result
	towho=nam.nu||" <"||adr.nu||">"
close(g)
if nu="" then do; noaddress=1; return; end
if adr.nu="" then do; noaddress=1; return; end
if towho="" then noaddress=1; return; end
return

addressedit:
/* ***************************************************************** */
/* *********************** ADDRESS BOOK EDIT *********************** */
/* ***************************************************************** */
tr ""
if ~exists("remail:phonebooks/"emailname".bk") then do
	open(g,"remail:phonebooks/"emailname".bk","W")
	close(g)
end

h=0; lin=1
do p=1 to 40
	sm "["lin";"h"H[33m"right(p,2,0)"[34m: "
lin=lin+1
if p=20 then do; h=40; lin=p-19; end
end

open(g,"remail:phonebooks/"emailname".bk","R")
h=4; lin=0
	do n=1 to 40
	nam.n=readln(g)
	adr.n=readln(g)
	lin=lin+1
if n=21 then do; h=44; lin=n-20; end
	sm "["lin";"h"H [0m"left(nam.n,9, ) 
	if nam.n~="" then do; sm " [34m<[33m"left(adr.n,22, )"[34m>[0m"; end
	if nam.n="" then do; sm " [33m"left(adr.n,22, ); end
	end
close(g)
if klooper=1 then do; fop=2; end; 
transmit "[22;0H"
receive 20; query "[33mEnter users name, eg: FRED BLOGGS [34m[[33mReturn=Quit[34m] [34m: [0m"; edi=upper(result)
if edi="" then signal main
transmit "[22;0H"
tr "                                                                                        "
transmit "[22;0H"
receive 45; query "[33mEnter EMail address, eg: fred@bumpy.land.cu.uk [34m[[33mReturn=Quit[34m] [34m: [0m"; ed=result
	if ed="" then signal main
transmit "[22;0H"
tr "                                                                                        "
transmit "[22;0H"
sm "Add [33m"edi"[0m,[33m "ed" [0mto book? [34m([0mY[34m/[0mN[34m)[0m "; getchar; l=upper(result)
	if l~="Y" then do; sm "No!"; signal addressedit; end
sm "Yes!"
open(g,"remail:phonebooks/"emailname".bk","A")
	pp=writeln(g,edi)
	pp=writeln(g,ed)
close(g)
signal addressedit

bye:
if mailscan=1 then do; return; end
if m=0 then do; sm "none found![0m"; tr cr||""; address command "delete ram:"||username||xxx; address command "delete ram:"||username||amount; shutdown; exit; end
tr ""
address command "delete ram:"||username||xxx
address command "delete ram:"||username||amount
if mailscan=0 then do; fop=1;
sm "Do you want to read it now? [36m([32mY[36m/[32mn[36m) [32m>[0m: "; getchar; k=upper(result)
if k~="Y" then do; sm "[0mNO!"||cr||cr; shutdown; exit; end
sm "Yes!"||cr
signal main
end
closedown:
shutdown
exit
end

error:
BREAK_C:
ioerr:
halt:
syntax:
tr cr||"ERROR!!! Contact neelix @ laluna BBS (+44) 01206 501835"
tr cr||"Or EMail neelix@laluna.keme.co.uk"
shutdown; exit; end
