home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / internet / yamtools20 / yamtools20english / stripmail.rexx < prev    next >
OS/2 REXX Batch file  |  1997-08-08  |  12KB  |  270 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*                              StripMail                                     */
  4. /*                 Copyright ©1997 by Dick Whiting                            */
  5. /*                                                                            */
  6. /*----------------------------------------------------------------------------*/
  7. /*  This strip attachment program strips:                                     */
  8. /*                                                                            */
  9. /*     The Mime warning message at the beginning of the mail                  */
  10. /*     Mime attachments and replaces them with a message including name       */
  11. /*     UUencoded files that are included as plain text                        */
  12. /*                                                                            */
  13. /*     It also fixes a couple minor things in badly formed mail:              */
  14. /*        Adds a null line after Header if missing                            */
  15. /*        Adds boundary end if missing (prevent 0 byte attachment msg)        */
  16. /*                                                                            */
  17. /*  NOTE: This one, like my other ones, retains the date/timestamp of the     */
  18. /*        original mail and its filenote.                                     */
  19. /*                                                                            */
  20. /*  NOTE: Changes won't be visible in Yam until you do an UPDATE INDEX.       */
  21. /*                                                                            */
  22. /*  NOTE: As long as you don't change the stripmsg value, you can run this    */
  23. /*        multiple times against the same mail and NOT lose the name of the   */
  24. /*        attachment that was stripped.                                       */
  25. /*                                                                            */
  26. /*----------------------------------------------------------------------------*/
  27. /*  If you use YamTools you can use this one as a TYPE=ONCE to apply to mail  */
  28. /*  selected one at a time from YAM, or TYPE=MAIL to do all mail selected     */
  29. /*  from a YamTools list.  Remember that you CAN define two buttons using     */
  30. /*  same script but with different TYPES.                                     */
  31. /*                                                                            */
  32. /*  If you don't use YamTools--why not;)                                      */
  33. /*                                                                            */
  34. /*----------------------------------------------------------------------------*/
  35. /*                                                                            */
  36. /* Standard Disclaimer: I wrote it, it works for me, I don't guarantee        */
  37. /* that it will do anything productive for anyone else, etc. etc. ;-)         */
  38. /*                                                                            */
  39. /*HOWEVER, if you DO find a use for it: I homeschool my kids and they         */
  40. /*would love a postcard from where EVER you live.                             */
  41. /*                                                                            */
  42. /*Instant GEOGRAPHY lesson;)                                                  */
  43. /*                                                                            */
  44. /*                                                                            */
  45. /*POSTCARDS:    Dick Whiting                                                  */
  46. /*              28590 S. Beavercreek Rd.                                      */
  47. /*              Mulino, Oregon 97042                                          */
  48. /*              USA                                                           */
  49. /*                                                                            */
  50. /*----------------------------------------------------------------------------*/
  51. /*                                                                            */
  52. /*               Address Bug Reports or Comments to:                          */
  53. /*                Dick Whiting <dwhiting@europa.com>                          */
  54. /*                            14 July 1997                                    */
  55. /*                                                                            */
  56. /******************************************************************************/
  57. /*
  58. $VER: 1.0 Copyright ©1997 by Dick Whiting
  59. $AUTHOR: Dick Whiting
  60. $DESCRIPTION: Strip attachments and MIME warning message from mail
  61. */
  62.  
  63. options results
  64.  
  65. stripleader=1           /* change this to 0 to NOT strip MIME warning message */
  66.  
  67. argpassed=''
  68. parse arg argpassed 
  69.  
  70. Call Localize
  71.  
  72. /******************************************************************************/
  73. /*  Find out the necessary information about the file                         */
  74. /******************************************************************************/
  75. Init:
  76.  
  77. if ~show('L','rexxsupport.library') then do
  78.    addlib('rexxsupport.library',0,-30)
  79. end
  80.  
  81. Address YAM 'getmailinfo file'
  82. mfile=result
  83. slpos=lastpos('/',mfile)
  84. copos=lastpos(':',mfile)
  85. filename=strip(substr(mfile,max(slpos,copos)+1))
  86. tmpfile = 'T:'||filename                              /* temporary file       */
  87. fstate=statef(mfile)                                  /* file information     */
  88. fbytes=subword(fstate,2,1)                            /* length of file       */
  89. fdate=subword(fstate,5,1)                             /* internal date        */
  90. fmins=subword(fstate,6,1)                             /* minutes since midnite*/
  91. fticks=subword(fstate,7,1)                            /* ticks past minutes   */
  92. fcomm=subword(fstate,8)                               /* old comment          */
  93.  
  94. fdate=date('E',fdate,'I')                             /* get date in ddmmyy   */
  95. fdate=translate(fdate,'-','/')                        /* convert / to -       */
  96. hh=fmins%60                                           /* get hours            */
  97. hh=right(hh,2,'0')                                    /* force to 2 digits    */
  98. mm=fmins//60                                          /* get minutes          */
  99. mm=right(mm,2,'0')                                    /* force to 2 digits    */
  100. ss=fticks%50                                          /* seconds              */
  101. ss=right(ss,2,'0')                                    /* force it             */
  102. ftime=hh||':'||mm||':'||ss                            /* timestamp rebuilt    */
  103.  
  104. TRUE=1
  105. FALSE=0
  106. multipart=FALSE
  107. uu=FALSE
  108. header=TRUE
  109. boundnum=0
  110. lf='0A'x
  111. hl='#'
  112. striptst='#'||stripmsg
  113. writeatt=FALSE
  114. attname=''
  115. outopen=FALSE
  116. tab='09'x
  117. date=' -- '||date()
  118.  
  119. /******************************************************************************/
  120. /*  Do the actual stripping of the mail file.                                 */
  121. /******************************************************************************/
  122. StripFile:
  123.  
  124. if open('OUT',tmpfile,'W') then do
  125.    outopen=TRUE
  126.    if open('IN',mfile,'R') then do
  127.       do until eof('IN')
  128.          linein = readln('IN')
  129.          writeit=TRUE
  130.          select
  131.             when header & linein='' then header=FALSE
  132.             when header & upper(word(linein,1))='CONTENT-TYPE:' then do
  133.                boundpos=pos('BOUNDARY=',upper(linein))
  134.                if boundpos>0 then do
  135.                   boundary=substr(linein,boundpos+9)
  136.                   boundary=strip(boundary,'B','"')
  137.                   if boundary~='' then do 
  138.                      boundary='--'||boundary
  139.                      endbound=boundary||'--'
  140.                      multipart=TRUE
  141.                   end
  142.                end
  143.             end
  144.             when header then do
  145.                tline=translate(linein,' ',tab)
  146.                if right(word(tline,1),1)~=':' & substr(tline,1,1)~=' ' then do
  147.                   say linein
  148.                   header=FALSE
  149.                   foo=writeln('OUT','')
  150.                end
  151.             end
  152.             when multipart then do
  153.                select
  154.                   when linein=boundary then do
  155.                      boundnum=boundnum+1
  156.                      if boundnum=1 & stripleader then do
  157.                         stripline=hl||leadermsg||hl||lf
  158.                         foo=writeln('OUT',stripline)
  159.                      end
  160.                      if boundnum>2 then do
  161.                         stripline=lf||hl||stripmsg||attname||hl||lf
  162.                         foo=writeln('OUT',stripline)
  163.                         writeatt=FALSE
  164.                         attname=''
  165.                      end
  166.                   end
  167.                   when linein=endbound then do 
  168.                      stripline=lf||hl||stripmsg||attname||hl||lf
  169.                      foo=writeln('OUT',stripline)
  170.                      multipart=FALSE
  171.                      writeatt=FALSE
  172.                      attname=''
  173.                   end
  174.                   when boundnum=0 then do
  175.                      if stripleader then writeit=FALSE
  176.                   end
  177.                   when boundnum>1 then do 
  178.                      if upper(word(linein,1))='CONTENT-TYPE:' then do
  179.                         if pos('NAME=',upper(linein))>0 then do
  180.                            tline=upper(linein)
  181.                            parse var tline junk 'NAME=' attname
  182.                            attname=strip(attname,'B','"')
  183.                            attname=attname||date
  184.                            writeatt=TRUE
  185.                         end                     
  186.                      end
  187.                      else do
  188.                         if pos(striptst,linein) then do
  189.                            attname=subword(linein,3)
  190.                            attname=strip(attname,'T','#')
  191.                            writeatt=TRUE
  192.                         end
  193.                      end
  194.                      writeit=FALSE
  195.                   end
  196.                   otherwise nop 
  197.                end
  198.             end
  199.             when ~multipart then do
  200.                select
  201.                   when upper(word(linein,1))='BEGIN' & word(linein,2)='644' then do
  202.                      attname=strip(subword(linein,3),'B')
  203.                      stripline=lf||hl||stripmsg||attname||hl||lf
  204.                      foo=writeln('OUT',stripline)
  205.                      attname=''
  206.                      uu=TRUE
  207.                      writeit=FALSE
  208.                   end
  209.                   when uu & strip(linein)='end' then do
  210.                      uu=FALSE
  211.                      writeit=FALSE
  212.                   end  
  213.                   when uu then do 
  214.                      select
  215.                         when strip(linein,'B')='' then writeit=FALSE
  216.                         when verify('aeiou',linein,'MATCH')=0 then writeit=FALSE
  217.                         otherwise uu=FALSE
  218.                      end
  219.                   end
  220.                   otherwise nop
  221.                end
  222.             end
  223.             otherwise nop
  224.          end
  225.          if writeit then do
  226.             foo=writeln('OUT',linein)
  227.          end
  228.       end
  229.       if writeatt then do
  230.          stripline=lf||hl||stripmsg||attname||hl||lf
  231.          foo=writeln('OUT',stripline)
  232.          if multipart then do
  233.             foo=writeln('OUT',endbound)
  234.          end
  235.       end
  236.       foo=close('IN')
  237.       foo=close('OUT')
  238.       outopen=FALSE
  239.       Address Command 'C:Copy 'tmpfile' 'mfile 
  240.       Address Command 'SetDate  ' mfile fdate ftime 
  241.       Address Command 'Filenote ' mfile '"'fcomm'"' 
  242.    end
  243.    if outopen then do
  244.       foo=close('OUT')
  245.    end
  246.    Address Command 'Delete 'tmpfile 'QUIET'
  247. end
  248.  
  249. if argpassed='' then do
  250.    Address YAM 'request "'donemsg'" "'yesnomsg'"'
  251.    ans=result
  252.    if ans=1 then do
  253.       Address YAM 'mailupdate'
  254.    end
  255. end
  256.  
  257. exit
  258.  
  259. /******************************************************************************/
  260. /*  Variables available for localization.                                     */
  261. /******************************************************************************/
  262. Localize:
  263.  
  264. donemsg='Done..Update Index?'
  265. yesnomsg='Yes|No'
  266. stripmsg='Stripped Attachment: '  /* message for stripping MIME warning */
  267. leadermsg='Stripped Mime Warning' /* message for stripping attachments  */
  268.  
  269.  
  270.