home *** CD-ROM | disk | FTP | other *** search
/ ANews 1 / AnewsCD01.iso / Internet / Newsgroup / THOR_2.6 / THOR26_AREXX.LHA / Rexx / MailtoScripts / IBMailTo.thor < prev    next >
Text File  |  1999-01-17  |  8KB  |  277 lines

  1. /*
  2. ** $VER: IBMailTo.thor v1.3 (11/01/99) John S. Burger (jsburger@xmission.com)
  3. **               <jsburger@xmission.com>
  4. **
  5. ** This script borrows heavily from AwebMailTo.thor by Shaun Downend.
  6. **                  <shaund@amiganut.demon.co.uk>
  7. **                         Thanks Shaun!!!
  8. **
  9. ** This script is designed for use with IBrowse's external mailto: support.
  10. ** It will take the email address supplied by IBrowse and start the text
  11. ** editor of your choice and automatically fill in the To: field. When you
  12. ** have finished you save the message and it will appear as an event in Thor.
  13. **
  14. ** See the .readme file for configuration information.
  15. **
  16. ** V1.1  First public release
  17. ** V1.2  Added ability to specify Thor's FSE as the editor
  18. ** V1.2ß Bug fixes to the FSE portion of the script and clarification
  19. **       to the IBrowse configuration in the .readme
  20. ** V1.3  No changes. Just bumped version number since I have not gotten
  21. **       any bug reports in V1.2beta.
  22. */
  23.  
  24. /* User defined variables */
  25.  
  26. MailSystem = 'Internet'                              /* Set to your TCP System in Thor                                          */
  27. MailConfName = 'EMail'                               /* Set to your Email Conference in Thor                                    */
  28. AddSignature = 'E'                                   /* Add signature (Y/N/E) from Thor or 'E' for another signature file       */
  29. SigFile = 'DH3:Thor/Sigs/IB.signature'                    /* File name with path for a signature file used with the 'E' option above */
  30. SendEvent  = 'N'                                     /* Send event immediately (Y/N)                                            */
  31. Editor = 'GED -STICKY'                               /* Set to the editor of your choice                                        */
  32.                                                      /* Set to FSE to use Thor's internal editor                                */
  33.  
  34. /* DON'T CHANGE ANYTHING BELOW HERE */
  35.  
  36. Tempfile = 't:MailTo.msg.'||time(s)'.ib'
  37.  
  38. parse arg argument
  39.  
  40. template = 'ADDRESS/A'
  41.  
  42. if(argument = '' | argument = '?') then
  43. do
  44.     say '$VER: IBMailTo.thor V1.3 (11/01/99) John S. Burger (jsburger@xmission.com)'
  45.     say 'Template:' template
  46.     exit
  47. end
  48.  
  49. if EDITOR=FSE then do
  50.    p=' '||address()||' '||show('P',,)
  51.    if pos(' THOR.',p)>0 then
  52.    thorport=word(substr(p,pos(' THOR.',p)+1),1)
  53.    else
  54.      do
  55.        call showerror("You have configured this script to use Thor's FSE as the editor. Thor must be running to use this script with FSE!")
  56.        exit
  57.      end
  58. end
  59.  
  60. if ~show('p', 'BBSREAD') then
  61. do
  62.     address command
  63.     "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  64.     "sys:rexxc/WaitForPort BBSREAD"
  65. end
  66.  
  67.  
  68. address BBSREAD
  69.  
  70. READARGS template ARGS CMDLINE argument
  71. if(rc ~= 0) then
  72. do
  73.     say BBSREAD.LASTERROR
  74.     exit
  75. end
  76.  
  77. address command 'echo >'tempfile' "To: 'ARGS.ADDRESS'*NSubject:  *N"'
  78.  
  79. if EDITOR=FSE then do
  80.    address(thorport)
  81.    STARTEDITOR tempfile
  82.    THORTOFRONT
  83.    address command "waitforport THOR_FSE.01"
  84.    address 'THOR_FSE.01'
  85.    ENDOFFILE
  86.    INCLUDEFILE SigFile
  87.    INSERTTAG
  88.    SETPOS X 9 Y 2
  89.    INSERTSTRING ' '
  90.      DO WHILE show('p', 'THOR_FSE.01')
  91.         NOP
  92.      END
  93.    address 'IBROWSE'
  94.    SCREENTOFRONT
  95.    END
  96. else
  97.  address command ''Editor' 'tempfile''
  98.  
  99. address BBSREAD
  100.  
  101. if(~OPEN(fh,tempfile,'Read')) then
  102. do
  103.     say 'Unable to open file'
  104.     exit
  105. end
  106.  
  107. str = readln(fh)
  108. if(upper(word(str, 1)) ~= "TO:") | (upper(word(str, 2)) = "") then
  109.  
  110. do
  111.     call showerror("First headerline wasn't a To: or no address was provided after To:,also, there must be a space after To: and the start of the actual address. Please don't mess with the header IBrowse provides.")
  112.     call close(fh)
  113.     address command 'c:delete >NIL: 'tempfile''
  114.     exit
  115. end
  116. else EVENT.TOADDR = word(str, 2)
  117.  
  118. str = readln(fh)
  119.  
  120. if(upper(word(str, 1)) ~= "SUBJECT: ") then
  121. do
  122.     call showerror("Second headerline wasn't a Subject: or there was no space left between Subject: and the actual subject text. Please don't mess with the header IBrowse provides.")
  123.     call close(fh)
  124.     address command 'c:delete >NIL: 'tempfile''
  125.     exit
  126. end
  127. else EVENT.SUBJECT = substr(str, 10)
  128. if(upper(word(str, 2)) = "") then
  129. do
  130.     call showerror("Mail Discarded by User")
  131.     call close(fh)
  132.     address command 'c:delete >NIL: 'tempfile''
  133.     exit
  134. end
  135.  
  136.  
  137. /* put the body of the message in a file with a unique name */
  138.  
  139. UNIQUEMSGFILE bbsname '"'MailSystem'"' stem UNIQUEFILE
  140. if(rc ~= 0) then
  141. do
  142.     call showerror('UNIQUEMSGFILE BBSRead command failed: ' || BBSREAD.LASTERROR)
  143.     call close(fh)
  144.     address command 'c:delete >NIL: 'tempfile''
  145.     exit
  146. end
  147.  
  148. call open(tmp, UNIQUEFILE.NAME, W)
  149.  
  150. do until eof(fh)
  151.     call writeln(tmp, readln(fh))
  152. end
  153.  
  154. /* add signature from the EMail conference/BBS/Global Settings */
  155.  
  156. IF Editor ~= FSE THEN DO
  157.  
  158. if(upper(AddSignature) = 'Y') then
  159. do
  160.     GETCONFDATA BBSNAME '"'MailSystem'"' CONFNAME '"'MailConfName'"' STEM CONFD
  161.     if(CONFD.SIGNATURE = "") then
  162.     do
  163.         GETBBSDATA BBSNAME '"'MailSystem'"' STEM BBSD
  164.         if(BBSD.SIGNATURE = "") then
  165.         do
  166.             GETGLOBALDATA STEM GLOBD
  167.             if(GLOBD.SIGNATURE = "") then
  168.             do
  169.                 call showerror('No signature configured in either conference, bbs or global settings! Please correct this in THOR or turn off signature adding in IBMailTo.thor.')
  170.                 call close(fh)
  171.                 address command 'c:delete >NIL: 'tempfile''
  172.                 exit
  173.             end
  174.             else sig = GLOBD.SIGNATURE
  175.         end
  176.         else sig = BBSD.SIGNATURE
  177.     end
  178.     else sig = CONFD.SIGNATURE
  179.  
  180.     drop CONFD.; drop BBSD.; drop GLOBD.
  181.  
  182.     if(sig ~= "") then
  183.     do
  184.     /* signature may be a filename */
  185.  
  186.         if(exists(sig)) then
  187.         do
  188.             call open(sigfh, sig, R)
  189.  
  190.             do until eof(sigfh)
  191.                 call writeln(tmp, readln(sigfh))
  192.             end
  193.  
  194.             call close(sigfh)
  195.         end
  196.         else call writeln(tmp, sig) /* or just a string */
  197.     end
  198. end
  199.  
  200. if(upper(AddSignature) = 'E') then
  201. do
  202.   if(exists(SigFile)) then
  203.   do
  204.      call open(sigfh, SigFile, R)
  205.      do until eof(sigfh)
  206.         call writeln(tmp, readln(sigfh))
  207.      end
  208.      call close(sigfh)
  209.   end
  210.   else
  211.     do
  212.       call showerror('The configured signature file does not exist! Please correct this or turn off signature adding in IBMailTo.thor.')
  213.       call close(fh)
  214.       address command 'c:delete >NIL: 'tempfile''
  215.       exit
  216.     end
  217. end
  218. call close(tmp)
  219.  
  220. END
  221.  
  222. /* fill out some more variables that BBSREAD require */
  223.  
  224. EVENT.CONFERENCE = MailConfName
  225. EVENT.MSGFILE = UNIQUEFILE.FILEPART
  226.  
  227. /* write the event */
  228.  
  229. WRITEBREVENT bbsname '"'MailSystem'"' event 0 stem EVENT
  230. if(rc ~= 0) then
  231. do
  232.     call showerror('WRITEBREVENT BBSRead command failed: ' || BBSREAD.LASTERROR)
  233.     call close(fh)
  234.     address command 'c:delete >NIL: 'tempfile''
  235.     exit
  236. end
  237.  
  238. call close(fh)
  239.  
  240. address command 'c:delete >NIL: 'tempfile''
  241.  
  242. if upper(sendevent) = "Y" then call send
  243.  
  244. exit 0
  245.  
  246. /* sophisticated errorhandling :-) */
  247.  
  248. showerror:
  249.  
  250. procedure expose MailSystem MailConfName AddSignature SigFile Editor
  251. parse arg errormsg
  252.  
  253. p=show('P',,)
  254.  
  255. if(pos('IBROWSE', p) > 0) then IBport = word(substr(p, pos('IBROWSE', p)), 1)
  256. else return
  257.  
  258. call open(err, "T:IBMailTo.thor.error.html", W)
  259. call writeln(err, "<HTML><HEAD><TITLE>IBMailTo.thor encountered an error</TITLE></HEAD><BODY><H1>Sending mail aborted</H1>" || errormsg || "<P>Please remember to verify the following settings:<PRE>" || '0a'x '0a'x || "MailSystem = '" || MailSystem || "'" || '0a'x || "MailConfName = '" || MailConfName || "'" || '0a'x || "AddSignature = '" || AddSignature || "'" || '0a'x || "SigFile = '" || SigFile || "'" || '0a'x || "Editor = '" || Editor || "'" || '0a'x '0a'x || "</PRE>If they are wrong, edit IBMailTo.thor and correct them. <hr> If this should happen to be an erroneous error, don't hesitate to contact the author, John S. Burger, by <A HREF=" || '"' || "mailto:jsburger@xmission.com" || '"' || ">email</A>.")
  260. call close(err)
  261.  
  262. address(IBport)
  263. 'GOTOURL URL file://localhost/T:IBMailTo.thor.error.html'
  264. 'SCREENTOFRONT'
  265. return
  266.  
  267. send:
  268.  
  269. If Show('p', 'AMITCP') | Show('p', 'MIAMI.1') = 1 then
  270. do
  271.     address BBSREAD
  272.     GETBBSDATA SystemName stem BBSDATA
  273.     if BBSDATA.NUMEVENTS ~= 0 then
  274.     address command 'run >NIL: `getenv thor/thorpath`bin/SendTCP 'MailSystem' pubscreen=Workbench'
  275. end
  276. return
  277.