; File sr0.5, copyright (C) Peter Lyall Easthope, 2000. ; All rights reserved. take prolog0.5 ; User configuration and procedures for login. ; Beginning of procedures used to send messages. def ConfirmSend { local csf if = \m(CS) 0 return 0 while = 1 1 { echo {Message \m(OutLine)} ; Echo first address getc \%u {Proceed to send message? (y/n): } switch \%u { :y, echo {y}, asg csf 0, break :n, echo {n}, asg csf 1, break :default, echo {Please respond by keying or .}, asg csf 2 } if < \m(csf) 2 break } return \m(csf) } def SendSubj { output {\13} ; Clear "Copies:" loop IInput {Subject:} {"Subject:" not received in SendSubj} \3 output {\fsubstr(\m(OutLine),9)\13} } ; This procedure is invoked by ProceedMsg and SendCopiesAd. ; AddrRes is localized in ProceedMsg. def abortAddr { asg AddrRes 1 output \3 echo {Aborting message} SkipOut } ; This procedure is invoked by ProceedMsg. AddrRes is localized there. def SendCopiesAd { while = 1 1 { ; Send Copies addresses xif equal {\fsubstr(\m(OutLine),1,7)} {Copies:} { asg OutLine \fsubstr(\m(OutLine),8) } output \m(OutLine) if < 0 \findex(@,\m(OutLine),1) output {,i} output {\13} clear input ; Empty the INPUT buffer ; The following cases correspond to defective, ambiguous and ; recognizable addresses. minput \m(WaitTime) {s found\13\10Copies:\9\9} {\27[3D} {Copies:\9\9} switch \v(minput) { :0, errext {Unrecognized char's when expecting "Copies:"} :1, abortAddr, break :2, abortAddr, break :3, break :default, errext {Undefined switch after echo from outgoing address} } if = \m(AddrRes) 1 break read OutLine ; Read line from the OutFile xif equal {\fsubstr(\m(OutLine),1,8)} {Subject:} return } } def SendMsgBody { local EndMsg IInput {[More]} {No [More] prompt when editor starts} output \13 ; Start message body editor IInput {J} {No "clear screen", J, when editor starts} ; echo Finished editor screen setup. ; FC editor fills screen with 24 lines asg LineCount \feval(24) asg EndMsg 0 while > \m(LineCount) 0 { IInput {H} - {Cursor row,col control not received before sending a line} {\3} read OutLine xif failure { asg EndMsg 1 break } xif equal {\fsubstr(\m(OutLine),1,\m(SepLength))} {\m(MSep)} { asg EndMsg 1 break } output {\m(OutLine)\13} asg LineCount \feval(\m(LineCount)-1) } ; echo {Exited 24 line loop.} if = \m(EndMsg) 1 return ; echo {Starting 25th line.} while = 1 1 { ; Screen is full; accept K control IInput {K} {Screen is full but K control not received.} {\3} IInput {H} {Cursor row,col control not received before sending a line} {\3} read OutLine if failure break if equal {\fsubstr(\m(OutLine),1,\m(SepLength))} {\m(MSep)} break output {\m(OutLine)\13} } } def Sig { for \%f 1 \m(SigLen) 1 { output {\&s[\%f]\13} asg LineCount \feval(\m(LineCount)-1) xif = \m(LineCount) 0 { ; Sreen is full; accept K control IInput {K} {K control not received after filling screen} \3 asg LineCount \feval(24) } IInput {H} {Cursor row,col control not received after sig line} {\3} } } def CloseMsg { ; set input echo on ; Send to leave message body editor. output {\27} IInput {J} {clear screen, J, not received in CloseMsg} IInput {2D} {cursor control, 2D, not received in CloseMsg} output {\13} IInput {3D} {cursor control, 3D, not received in CloseMsg} output {\13} minput \m(WaitTime) {Forward.} {Scan.} ; accept command summary GetPrompt echo {Message sent.} ; set input echo off } def ProceedMsg { ; echo {Beginning ProceedMsg.} output {n\13} ; Ask FirstClass to create a message echo {Sending message, "\m(OutLine)".} IInput {To:} {"To:" not received from host in ProceedMsg} \3 local AddrRes asg AddrRes 0 ; Indicates an acceptable address while = 1 1 { ; Send address xif equal {\fsubstr(\m(OutLine),1,3)} {To:} { asg OutLine \fsubstr(\m(OutLine),4) } output \m(OutLine) if < 0 \findex(@,\m(OutLine),1) output {,i} output {\13} clear input ; Empty the INPUT buffer ; The following cases correspond to defective, ambiguous and ; recognizable addresses. minput \m(WaitTime) {s found\13\10To:\9\9} {\27[3D} {To:\9\9} switch \v(minput) { :0, errext {Unrecognized characters when expecting "To:"} :1, abortAddr, break :2, abortAddr, break :3, break :default, errext {Undefined switch after echo from outgoing address} } if = \m(AddrRes) 1 break read OutLine ; Read line from the OutFile xif equal {\fsubstr(\m(OutLine),1,8)} {Subject:} { output {\13} ; Clear "To:" loop SendSubj break } else { xif equal {\fsubstr(\m(OutLine),1,7)} {Copies:} { output {\13} ; Clear "To:" loop SendCopiesAd if = \m(AddrRes) 0 SendSubj break } } } if = \m(AddrRes) 1 return SendMsgBody xif not equal {n} {\fsubstr(\m(OutLine),\feval(\m(SepLength)+1),1)} {Sig} CloseMsg } def SendMsgs { open read \m(OutFile) if failure errext {Can't open \m(OutFile)} while = 1 1 { read OutLine ; Read the address from the OutFile if failure return ; No more messages in OutFile if equal {\fsubstr(\m(OutLine),1,\m(SepLength))} {\m(MSep)} return ConfirmSend xif = \v(return) 0 {ProceedMsg} else {SkipOut} ; echo {Finished processing outgoing message.} } close read-file } ; End of procedures used to send messages. ; Beginning of procedures used to receive messages. ; SkipOut is used to read through an outgoing message but not send it. def SkipOut { local LineBuffer while = 1 1 { read LineBuffer if failure break if equal {\fsubstr(\m(LineBuffer),1,\m(SepLength))} {\m(MSep)} break } ; echo {Leaving SkipOut.} } def GetMailbox { open write MAILBOX if failure errext {can't open MAILBOX for writing} echo {MAILBOX opened for writing.} output {1\13} IInput {J} {J not received before reading Mailbox} IInputLine SaveLine writeln file {\m(InLine)} xif equal {\fsubstr(\m(InLine),1,23)} {Home:MailBox: No items.} { ; Mailbox is empty. IInputLine IInputLine GetPrompt } else { ; Mailbox is not empty. local ExitMB def ExitMB 0 while equal \m(ExitMB) 0 { clear input minput \m(WaitTime) {\10} {[More]} switch \v(minput) { :0, errext {Unrecognized characters when receiving Mailbox} :1, SaveLine, InputMB1 {1}, break :2, InputMB2, break :default, errext {Undefined switch in Mailbox reading loop} } } } close write-file } ; ProcessMsgs gets the mailbox listing into a file and then reads ; unread messages. def ProcessMsgs { GetMailbox echo {MAILBOX file written and closed. Checking each entry ... } open read MAILBOX if failure errext {can't open MAILBOX for reading} read Title if failure errext {Nothing in mailbox} while = 1 1 { read Title if failure break ; echo {Checking a line in the mailbox file ...} ; echo {\m(Title)} xif equal {\fsubstr(\m(Title),1,1)} {*} { GetMsgNum if > \m(MsgNum) 0 RecvMsg } } close read-file ; Close the MAILBOX file } ; End of procedures used to receive messages or to tidy the mailbox. def Communicate { Login xif exist \m(OutFile) { SendMsgs ; Send outgoing messages ... xif = \m(DOFAS) 1 { delete \m(OutFile) } } ProcessMsgs ; Read the incoming messages or tidy the mailbox. output {logout y\13} hangup close session ; Close session log quit } ; Finished macro definitions. Communicate ; Make it happen. .