home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1997 #5 / AmigaPlus_Extra-CD_5-97.iso / online-tools / mail / yamtools1.7 / redate.rexx < prev    next >
OS/2 REXX Batch file  |  1997-05-06  |  8KB  |  135 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.0 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. /******************************************************************************/
  66. /*  Find out the necessary information about the file                         */
  67. /******************************************************************************/
  68.  
  69. 'getmailinfo file'
  70. mfile=result
  71. slpos=lastpos('/',mfile)
  72. copos=lastpos(':',mfile)
  73. filename=strip(substr(mfile,max(slpos,copos)+1))
  74. parse var filename fdate '.' rest                     /* fn=internal date     */
  75. dow=substr(date('W',fdate,'I'),1,3)                   /* day of week received */
  76. normdate=date('N',fdate,'I')                          /* date received        */
  77. fstate=statef(mfile)                                  /* file information     */
  78. fbytes=subword(fstate,2,1)                            /* length of file       */
  79. fdate=subword(fstate,5,1)                             /* internal date        */
  80. fmins=subword(fstate,6,1)                             /* minutes since midnite*/
  81. fticks=subword(fstate,7,1)                            /* ticks past minutes   */
  82. fcomm=subword(fstate,8)                               /* old comment          */
  83.  
  84. fdate=date('E',fdate,'I')                             /* get date in ddmmyy   */
  85. fdate=translate(fdate,'-','/')                        /* convert / to -       */
  86. hh=fmins%60                                           /* get hours            */
  87. hh=right(hh,2,'0')                                    /* force to 2 digits    */
  88. mm=fmins//60                                          /* get minutes          */
  89. mm=right(mm,2,'0')                                    /* force to 2 digits    */
  90. ss=fticks%50                                          /* seconds              */
  91. ss=right(ss,2,'0')                                    /* force it             */
  92. ftime=hh||':'||mm||':'||ss                            /* timestamp rebuilt    */
  93.  
  94. /******************************************************************************/
  95. /*  Read the selected mail and replace the Date: header.                      */
  96. /******************************************************************************/
  97.  
  98. if open('IN',mfile,'R') & open('OUT','T:fdate.tmp','W') then do
  99.    do until eof('IN')
  100.       linein=readln('IN')
  101.       if substr(linein,1,6)='Date: ' then do
  102.          copos=lastpos(':',linein)                 /* find last : in time     */
  103.          mtime=substr(linein,copos-5)              /* timestamp of sender     */      
  104.          datestamp='Date: '||dow||', '||normdate||' '||mtime
  105.          foo=writeln('OUT',datestamp)
  106.          do until eof('IN')
  107.             blockin=readch('IN',20480)             /* grab BIG chunks now     */
  108.             foo=writech('OUT',blockin)
  109.          end
  110.          signal cleanup
  111.       end
  112.       foo=writeln('OUT',linein)
  113.    end
  114. end
  115.  
  116. CLEANUP:
  117.  
  118. /******************************************************************************/
  119. /*  Should be all done. Close files, replace mail with temp, and cleanup      */
  120. /******************************************************************************/
  121.  
  122. foo=close('IN')
  123. foo=close('OUT')
  124.  
  125. Address Command 'SetDate T:fdate.tmp 'fdate ftime
  126. Address Command 'Filenote T:fdate.tmp "'fcomm'"'
  127. Address Command 'Copy T:fdate.tmp TO ' mfile 'CLONE QUIET'
  128. Address Command 'Delete T:fdate.tmp QUIET'
  129.  
  130. exit
  131.  
  132. /******************************************************************************/
  133. /*  END OF ACTIVE CODE                                                        */
  134. /******************************************************************************/
  135.