/* GrabTag.Spot Vers 1.3 (16-9-93) By Chi Wai Lee <2:253/167.9>
**
** Interogates a message and writes out the tagline to a file.
** Tagline must begin with '...'
** Requires RexxReqTools.library
*/

/* checks to see if library is loaded, otherwise load it */
if ~show('l','rexxreqtools.library') then call addlib('rexxreqtools.library',0,-30,0)

address SPOT
options results

/* Put full path to your tagfile here */
tagfilename = "MAIL:Spot.taglines"

'ismessages'
if rc = 0 then do   /* Must be in messages */

     /* Save out message and read it into a variable */
     'saveascii t:spotascii.tmp overwrite noheader notearline'
     call open(in,'t:spotascii.tmp','r')
     msg = readch(in,65535)

     /* Find the tagline identifier i.e. '...' */
     start = lastpos('0a2e2e2e'x,msg)
     if start ~= 0 then do    /* Can't find a tagline */

          /* Puts the tagline into a variable */
          call seek(in,start+4,'b')
          tag = rtgetstring(strip(readln(in),'b'),"Well, here's the tagline.  Edit it if you want.","GrabTag")
          IF rtresult = 1 then do

               /* Makes sure that mail:tagfile exists */
               if ~exists(tagfilename) then call open(tagfile,tagfilename,'w')
               else do
                    call open(tagfile,tagfilename,'a')
                    call writeln(tagfile,'%%')
               end
               call writeln(tagfile,tag)
          end
     end
     else 'requestnotify "I can''t seem to find a tagline."'
     call close in
     address command 'delete >nil: t:spotascii.tmp'
end
else 'requestnotify "Use in message window only!"'
