home *** CD-ROM | disk | FTP | other *** search
- /* $VER: ForwardMsg.thor 3.1 (17.11.94)
- **
- ** Arexx script to forward messages from a user to another user.
- **
- ** Must be started from THOR.
- **
- ** Script by: Petter Nilsen, Ultima Thule Software.
- **/
-
- options results
-
- EVE_ENTERMSG = 0 /* Enter message */
-
- thorport = address()
-
- if ~show('p', 'BBSREAD') then do
- address command
- "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
- "WaitForPort BBSREAD"
- end
-
- address(thorport)
-
- CURRENTMSG stem MSG
- if(rc ~= 0) then
- do
- REQUESTNOTIFY TEXT '"No current message."' BT '"_Ok"'
- exit
- end
-
- REQUESTNOTIFY TEXT '"Forward to the same system and conference ?"' BT '" _Yes | _No "'
- if(rc ~= 0) then
- do
- say THOR.LASTERROR
- exit
- end
-
- if(result = 0) then
- do
- address BBSREAD GETBBSLIST stem BBSLIST
- if(rc ~= 0) then goto quit
-
- REQUESTLIST instem BBSLIST title '"Select system to forward to:"'
- if(rc ~= 0) then
- do
- if(rc ~= 5) then address(thorport) REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
- exit
- end
-
- bbs = result
-
- address BBSREAD GETCONFLIST bbsname '"'bbs'"' stem CONFLIST
- if(rc ~= 0) then goto quit
-
- REQUESTLIST instem CONFLIST title '"Select Conference:"'
- if(rc ~= 0) then
- do
- if(rc ~= 5) then address(thorport) REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
- exit
- end
- conf = result
- other = 1
- end
- else
- do
- other = 0
- bbs = MSG.BBSNAME
- conf = MSG.CONFNAME
- end
-
- /* Let's ask for a user name.. */
-
- do forever
- REQUESTSTRING TITLE '"Enter username to forward to:"' BT '" _Ok | _Cancel "' MAXCHARS 200
- if(rc ~= 0) then exit
- forwardto = result
-
-
- if(upper(forwardto) ~= "ALL") then
- do
- address(bbsread)
-
- /*
- The message was not addressed to 'ALL',
- let's search for the user on the system
- the message is to be forwarded to.
- Both name, addresses and aliases will be searched
- for to find a match.
- */
-
- SEARCHBRUSER bbsname '"'bbs'"' stem USERS search '"'forwardto'"' name address alias suggestusersstem SUG
- if(rc ~= 0) then goto quit
-
- if(result > 0) then
- do
- /* Ok, we found one or more users matching the data entered exactly */
-
- address(bbsread)
-
- drop LIST.
- drop USERTAGS.
-
- LIST.COUNT = USERS.COUNT
-
- /*
- We must build a list of user names suitable to
- be viewed with the REQUESTLIST command.
- */
-
- do n = 1 to USERS.COUNT
- LIST.n.USERNR = USERS.n.USERNR
- READBRUSER bbsname '"'bbs'"' usernr USERS.n.USERNR tagsstem USERTAGS
- if(rc ~= 0) then goto quit
- LIST.n = USERTAGS.NAME
-
- if(symbol("USERTAGS.ADDRESS") = "VAR") then
- LIST.n.ADDRESS = USERTAGS.ADDRESS
- end
-
- /* Select a user */
-
- address(thorport)
- REQUESTLIST instem LIST title '"Select user:"'
- if(rc ~= 0) then
- do
- if(rc ~= 5) then REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
- exit
- end
-
- forwardto = result
-
- /* We might have an address (email address/Fido address etc.) */
-
- do n = 1 to LIST.COUNT
- if(LIST.n = forwardto) then
- forwardaddress = LIST.n.ADDRESS
- end
- leave
- end
- else
- do
- /*
- No users matching the given data exactly were found,
- let's prosess the suggestions.
- */
-
- if(symbol("SUG.COUNT") = "VAR") then do
- address(thorport)
- REQUESTLIST instem SUG title '"Select user:"'
- if(rc ~= 0) then
- do
- if(rc ~= 5) then REQUESTNOTIFY TEXT '"'THOR.LASTERROR'"' BT '"_Ok"'
- exit
- end
-
- forwardto = result
-
- /* Let's find the user number of the user selected */
-
- do n = 1 to SUG.COUNT
- if(SUG.n = forwardto) then
- usernumber = SUG.n.USERNR
- end
-
- drop USERTAGS.
-
- address(bbsread)
-
- /* Get some data about the user selected */
-
- READBRUSER bbsname '"'bbs'"' usernr usernumber tagsstem USERTAGS
- if(rc ~= 0) then goto quit
-
- if(symbol("USERTAGS.ADDRESS") = "VAR") then
- forwardaddress = USERTAGS.ADDRESS
-
- leave
- end
- else
- do
- /* No users were found in the search */
-
- address(thorport)
- REQUESTNOTIFY TEXT '"No matching users found, try again?"' BT '"_Ok | _Cancel"'
- if(rc ~= 0) then exit
- if(result = 0) then exit
- end
- end
- end
- else
- leave
- end
-
- address(bbsread)
-
- /* Get a unique message for the event */
-
- UNIQUEMSGFILE bbsname '"'bbs'"' stem UNIQUEFILE
- if(rc ~= 0) then goto quit
-
- /* Read the data on the message that is to be forwarded */
-
- READBRMESSAGE bbsname '"'MSG.BBSNAME'"' confname '"'MSG.CONFNAME'"' msgnr MSG.MSGNR headstem HEADTAGS textstem TEXTTAGS
- if(rc ~= 0) then goto quit
-
- if(~open(fh, UNIQUEFILE.NAME, 'A')) then
- do
- address(thorport)
- REQUESTNOTIFY TEXT '"Unable to open file:' UNIQUEFILE.NAME '"' BT '"_Ok"'
- exit
- end
-
- /* Build the forwarded message */
-
- msgfrom = HEADTAGS.FROMNAME
- msgto = ''
- if(symbol("HEADTAGS.TONAME") = "VAR") then msgto = HEADTAGS.TONAME
- if(symbol("HEADTAGS.TOADDR") = "VAR") then msgto = msgto || ' <' || HEADTAGS.TOADDR || '>'
- if(symbol("HEADTAGS.FROMADDR") = "VAR") then msgfrom = msgfrom || ' <' || HEADTAGS.FROMADDR || '>'
- call writeln(fh, '--------- START OF FORWARDED MESSAGE ---------')
- call writeln(fh, '')
-
- if(other = 1) then
- do
- call writeln(fh, 'From System ....: ' || MSG.BBSNAME)
- call writeln(fh, 'From Conference : ' || MSG.CONFNAME)
- end
-
- if(symbol("HEADTAGS.ORGINALNR") = "VAR") then do
- call writeln(fh, 'MessageNr ......: ' || HEADTAGS.ORGINALNR)
- end
- if(symbol("HEADTAGS.MSGID") = "VAR") then do
- call writeln(fh, 'MessageID ......: '|| HEADTAGS.MSGID)
- end
-
- call writeln(fh, 'Originally from : ' || msgfrom)
- if(msgto ~= '') then do
- call writeln(fh, 'Originally to ..: ' || msgto)
- end
- call writeln(fh, 'Subject ........: ' || HEADTAGS.SUBJECT || '0a'x)
-
- do n=1 to TEXTTAGS.TEXT.COUNT
- call writeln(fh, TEXTTAGS.TEXT.n)
- end
- call writeln(fh, '')
- call writeln(fh, '---------- END OF FORWARDED MESSAGE ----------')
-
- call close(fh)
-
- /* Post it */
-
- drop EVENT.
-
- EVENT.SUBJECT = 'FWD: '||HEADTAGS.SUBJECT
- EVENT.TONAME = forwardto
- EVENT.TOADDR = forwardaddress
- EVENT.CONFERENCE = conf
- EVENT.MSGFILE = UNIQUEFILE.FILEPART
-
- WRITEBREVENT bbsname '"'bbs'"' event EVE_ENTERMSG stem EVENT
- if(rc ~= 0) then goto quit
-
- address(thorport)
-
- if(bbs ~= MSG.BBSNAME) then
- PACKEVENTS '"'bbs'"'
-
- exit
-
- quit:
- address(thorport)
- REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
- exit
-