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

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*                             ReDate.rexx                                    */
  4. /*                 Copyright ©1997 by Dick Whiting                            */
  5. /*                                                                            */
  6. /*----------------------------------------------------------------------------*/
  7. /*                                                                            */
  8. /*  This one changes the  Date: header in a mail to the date/time that it     */
  9. /*  was received. Most useful for handling mail sent by people without        */
  10. /*  a valid clock. Not sure what happens if YOU don't have one.               */
  11. /*                                                                            */
  12. /*  I decided to NOT use the date/timestamp of the file itself, since so      */
  13. /*  many of the scripts that I have seen update it. Instead, I use the        */
  14. /*  filename to determine the date and use the timestamp from the original    */
  15. /*  Date: header to build the new one. This seems to be the best compromise.  */
  16. /*                                                                            */
  17. /*  NOTE: This one, like my other ones, retains the date/timestamp of the     */
  18. /*  original mail.                                                            */
  19. /*                                                                            */
  20. /*  NOTE: Changes won't be visible in Yam until you do an UPDATE INDEX.       */
  21. /*                                                                            */
  22. /*----------------------------------------------------------------------------*/
  23. /*  If you use YamTools you can use this one as a TYPE=ONCE to apply to mail  */
  24. /*  selected one at a time from YAM, or TYPE=MAIL to do all mail selected     */
  25. /*  from a YamTools list.  Remember that you CAN define two buttons using     */
  26. /*  same script but with different TYPES.                                     */
  27. /*                                                                            */
  28. /*  If you don't use YamTools--why not;)                                      */
  29. /*                                                                            */
  30. /*----------------------------------------------------------------------------*/
  31. /* Standard Disclaimer: I wrote it, it works for me, I don't guarantee        */
  32. /* that it will do anything productive for anyone else, etc. etc. ;-)         */
  33. /*                                                                            */
  34. /*HOWEVER, if you DO find a use for it: I homeschool my kids and they         */
  35. /*would love a postcard from where EVER you live.                             */
  36. /*                                                                            */
  37. /*Instant GEOGRAPHY lesson;)                                                  */
  38. /*                                                                            */
  39. /*                                                                            */
  40. /*POSTCARDS:    Dick Whiting                                                  */
  41. /*              28590 S. Beavercreek Rd.                                      */
  42. /*              Mulino, Oregon 97042                                          */
  43. /*              USA                                                           */
  44. /*                                                                            */
  45. /*----------------------------------------------------------------------------*/
  46. /*                                                                            */
  47. /*               Address Bug Reports or Comments to:                          */
  48. /*                Dick Whiting <dwhiting@europa.com>                          */
  49. /*                            06 May 1997                                     */
  50. /*                                                                            */
  51. /******************************************************************************/
  52. /*
  53. $VER: 1.1 Copyright ©1997 by Dick Whiting
  54. $AUTHOR: Dick Whiting
  55. $DESCRIPTION: Change Date: header in mail to the date received 
  56. */
  57.  
  58. options results
  59. ADDRESS YAM
  60.  
  61. if ~show('L','rexxsupport.library') then do
  62.    addlib('rexxsupport.library',0,-30)
  63. end
  64.  
  65. argpassed=''
  66. parse arg argpassed 
  67.  
  68. Call Localize
  69.  
  70. /******************************************************************************/
  71. /*  Find out the necessary information about the file                         */
  72. /******************************************************************************/
  73.  
  74. 'getmailinfo file'
  75. mfile=result
  76. slpos=lastpos('/',mfile)
  77. copos=lastpos(':',mfile)
  78. filename=strip(substr(mfile,max(slpos,copos)+1))
  79. parse var filename fdate '.' rest                     /* fn=internal date     */
  80. dow=substr(date('W',fdate,'I'),1,3)                   /* day of week received */
  81. normdate=date('N',fdate,'I')                          /* date received        */
  82. fstate=statef(mfile)                                  /* file information     */
  83. fbytes=subword(fstate,2,1)                            /* length of file       */
  84. fdate=subword(fstate,5,1)                             /* internal date        */
  85. fmins=subword(fstate,6,1)                             /* minutes since midnite*/
  86. fticks=subword(fstate,7,1)                            /* ticks past minutes   */
  87. fcomm=subword(fstate,8)                               /* old comment          */
  88.  
  89. fdate=date('E',fdate,'I')                             /* get date in ddmmyy   */
  90. fdate=translate(fdate,'-','/')                        /* convert / to -       */
  91. hh=fmins%60                                           /* get hours            */
  92. hh=right(hh,2,'0')                                    /* force to 2 digits    */
  93. mm=fmins//60                                          /* get minutes          */
  94. mm=right(mm,2,'0')                                    /* force to 2 digits    */
  95. ss=fticks%50                                          /* seconds              */
  96. ss=right(ss,2,'0')                                    /* force it             */
  97. ftime=hh||':'||mm||':'||ss                            /* timestamp rebuilt    */
  98.  
  99. /******************************************************************************/
  100. /*  Read the selected mail and replace the Date: header.                      */
  101. /******************************************************************************/
  102.  
  103. if open('IN',mfile,'R') & open('OUT','T:fdate.tmp','W') then do
  104.    do until eof('IN')
  105.       linein=readln('IN')
  106.       if substr(linein,1,6)='Date: ' then do
  107.          copos=lastpos(':',linein)                 /* find last : in time     */
  108.          mtime=substr(linein,copos-5)              /* timestamp of sender     */      
  109.          datestamp='Date: '||dow||', '||normdate||' '||mtime
  110.          foo=writeln('OUT',datestamp)
  111.          do until eof('IN')
  112.             blockin=readch('IN',20480)             /* grab BIG chunks now     */
  113.             foo=writech('OUT',blockin)
  114.          end
  115.          signal cleanup
  116.       end
  117.       foo=writeln('OUT',linein)
  118.    end
  119. end
  120.  
  121. CLEANUP:
  122.  
  123. /******************************************************************************/
  124. /*  Should be all done. Close files, replace mail with temp, and cleanup      */
  125. /******************************************************************************/
  126.  
  127. foo=close('IN')
  128. foo=close('OUT')
  129.  
  130. Address Command 'SetDate T:fdate.tmp 'fdate ftime
  131. Address Command 'Filenote T:fdate.tmp "'fcomm'"'
  132. Address Command 'Copy T:fdate.tmp TO ' mfile 'CLONE QUIET'
  133. Address Command 'Delete T:fdate.tmp QUIET'
  134.  
  135. if argpassed='' then do
  136.    Address YAM 'request "'donemsg'" "'yesnomsg'"'
  137.    ans=result
  138.    if ans=1 then do
  139.       Address YAM 'mailupdate'
  140.    end
  141. end
  142.  
  143. exit
  144.  
  145. /******************************************************************************/
  146. /*  Variables available for localization.                                     */
  147. /******************************************************************************/
  148. Localize:
  149.  
  150. donemsg='Done..Update Index?'
  151. yesnomsg='Yes|No'
  152.  
  153.  
  154.