home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / bagmak10.zip / BAGMAKE.CMD < prev   
OS/2 REXX Batch file  |  1995-12-03  |  7KB  |  220 lines

  1. /* make new .bag file for pmmail from *.msg*/
  2. /* 
  3.  Rexx for OS/2
  4.  Program written by:
  5.  Jerry L. Rowe, 12/1/95
  6.  Marion, IN USA
  7.  jlrowe@holli.com, IMJerry@aol.com
  8.  [Team OS/2, IBM BESTeam]
  9.  
  10.  This Rexx script is for PMMail 1.x. 
  11.  
  12.  The purpose is the re-create the [foldername].bag files with exist in the
  13.  x:\PMMail directory. These files can become corrupted, erased, inaccurate,
  14.  or whatever. The messages will still exist, but the list of them [the 
  15.  bagfile] may be wrong. This script is my attempt at fixing them. The 
  16.  script is the result of work due to lost bagfiles on my own system.
  17.  
  18.  It creates the bag files, but leaves them in the x:\PMMail\folders 
  19.  directory. It is up to the user to copy them to x:\PMMail since doing so
  20.  will erase the existing files. I suggest that you back up the existing files
  21.  first.
  22.  
  23.  It should be executed from the
  24.  x:\PMMail
  25.  directory on your hard disk, or whatever directory your PMMail is
  26.  installed in.
  27.  
  28.  You can execute the script by:
  29.  bagmake [enter]                  (to make all of the files)
  30.  or
  31.  bagmake [foldername] [Enter]     (to make just one)
  32.  
  33.  As a bonus, it also makes FOLDERS.TXT, which is an emergency replacement
  34.  for FOLDERS.INI in case that file has been lost. Long folder names  [the
  35.  first occurence of the name in the file] as used in PMMail are NOT recreated
  36.  since there is no way of knowing them. You can edit this file with a text
  37.  editor to change that if you want.
  38.  
  39.  Cheers,
  40.  
  41.  Jerry
  42.  */
  43.  
  44. folderini=''
  45. outline=''
  46. inline=''
  47. eline=''
  48. infile=''
  49. mdate=''
  50. mtime=''
  51. mmsg=''
  52. email=''
  53. ename=''
  54. mfile=filein
  55. msep=x2c('DE')
  56. mread=x2c('59E1')
  57. munread=x2c('4EE1')
  58. mmon=''
  59. mday=''
  60. myr=''
  61. totalfiles=0
  62.  
  63. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  64. call SysLoadFuncs
  65.  
  66. Parse arg folder
  67. if folder='' then do
  68.     folder='folders\*.'
  69.     folderini='folders.txt'
  70. end
  71.  
  72.    
  73. call sysfiletree folder,"filedir",'DO'
  74. if filedir.0=0 then do
  75.     say 'Directory not found, exiting...'
  76.     exit
  77. end
  78. else
  79.     if filedir.0 \= 0 then do
  80.         if folderini\='' then
  81.         rc=lineout(folderini,,1)/* open folders.txt */
  82.         
  83.         do Q= 1 to filedir.0
  84.             if folderini\='' then do /* Add items to folder.txt[ini] */
  85.                 folderitem=delstr(filedir.Q,1,lastpos('\',filedir.Q))
  86.                 rc=sysfiledelete(folderini)
  87.                 rc=lineout(folderini,folderitem)
  88.                 rc=lineout(folderini,folderitem)
  89.                 rc=lineout(folderini,n)
  90.             end
  91.             outfile=filedir.Q||'.bag'
  92.             say 'Creating bagfile: 'outfile
  93.             call processfiles
  94.         end
  95.     end
  96. if folderini\='' then do
  97.     rc=lineout(folderini) /* close FOLDERS.TXT if open */
  98. end
  99. Say 'Finished, Total Msg files processsed: ' totalfiles
  100.  
  101. exit /* program */
  102.  
  103. processfiles:    
  104.  
  105. call sysfiletree filedir.Q||"\*.*","file",'FO'
  106.     if file.0 \= 0 then do
  107.         totalfiles=totalfiles+file.0
  108.         rc=sysfiledelete(outfile)
  109.         rc=lineout(outfile,,1)
  110.         rc=lineout(outfile,file.0)
  111.         parse value syscurpos() with row col
  112.         say row col
  113.         if row=24 then row = 23
  114.         do I= file.0 to 1 by -1
  115.         /*         trace commands  */
  116.             cp=syscurpos(row,col)
  117.             say 'MsgFile #: 'Q'-'I'                   '
  118.  
  119.             call readfile
  120.             call putbagline
  121.             rc=lineout(file.i) /* close infile */
  122.         end
  123.         rc=lineout(outfile) /* close outfile */
  124.     end
  125.     else
  126.         say "No msg files found"
  127. return
  128.  
  129. putbagline:
  130.     rc=lineout(outfile,outline)
  131. return
  132.  
  133. sayfile:
  134. /*     say 'File: 'file.i
  135.     say 'reading'
  136.     say 'date: 'mdate
  137.     say 'email='email
  138.     say '  ename='ename
  139.     say 'Subject: 'mmsg
  140.     say 'OutLine:'Outline
  141.  */    
  142.     say i': 'Outline
  143.     say
  144.     
  145. return
  146.     
  147. Readfile:
  148.     rc=linein(file,I,0)
  149. /*     trace off
  150.     say 'Lines ('file.I')#: 'lines(file.I)  */
  151.     inline='a'
  152.     do while ((lines(file.I)>0) & (length(inline)>0))
  153.         inline=linein(file.I)
  154.         eline=inline
  155. /*          say 'Line: 'eline */
  156.         select
  157.             when pos('From: ',eline)=1 then do
  158.                 eline=delstr(eline,1,6)
  159.                 tn=0
  160.                 do until tw=''
  161.                     tn=tn+1
  162.                     tw=word(eline,tn)
  163.                     if pos('@',tw)>0 then do
  164.                         email=tw
  165.                         emailn=pos(email,eline)
  166.                         ename=strip(delstr(eline,emailn,length(email)))
  167.                         if pos('<',email)=1 then do
  168.                             email=delstr(email,1,1)
  169.                             email=left(email,length(email)-1)
  170.                         end
  171.                         emailn=tn
  172.                     end /* if */
  173.                 end /* do */
  174.             end /* do */
  175.  
  176.             when pos('Subject: ',eline)=1 then do
  177.                 mmsg=strip(delstr(eline,1,9))
  178.                 mmsg=strip(left(mmsg,34))
  179.             end /* do */
  180.             
  181.             when pos('Date: ',eline)=1 then do
  182.                 parse upper var eline intro wkday mday mmonth myr mtime gmt
  183.                 if datatype(wkday,N)=1 then
  184.                     parse upper var eline intro mday mmonth myr mtime gmt
  185.                 if length(myr)=4 then 
  186.                     myr=right(myr,2)
  187.                 mtime=translate(mtime,'0123456789 ','0123456789:')
  188.                 parse var mtime mhr mmin msec
  189.                 mhr=right(mhr,2,'0')
  190.                 mmin=right(mmin,2,'0')
  191.                 msec=right(msec,2,'0')
  192.                 mtime=mhr||':'||mmin||':'||msec
  193.                 select
  194.                     when mmonth='JAN' then mmon='01'
  195.                     when mmonth='FEB' then mmon='02'
  196.                     when mmonth='MAR' then mmon='03'
  197.                     when mmonth='APR' then mmon='04'
  198.                     when mmonth='MAY' then mmon='05'
  199.                     when mmonth='JUN' then mmon='06'
  200.                     when mmonth='JUL' then mmon='07'
  201.                     when mmonth='AUG' then mmon='08'
  202.                     when mmonth='SEP' then mmon='09'
  203.                     when mmonth='OCT' then mmon='10'
  204.                     when mmonth='NOV' then mmon='11'
  205.                     when mmonth='DEC' then mmon='12'
  206.                     otherwise mmon=''
  207.                 end
  208.             end
  209.             otherwise
  210.         end
  211.     end
  212.     if length(mmon) = 1 then mmon='0'||mmon
  213.     if length(mday) = 1 then mday='0'||mday
  214.     if length(mtime) =5 then mtime=mtime||':00'
  215.     mdate=myr || '-' || mmon || '-' || mday
  216.     infile=right(file.i,length(file.i)-lastpos('\',file.i))
  217.     infile=translate(infile,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  218.     outline=mdate||msep||mtime||msep||mmsg||msep||ename||msep||email||msep||infile||msep||mread
  219. return
  220.