home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / networking / news / modhdr.lha / modhdr.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1995-03-08  |  7.2 KB  |  237 lines

  1. /* modheaders.rexx - Takes a mail file and modifies some    */
  2. /* headers that TIA installation leaves wrong...            */
  3. /* v0.00alpha 1-17-95                                       */
  4. /* v0.01alpha 1-18-95 ... Apparently works. :)              */
  5. /* v1.00      1-18-95 ... "Release" version                 */
  6. /* v1.01beta  1-31-95 ... more reqtools, because it rules   */
  7. /* v1.02      3-8-95  ... Strip those blank lines ...       */
  8. /*                        Also won't ask for headers that   */
  9. /*                        are already there ...             */
  10.  
  11. /* As for my previous script package(s), this distribution  */
  12. /* is freeware ... All I ask is that you tell me about any  */
  13. /* changes/upgrades you make to this so that I and the rest */
  14. /* of Amiga-land might benefit from them ...                */
  15.  
  16. /* This script has been thrown together, but seeing as it   */
  17. /* works great, I haven't felt the need to optimize it ...  */
  18.  
  19. /* Environment variables:                                   */
  20. /* DRMEDITOR = pathname of your editor                      */
  21. /* DRMTIA = YES if you're using TIA or wish the script to   */
  22. /*            substitute DRMREAL in From: headers ...       */
  23. /* DRMREAL = Your real email address.  Required if you      */
  24. /*           set DRMTIA = YES                               */
  25. /* NEWSEDITOR = "sys:rexxc/rx wherever:you/put/modhdr.rexx" */
  26.  
  27. /* Initialize */
  28.  
  29. call addlib("rexxreqtools.library",0,-30,0)
  30. options results
  31. lf = '0a'x
  32. cr = '0d'x
  33. colon='3a'x
  34. semicol='3b'x
  35. qmark='22'x
  36. fonttag=""
  37. aflags=""
  38. address command
  39.  
  40. /* Intercept the filename */
  41.  
  42.      localfile = ARG(1)
  43.  
  44. /* Open file and parse the important headers */
  45.  
  46.      dummy = open(mf,localfile,read)
  47.  
  48.      subject = ""
  49.      replyto = ""
  50.      newsgroups = "***"
  51.      mto = "***"
  52.      
  53.      do until currline = ""
  54.                 currline = readln(mf)
  55.                 currll = length(currline)
  56.                     if left(currline,8)=="Subject:" then subject = right(currline,currll-9)
  57.                     if left(currline,11)=="Newsgroups:" then newsgroups = right(currline,currll-12)
  58.                     if left(currline,5)=="From:" then replyto = right(currline,currll-6)
  59.                     if left(currline,3)=="To:" then mto = right(currline,currll-4)
  60.            end
  61.      call close mf
  62.  
  63. /* The following makes a temp file with just the message body.  We don't */
  64. /* need no steenking headers ...                                         */
  65.  
  66. /* Modification for 1.02 - remove extra blanks ... */
  67.  
  68.                   call open mf,localfile,read
  69.                   call open tf,'t:msg.tmp',write
  70.  
  71.                   firstline = 0
  72.                   eoheads = 0
  73.                   do until eof(mf)=1
  74.                        daline = readln(mf)
  75.                        if daline = "" then eoheads = 1
  76.                        if (eoheads=1)&(daline ~= "") then firstline=1
  77.                        if (eoheads = 1)&(firstline = 1) then call writeln tf,daline
  78.                        end
  79.                  call close mf
  80.                  call close tf
  81.  
  82. /* Let's ask the user about the headers ...          */
  83. /* If it's a news article, don't ask who it's to ... */
  84.  
  85. ngroup = newsgroups
  86. whoto = mto
  87. msub = subject
  88.  
  89. /* Modification for 1.02 - don't query if there's already a header. */
  90.  
  91. if (newsgroups ~="***")&(strip(newsgroups)="") then do
  92.      ngroup = getval(newsgroups,"     Where would you like to post this text?     ")
  93.      end
  94.  
  95. if (newsgroups ="***")&(strip(mto)="") then do
  96.      whoto = getval(mto,"     Who to mail this to? (user@host)     ")
  97.      end
  98.  
  99. if strip(subject)="" then do
  100.      msub = getval(subject,"     Enter a subject for this transmission:     ")
  101.      end
  102.  
  103. if envar('DRMTIA')=="YES" then replyto = envar('DRMREAL')
  104. mfrom = replyto
  105.  
  106. /* Uncomment the following if you want to be queried about your "From:" address each time    */ 
  107. /* mfrom = getval(replyto,"     Where would you like to say this is from? (user@host)     ") */
  108.  
  109. /* We should probably edit the file without headers ... */
  110.  
  111. TFileName = "T:msg.tmp"
  112.  
  113. call open .dae,'t:modheaders.cmd',write
  114. call writeln .dae,envar('DRMEDITOR') TFileName
  115. call close .dae
  116.  
  117. 'execute t:modheaders.cmd'
  118. 'delete 'localfile' QUIET'
  119.  
  120. /* Change header options */
  121.  
  122. hdflag = -1
  123.  
  124. mcc = "<None>"
  125. mbcc = "<None>"
  126.  
  127.   do until hdflag = 0
  128.  
  129.     hdmsg = "Newsgroups :"||ngroup||lf||"Subject    : "||msub||lf||"Reply-To   : "mcc||lf||"Followup-To: "||mbcc
  130.     hdbuttons = "_Newsgroups|_Subject|_Reply-To|_Followup-To|_Done!"
  131.  
  132.     if ngroup = "***" then do
  133.        hdmsg = "To     : "||whoto||lf||"Subject: "||msub||lf||"Cc     : "mcc||lf||"Bcc    : "||mbcc
  134.        hdbuttons = "_To|_Subject|_Carbons|_Blind Carbons|_Done!"
  135.        end
  136.  
  137.     hdflag = rtezrequest(hdmsg,hdbuttons,"Edit headers?","")
  138.  
  139.   select 
  140.  
  141.       when hdflag = 1 then do
  142.          mto = whoto
  143.          if ngroup ~="***" then mto = ngroup
  144.          mtxt = "     Who to mail this to? (user@host)     "
  145.          if ngroup ~="***" then mtxt = "     Where would you like to post this?      "
  146.          whoto = getval(mto,mtxt)
  147.          if ngroup ~="***" then ngroup = whoto   
  148.          end
  149.  
  150.       when hdflag = 2 then do
  151.          subject = msub
  152.          msub = getval(subject,"     Enter a subject for this transmission:     ") 
  153.          end
  154.  
  155.       when hdflag = 3 then do
  156.          omcc = mcc
  157.          mtxt = "     Send carbon copies of this mail to? (user@host)     "
  158.          if ngroup ~="***" then mtxt = "     Send replies to this news posting to? (user@host)     "
  159.          mcc = getval(omcc,mtxt)
  160.          end
  161.  
  162.       when hdflag = 4 then do
  163.          ombcc = mbcc
  164.          mtxt = "     Send blind carbon copies of this mail to? (user@host)     "
  165.          if ngroup ~="***" then mtxt = "     Send followups to this news posting to? (user@host)     "
  166.          mbcc = getval(ombcc,mtxt)
  167.          end
  168.  
  169.       otherwise
  170.   end
  171. end
  172.  
  173. /* Now that we've edited this file we should put together a message with */
  174. /* headers */
  175.  
  176. call open hdr,"T:temp.hdr",write
  177.  
  178. if ngroup = "***" then do
  179.      call writeln hdr, 'To:' whoto
  180.      end
  181.  
  182. if ngroup ~= "***" then do
  183.      call writeln hdr, 'Newsgroups:' ngroup   
  184.      end
  185.  
  186.      call writeln hdr, 'From:' mfrom
  187.      call writeln hdr, 'Subject:' msub
  188.  
  189. select 
  190.      when ngroup = "***" then do
  191.           if mcc ~= "<None>" then call writeln hdr, 'Cc:' mcc
  192.           if mbcc ~= "<None>" then call writeln hdr, 'Bcc:' mbcc
  193.           end
  194.      otherwise do
  195.           if mcc ~= "<None>" then call writeln hdr, 'Reply-To:' mcc
  196.           if mbcc ~= "<None>" then call writeln hdr, 'Followup-To:' mbcc
  197.           end
  198. end
  199.      call writeln hdr,""
  200.  
  201.      call close hdr
  202.      'join T:temp.hdr T:msg.tmp AS 'localfile
  203.  
  204. /* Diagnostic line follows... */
  205. /*     'most 'localfile       */
  206.  
  207. /* Return control to the caller ... */
  208.  
  209. exit
  210.  
  211. /* Useful subprograms follow ... */
  212.  
  213. getval: procedure
  214.      parse arg defsub,msg
  215.      mailsub = rtgetstring(defsub,msg,"ModHdr v1.02 by Rick Taylor","Ok","")
  216.      if mailsub = "" then mailsub = defsub
  217.      if mailsub = "" then mailsub = "<None>"
  218.      return mailsub
  219.      
  220. diagnostic: procedure
  221.      parse arg showit
  222.      msg = "Value = "||showit
  223.      cf=rtezrequest(msg,"OK","Diagnostic","")
  224.      return cf
  225.           
  226. envar: procedure
  227.      arg evname
  228.      epath = "ENV:"||evname
  229.      evalue = ""
  230.      if exists(epath) then do
  231.           call open .envar,epath,read
  232.           evalue = readln(.envar)
  233.           call close .envar
  234.           end
  235.      return evalue
  236.  
  237.