; Host Mode Mail include file - Do not compile! ;*********************************************************************** ;* * ;* MAIL.WAS * ;* Copyright (C) 1992 Datastorm Technologies, Inc. * ;* All rights reserverd. * ;* * ;* Purpose: Contains the Host Mail routines for Host Mode * ;* * ;*********************************************************************** ;*********************************************************************** ;* * ;* WARNING!!!! * ;* * ;* Do not modify this script file unless you have a good under- * ;* standing of the Windows ASPECT language. If you do modify this * ;* script, PLEASE MAKE A BACKUP before doing so. * ;* * ;*********************************************************************** ;*********************************************************************** ;* * ;* Structure of HOST.HDR for each message in the HOST.MSG file * ;* * ;* integer 2 bytes message number * ;* long 4 bytes offset - offset into the HOST.MSG file * ;* integer 2 bytes message length - length of message in HOST.MSG * ;* char 1 bytes flag - see below * ;* string 31 bytes destination - TO: * ;* string 31 bytes from - FROM: * ;* string 37 bytes subject - SUBJECT: * ;* string 9 bytes date - date message was created * ;* string 11 bytes time - time message was created * ;* * ;* The mail flag is set by adding the desired attributes together. * ;* PUBLIC 0 - anyone can read * ;* PRIVATE 1 - only TO: and FROM: can read or delete * ;* NEWMAIL 2 - hasn't been read * ;* DELETED 4 - marked for deletion * ;* * ;* All strings include a NULL at the last position. * ;* * ;*********************************************************************** ;*********************************************************************** ;* * ;* LEAVEMAIL * ;* * ;* This procedure creates the mail messages * ;* * ;* * ;* Calls: HOSTPUTS, HOSTGETS, HOSTGETYN, HOSTGETC, SETFAILURE, * ;* HOSTMSGBOX, EXITHOST, MAILGETLINE, COUNTMSG * ;* * ;* Modifies globals: tempfile, name, msgfile, hdrfile * ;* * ;* Labels : GETMESSAGE, LOOP * ;* * ;*********************************************************************** proc LeaveMail intparm replyflag strparm subject strparm destination string line, line_num, choice integer mailflag, line_count, msg_num, chars_to_read, blocksize integer dummy, length, count long msgfile_offset, msg_length fetch aspect scriptpath tempfile addfilename tempfile "~HOST.TMP" if isfile tempfile delfile tempfile endif while 1 line_count=1 if ! replyflag HostPutS("`r`n`r`n To: ") HostGetS(&destination 30 DISP) strupr destination endif if ! replyflag HostPutS("`r`nSubj: ") HostGetS(&subject 40 DISP) endif HostPutS("`r`n`r`n") HostPutS("Private Mail (Y/N)? ") HostGetYN() if success mailflag=PRIVATE+NEWMAIL else mailflag=PUBLIC+NEWMAIL endif HostPutS("`r`n`r`n To: ") HostPutS(destination) HostPuts("`r`nFrom: ") HostPutS(name) HostPutS("`r`nSubj: ") HostPutS(subject) if ! replyflag HostPutS("`r`n`r`nIs this correct (Y/N/Q)? ") HostGetC(&choice) if not success SetFailure() return endif HostPutS(choice) HostPutS("`r`n") strupr choice switch choice case "Y" endcase case "N" loopwhile endcase case "Q" return endcase endswitch endif fopen 1 tempfile CREATE if not success HostMsgBox("FATAL ERROR - Can't open TEMP file!") ExitHost() endif GETMESSAGE: while 1 strfmt line_num "%5d: " line_count HostPutS("`r`n") HostPutS(line_num) MailGetLine(&line) strcmp line "" if success exitwhile endif fputs 1 line ; write line to tempfile fputc 1 0x0D ; append CR to line fputc 1 0x0A ; append LF to line line_count++ endwhile LOOP: HostPutS("`r`n`r`nS)ave A)bort D)isplay C)ontinue ? ") HostGetC(&choice) strupr choice HostPutS(choice) if success HostPutS("`r`n") strupr choice switch choice case "S" HostPuts("`r`nSaving message ...`r`n") isfile msgfile if success fopen 0 msgfile WRITE if not success HostMsgBox("FATAL ERROR - Can't open HOST.MSG file!") halt endif else fopen 0 msgfile CREATE endif fseek 0 0 2 ftell 0 msgfile_offset fclose 1 findfirst tempfile msg_length=$FSIZE fopen 1 tempfile READWRITE length=msg_length chars_to_read = msg_length fseek 0 0 2 while chars_to_read > 0 if chars_to_read > 128 blocksize = 128 else blocksize = chars_to_read endif fread 1 line blocksize dummy fwrite 0 line blocksize if not success HostMsgBox("FATAL ERROR - Can't write to HOST.MSG file!") halt endif chars_to_read = chars_to_read - blocksize endwhile fclose 0 fclose 1 delfile tempfile ;count messages to get this message number CountMsg(&msg_num) ;write header info isfile hdrfile if success fopen 2 hdrfile WRITE if not success HostMsgBox("FATAL ERROR - Can't open HOST.MSG file!") halt endif else fopen 2 hdrfile create endif fseek 2 0 2 CountMsg(&msg_num) inc msg_num fputi 2 msg_num fputl 2 msgfile_offset fputi 2 length fputc 2 mailflag fwrite 2 destination 31 fwrite 2 name 31 fwrite 2 subject 37 fwrite 2 $DATE 9 fwrite 2 $TIME 11 fclose 2 endcase case "A" HostPutS("`r`nAbort message (Y/N)? ") HostGetYN() if success fclose 1 delfile tempfile return endif HostPutS("`r`n") goto LOOP endcase case "D" count=1 rewind 1 while 1 fgets 1 line if FEOF 1 exitwhile endif HostPutS(line) inc count if count==23 count=1 HostPuts("-MORE-") HostGetC(&choice) HostPutS("`b`b`b`b`b`b") strupr choice strcmp choice "N" if success exitwhile endif endif endwhile goto LOOP endcase case "C" goto GETMESSAGE endcase default goto LOOP endcase endswitch else SetFailure() endif return endwhile endproc ;*********************************************************************** ;* * ;* READMAIL * ;* * ;* This procedure reads and displays mail messages * ;* * ;* Calls: COUNTMSG, HOSTPUTS, HOSTGETC, SETFAILURE, HOSTGETS, READMSG * ;* * ;* Modifies globals: msg, msg_number * ;* * ;* Labels : LOOP * ;* * ;*********************************************************************** proc ReadMail string choice integer msg_total, searchflag LOOP: CountMsg(&msg_total) strfmt msg "`r`n`r`nTotal messages: %d`r`n`r`n" msg_total HostPutS(msg) HostPutS("F)orward read`r`n") HostPutS("N)ew mail`r`n") HostPutS("S)earch mail`r`n") HostPutS("Q)uit`r`n`r`n? ") HostGetC(&choice) if not success SetFailure() return endif HostPuts(choice) HostPuts("`r`n") strupr choice switch choice case "F" HostPuts("`r`nStarting message number ( for first): ") HostGetS(&choice 5 DISP) if not success SetFailure() return endif HostPuts("`r`n") strcmp choice "" if success msg_number=1 else atoi choice msg_number if msg_number>msg_total HostPutS("`r`nInvalid msg number!`r`n") goto LOOP endif endif while msg_number<=msg_total ReadMsg(0) if not success exitwhile endif endwhile HostPutS("`r`nEnd of messages.`r`n") goto LOOP endcase case "N" msg_number=1 while msg_number<=msg_total ReadMsg(1) if not success exitwhile endif endwhile HostPutS("`r`nEnd of messages.`r`n") goto LOOP endcase case "S" HostPutS("`r`n`r`nWhich field: T)o F)rom or S)ubject ? ") HostGetS(&choice 1 DISP) if not success SetFailure() return endif HostPuts("`r`n") strupr choice switch choice case "T" searchflag=2 endcase case "F" searchflag=3 endcase case "S" searchflag=4 endcase default return endcase endswitch HostPuts("Search string: ") HostGetS(&searchstr 30 DISP) HostPutS("`r`n") if not success SetFailure() return endif msg_number=1 while msg_number<=msg_total ReadMsg(searchflag) if not success exitwhile endif endwhile HostPutS("`r`nEnd of messages.`r`n") goto LOOP endcase case "Q" return endcase default goto LOOP endcase endswitch endproc ;*********************************************************************** ;* * ;* READMSG * ;* * ;* This procedure opens and displays a mail message. * ;* * ;* Calls: HOSTPUTS, HOSTMSGBOX, EXITHOST, CHANGEFLAG, DISPLAYFILE, * ;* HOSTGETC, SETFAILURE, LEAVEMAIL, DELETEMSG * ;* * ;* Modifies globals: tempfile, hdrfile, msg_number, _date, _time, * ;* access_level, name, msg, msgfile * ;* * ;* Labels: LOOP * ;* * ;*********************************************************************** proc ReadMsg intparm readflag integer msg_num, msg_length, msg_flag, dummy, chars_to_read, blocksize long offset, hdr_offset string destination, from, subject,flag, line, choice, reply="REPLY - " fetch aspect scriptpath tempfile addfilename tempfile "~HOST.TMP" isfile hdrfile if not success HostPutS("`r`nNo mail file found!`r`n") return endif fopen 0 hdrfile READWRITE if not success HostMsgBox("FATAL ERROR - Can't open HOST.HDR!") ExitHost() endif hdr_offset=(msg_number-1)*128 ; goto a specific record in .HDR file fseek 0 hdr_offset 0 LOOP: fgeti 0 msg_num if FEOF 0 SetFailure() inc msg_number return endif fgetl 0 offset fgeti 0 msg_length fgetc 0 msg_flag if (msg_flag & 1) ==1 flag="Private" ;remove new mail flag else flag="Public" endif fread 0 destination 31 dummy fread 0 from 31 dummy fread 0 subject 37 dummy fread 0 _date 9 dummy fread 0 _time 11 dummy if (msg_flag & 1)==1 ; if message is PRIVATE strcmp access_level "2" if not success strcmp name destination ; compare user name to TO: if not success strcmp name from ; compare user name to FROM: if not success inc msg_number goto LOOP endif endif endif endif if (msg_flag & 4)==DELETED inc msg_number goto LOOP endif switch readflag case 1 ; read new mail only strcmp destination name if not success inc msg_number goto loop endif if (msg_flag & 2)!=NEWMAIL inc msg_number goto LOOP endif endcase case 2 ; search for TO: if not strfind destination searchstr inc msg_number goto LOOP endif endcase case 3 ; search for FROM: if not strfind from searchstr inc msg_number goto LOOP endif endcase case 4 ; search for SUBJECT if not strfind subject searchstr inc msg_number goto LOOP endif endcase endswitch fclose 0 strcmp destination name if success msg_flag=msg_flag & 1 ;unset NEWMAIL flag ChangeFlag(msg_flag) endif strfmt msg "`r`n Msg: %d (%s, sent %s at %s)`r`n" msg_num flag _date _time HostPutS(msg) strfmt msg "From: %s`r`n" from HostPuts(msg) strfmt msg " To: %s`r`n" destination HostPutS(msg) strfmt msg "Subj: %s`r`n`r`n" subject HostPutS(msg) isfile msgfile if not success HostMsgBox("No message file!") return else fopen 1 msgfile READ text if not success HostMsgBox("Can't open message file!") return endif fopen 2 tempfile create text if not success HostMsgBox("Can't open temp file!") return endif fseek 1 offset 1 chars_to_read = msg_length while chars_to_read > 0 if chars_to_read > 128 blocksize = 128 else blockSize = chars_to_read endif fread 1 line blocksize dummy fwrite 2 line blocksize if not success HostMsgBox("Can't write to temp file!") halt endif chars_to_read = chars_to_read - blocksize endwhile fclose 1 fclose 2 DisplayFile(tempfile, 17) delfile tempfile HostPutS("`r`nR)eply D)elete Q)uit ( for another): ") HostGetC(&choice) if not success SetFailure() return endif HostPutS(choice) HostPutS("`r`n") switch choice case "R" substr msg subject 0 21 strcat reply msg LeaveMail(1, reply, from) inc msg_number return endcase case "D" DeleteMsg() endcase case "Q" SetFailure() return endcase case "`r" inc msg_number return endcase default choice="" endcase endswitch endif endproc ;**** End of MAIL.WAS ****