home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / fwd-1.0.zip / forward.cmd < prev    next >
OS/2 REXX Batch file  |  2000-10-29  |  4KB  |  125 lines

  1. /*------------------------------------------------------------------
  2.  * forward.cmd ver 1.0 by Nick Lepehin nickk@myflat.com 
  3.  * based on  getpop.cmd by Christoph Lechleitner
  4.  * This script fetches mail from pop3 server and forwards it to smtp server
  5.  * multithreaded (uses rexxipc.dll)
  6.  * controls hangs sockrcv function
  7.  * uses auxiliary cmd files : process.cmd & sockrcv.cmd
  8.  *------------------------------------------------------------------*/
  9.  
  10. trace off
  11.  
  12. parse arg filelist smtpserver logfile tempfdir
  13. filelist=space(filelist)
  14. smtpserver=space(smtpserver)
  15. tempfdir=space(tempfdir)
  16. logfile=space(logfile)
  17.  
  18. if (filelist='')|(smtpserver='')|(logfile='')|(tempfdir='') then
  19.    do
  20.    say "Usage: forward <config> <smtpserver to forward to> <logfile name> <dir for store temp files>"
  21.    exit 1
  22.    end
  23.  
  24. rc=stream(filelist,'c','open read')
  25. rc1=stream(logfile,'c','open write')
  26.  
  27. if (rc<>"READY:")|(rc1<>"READY:")|(lines(filelist)=0) then
  28.    do
  29.    say "Usage: forward <config> <smtpserver to forward to> <logfile name> <dir for store temp files>"
  30.    exit 1
  31.    end
  32.  
  33.  
  34. entrynum=0
  35. do while lines(filelist)=1 
  36.  curline=linein(filelist)
  37.  if left(curline,1)<>';' then
  38.   do
  39.    entrynum=entrynum+1
  40.    parse var curline servers.entrynum users.entrynum passwords.entrynum forwards.entrynum keeps.entrynum
  41.    if (servers.entrynum = "")|(users.entrynum ='')|(passwords.entrynum ='')|(forwards.entrynum ='') then
  42.     do
  43.      say "Wrong format of config file."
  44.      say "Should be: <pop3server> <user> <password> <forwarding address> [<keep>]" 
  45.      exit 1
  46.     end
  47.   end
  48. end
  49.  
  50. call saynlog ' '
  51. /* call saynlog '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' */
  52. call saynlog substr(x2c('DB'),1,79,x2c('DB'))
  53. call saynlog '----------Forward.cmd started 'Date('E')' at 'time()'-----------'
  54. call saynlog 'Was found 'entrynum' entries in config file'
  55.  
  56. /*------------------------------------------------------------------
  57.  * initialize function packages
  58.  *------------------------------------------------------------------*/
  59.  
  60. call RxFuncAdd 'SysTempFileName', 'RexxUtil', 'SysTempFileName'
  61. if RxFuncQuery("SockLoadFuncs") then
  62.    do
  63.     rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
  64.     rc = SockLoadFuncs()
  65.    end
  66.  
  67. if RxFuncQuery("IPCLoadFuncs") then
  68.    do
  69.     call RxFuncAdd 'IPCLoadFuncs', 'REXXIPC', 'IPCLoadFuncs'
  70.     call IPCLoadFuncs
  71.    end
  72.  
  73. /*-------------Starting processing the server list------------------*/
  74. do cenum=1 to entrynum
  75.  StartMessage.cenum=' 'x2c('FE')' Processing 'cenum' entry: Start at 'time('L')
  76.  logc=logfile||'.l'||cenum
  77.  call IPCContextCreate context.cenum
  78.  call ProcCreateThread context.cenum, 'process.cmd', servers.cenum, users.cenum, passwords.cenum, forwards.cenum, keeps.cenum, cenum, smtpserver, logc, tempfdir 
  79.  if result\=0 then call saynlog 'Error creating thread 'cenum' :'result
  80.  call syssleep 0.5 /* Sometimes proccreatethread results error : process.cmd can't be read */
  81. end
  82.  
  83. do cenum=1 to entrynum
  84.  call IpcContextWait context.cenum
  85.  call saynlog StartMessage.cenum||'. End at 'time('L')' 'x2c('FE')
  86. end
  87.  
  88. fmask=logfile||'.l*'
  89. rc=SysFileTree(fmask,'res','FO')
  90. do i= 1 to res.0
  91.  call lineout logfile, substr(x2c('DC'),1,79,x2c('DC'))
  92.  fname=logfile||'.l'||i
  93.  do while lines(fname)
  94.   call lineout logfile, linein(fname)
  95.  end
  96.  rc=stream(fname,'c','close')
  97.  '@del 'fname
  98. end
  99.  
  100. call saynlog '----------Forward.cmd finished 'Date('E')' at 'time()'----------'
  101. rc=stream(logfile,'c','close')
  102. exit
  103.  
  104.  
  105.  
  106. /*------------------------------------------------------------------
  107.  * exit with a message and return code
  108.  *------------------------------------------------------------------*/
  109. Error: procedure expose logfile
  110.    sock = arg(1)
  111.    msg  = arg(2)
  112.  
  113.    if (sock <> -1) then
  114.       rc = SockSoClose(sock)
  115.  
  116.    call saynlog msg
  117.    rc=stream(logfile,'c','close')
  118.  return 0
  119. /*-----------------------------*/
  120. saynlog: procedure expose logfile
  121.  mes=arg(1)
  122.  say mes
  123.  call lineout logfile , mes
  124. return
  125.