home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ice4ward.zip / ice4ward.cmd next >
OS/2 REXX Batch file  |  1997-04-13  |  5KB  |  181 lines

  1. /* ice4ward.cmd */
  2. /* master routine for mail forwarding */
  3. /* invoke this as ice4ward 2>&1 | tee ice4ward.log   */
  4. call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  5. call SysLoadFuncs
  6.  
  7. trace r
  8.  
  9. /* dependencies:  (all must be reachable by the PATH except for mailto.exe)
  10.    zip.exe     infozip zip utility
  11.    mailto.exe  (in mr2ice directory; need one later than 1.26 that
  12.                 doesn't have a length limitation)
  13.    killem.exe   kills process by name of executable (orprocess #)
  14.    uuencode.exe standard utility available from various sources
  15. */
  16. parmfile=ice4ward.prm
  17. msgfil= 'ice4msg.fil'
  18. counterfil='ice4cou.fil'
  19.  
  20. /* parameterized (but not tested as such) */
  21.  
  22.  
  23. call readparms
  24.  
  25. /* this is the outer timing loop */
  26. do forever
  27. dat= date('s')
  28. t=time('M')
  29. /* next line is for test */
  30. select
  31. when params.test=1 then w=0
  32. /* need to overhaul this approach */
  33. when t<params.t1 then w=params.t1-t
  34. when t<params.t2 then w=params.t2-t
  35. when t<params.t3 then w=params.t3-t
  36. when t<params.t4 then w=params.t4-t
  37. when t<params.t5 then w=params.t5-t
  38. otherwise w= (24*60)+params.t1-t    /* next day */
  39. end    /* select */
  40.  
  41. say 'waiting ' w ' minutes'
  42. s=syssleep(w*60)
  43.  
  44. xs=stream('i4wtime.log','c','open write');
  45. xs=stream('i4wtime.log','c','seek<0');
  46. xs=lineout('i4wtime.log',date('s') time());
  47. xs=stream('i4wtime.log','c','close');
  48.  
  49. call forward
  50. if params.test=1 then leave   /* for testing */
  51. end  /* do forever */
  52.  
  53. /* leave comes here */
  54. 'echo FINI ----------' dat time() ' >> i4wtime.log'
  55. exit
  56.  
  57. forward: procedure expose params.
  58. /*   this is the procedure that calls the ISP and collects the messages */
  59. /* strategy:
  60.    1.  call ISP
  61.    2.  wait 1 min
  62.    3.  invoke mr2i /x (gets mail, then exits)
  63.    4.  call msgmake (builds msgcat, zip, uuencode and msgfil)
  64.    5.  mailto
  65.    5a.  long wait for mailto to complete 
  66.    6.  killem ppp
  67.    7.  end and go back into outer loop to wait for next trigger     */
  68.  
  69.  
  70. mydir=directory()   /* save current directory for later */
  71. xx=directory(params.tcp)
  72. /* 1. call epix */
  73. /* params.dialup */
  74. '@start' params.dialup 
  75.  
  76. /* wait a bit */
  77. say 'waiting' params.wait1 'sec to ensure connection'
  78. s=SysSleep(params.wait1)
  79.  
  80. /* 3.  callauto - get ice mail */
  81. /* call mr2ice */
  82. xx = directory(params.icedir)
  83. 'mr2i.exe /t /x'
  84.  
  85. /* 4. msgmake builds the messages */
  86. here:
  87. xx=directory(mydir)
  88. call msgmake
  89.  
  90. /* 5. mailto */
  91. params.icedir||"\mailto" msgfil params.to params.mailhost
  92.  
  93. /* rc = -4 if no connection */
  94.  
  95. /*  6.  wait a bit then knock down ppp */
  96. say 'waiting' params.wait2 'sec before killing ppp'
  97. s=SysSleep(params.wait2)
  98. 'killem ppp'
  99. return         /* end of forward procedure */
  100.  
  101.  
  102. msgmake: procedure expose params.
  103. /* this collects the messages and packages them for sending  */
  104. 'xcopy '||params.folder||'*.rcv .' 
  105. 'erase '||params.folder||'*.rcv'
  106.  
  107. 'rxqueue /clear'
  108. 'dir /b *.rcv | rxqueue'
  109. work= queued()
  110. say ' processing ' work ' messages'
  111. if work>0 then do
  112. msgno=linein(counterfil)
  113. if msgno='' then msgno=1
  114. is=stream(counterfil,'c','close')
  115. '@erase' counterfil
  116. is=stream(counterfil,'c','open write')
  117. is=lineout(counterfil,msgno+1)
  118. is=stream(counterfil,'c','close')
  119.  
  120. 'zip mz'||msgno||' *.rcv' 
  121. do while queued()>0
  122.    parse pull filnam
  123.    'echo =+=+=+=+ ' filnam '>>mcat'||msgno
  124.    'type' filnam '>> mcat'||msgno
  125.    end
  126.  
  127. 'erase autm*.zip'
  128. 'zip autm'||msgno 'mcat'||msgno
  129. 'erase *.rcv'
  130. 'erase mcat'||msgno
  131. end /* work >0 */
  132.  
  133. '@erase' msgfil
  134. os=lineout(msgfil,params.from) /* 'From: JT autosend <jt@epix.net>')  */
  135. dayte=date()
  136. dow=date('W')
  137. tim=time()
  138. parse var dayte da rest
  139. if da<10 then da='0'||da
  140. datlin='Date: '||left(dow,3)||', '||da rest tim params.tzx
  141. os=lineout(msgfil,datlin)
  142. os=lineout(msgfil,'To: '||params.to)
  143. os=lineout(msgfil,'Subject: autobatch number '||msgno)
  144. os=lineout(msgfil,' ')
  145. os=lineout(msgfil,' ')
  146. os=lineout(msgfil,work 'messages this batch')
  147. if work>0 then do
  148.    os=stream(msgfil,'c','close')
  149.    'uuencode autm'||msgno||'.zip autm'||msgno||'.zip >>' msgfil
  150.     os=lineout('spaces','     ')
  151.     os=lineout('spaces')
  152.     'type spaces >>' msgfil
  153.     'erase spaces'
  154.     os=stream(msgfil,'c','open')
  155.     os=stream(msgfil,'c','seek <0')
  156.     end
  157. os=lineout(msgfil,' ')
  158. os=lineout(msgfil,'  - - - - - end msg batch  - - - -')
  159. os=stream(msgfil,'c','close')
  160.  
  161. return /* end of msgmake procedure */
  162.  
  163.  
  164. /* read params  */
  165. readparms: procedure  expose params. parmfile
  166.  
  167. params.='***'
  168. is=stream(parmfile,'c','open read')
  169.  
  170. do while lines(parmfile)
  171.    line=strip(linein(parmfile)) 
  172.    if line='' then iterate
  173.    if left(line,2) = '/'||'*' then iterate
  174.    if left(line,1) = ';' then iterate
  175.    parse var line parm '=' value
  176.    parm=strip(translate(parm))
  177.    params.parm=strip(value)
  178.    end
  179. is=stream(parmfile,'c','close') 
  180. return
  181.