home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / postroad.zip / forward.cmd < prev    next >
OS/2 REXX Batch file  |  1997-10-23  |  5KB  |  126 lines

  1. /* FORWARD.CMD - A REXX user exit, for a filter to execute, to forward or */
  2. /*            redirect an incoming note to multiple addresses             */
  3. /*                                                                        */
  4. /*              Do not use without customizing FORWARD.CFG!               */
  5. /*                                                                        */
  6. /*   Copyright (c)1996 Kari Jackson for InnoVal Systems Solutions, Inc.   */
  7. /*  Portions adapted from PRMAF102.CMD, Copyright (c)1995 Bill Springall  */
  8. /*                  for InnoVal Systems Solutions, Inc.                   */
  9. /*    InnoVal Systems Solutions, Inc., and the authors cannot be held     */
  10. /*   responsible for damage that might occur while using this program.    */
  11. /*                         Use at your own risk.                          */
  12. /*                                                                        */
  13. /* FORWARD.CFG file must be present; instructions are in it, in comments. */
  14.  
  15. parse arg filename
  16. inbasket=left(filename,lastpos('\',filename))
  17. parse source . . program
  18. program=left(program,lastpos('.',program))
  19. inifile=program||'cfg'
  20. inifile=stream(inifile,'C','QUERY EXISTS')
  21. /* This program can't do anything if you don't tell it to whom you want the
  22.    notes redirected or forwarded! */
  23. if inifile='' then exit
  24. tos.0=0 ; others.0=0
  25. do while lines(inifile)
  26.    line=linein(inifile)
  27.    select
  28.       when left(line,2)='/*' then nop
  29.       when strip(line)='' then nop
  30.       when translate(left(line,5))='FROM:' then FROM=strip(substr(line,6))
  31.       when translate(left(line,9))='REPLY-TO:' then REPLYTO=strip(substr(line,10))
  32.       when translate(left(line,8))='SUBJECT:' then SUBJECT=strip(substr(line,9))
  33.       when translate(left(line,3))='TO:' then do
  34.          tos.0=tos.0+1
  35.          i=tos.0
  36.          tos.i=strip(substr(line,4))
  37.       end
  38.       when translate(left(line,8))='TRAILER:' then TRAILER=substr(line,9)
  39.       when translate(line)='SEND HEADER' then HEADER='yes'
  40.       otherwise do
  41.          others.0=others.0+1
  42.          i=others.0
  43.          others.i=line
  44.       end
  45.    end
  46. end
  47. call lineout inifile
  48. /* This program can't do anything if you don't tell it to whom you want the
  49.    notes redirected or forwarded! */
  50. if tos.0=0 then exit
  51. outfile=getpopname(inbasket'SNDNOTES','POP')
  52. /* the following would virtually never happen; if it did, the program would
  53.    not be able to do its job, so exit */
  54. if outfile='error' then exit
  55. outfile=inbasket'SNDNOTES\'outfile'.POP'
  56. /* now we'll read the header of the incoming note */
  57. header.0=0
  58. do while lines(filename)
  59.    i=header.0+1
  60.    header.i=linein(filename)
  61.    if strip(header.i)='' then leave
  62.    header.0=i
  63.    select
  64.       when translate(left(header.i,5))='FROM:' & FROM='FROM' then FROM=strip(substr(header.i,6))
  65.       when translate(left(header.i,9))='REPLY-TO:' & REPLYTO='REPLYTO' then REPLYTO=strip(substr(header.i,10))
  66.       when translate(left(header.i,8))='SUBJECT:' & SUBJECT='SUBJECT' then SUBJECT=strip(substr(header.i,9))
  67.       otherwise nop
  68.    end
  69. end
  70. tagchar=x2c('05')
  71. do i=1 to tos.0
  72.    call lineout outfile,tagchar||x2c('01')||tos.i
  73. end
  74. if FROM<>'FROM' then call lineout outfile,tagchar||x2c('0B')||FROM
  75. if REPLYTO<>'REPLYTO' then call lineout outfile,tagchar||x2c('31')||REPLYTO
  76. do i=1 to others.0
  77.    call lineout outfile,others.i
  78. end
  79. if SUBJECT<>'SUBJECT' then call lineout outfile,tagchar||x2c('0F')||SUBJECT
  80. call lineout outfile,''
  81. if header='yes' then do
  82.    do i=1 to header.0
  83.       call lineout outfile,header.i
  84.    end
  85.    call lineout outfile,''
  86. end
  87. do while lines(filename)
  88.    call lineout outfile,linein(filename)
  89. end
  90. if trailer<>'TRAILER' then do
  91.    call lineout outfile,''
  92.    call lineout outfile,trailer
  93. end
  94. call lineout outfile,''
  95. call lineout outfile
  96. call lineout filename
  97. exit
  98.  
  99. /* Copyright (c)1996 Kari Jackson for InnoVal Systems Solutions, Inc. */
  100. /* Subroutine to produce a *.POP-style filename */
  101. /* Returns 8-character name or "error" */
  102. GetPopName:procedure
  103. parse arg directory,extension
  104. characters='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  105. parse value date("O") with . 2 year "/" month "/" day
  106. parse value time() with hour ":" minute ":" second
  107. month=substr(characters,month+1,1)
  108. day=substr(characters,day+1,1)
  109. hour=substr(characters,hour+1,1)
  110. fifth=minute%36
  111. sixth=substr(characters,minute//36+1,1)
  112. test=second//36
  113. string=year||month||day||hour||fifth||sixth
  114. do j=1 to 36
  115.    test2=(test+j)//36
  116.    if test2=0 then seventh=substr(characters,36,1)
  117.    else seventh=substr(characters,test2,1)
  118.    do i=1 to 36
  119.       tryit=string||seventh||substr(characters,i,1)
  120.       filename=directory||"\"||tryit||'.'||extension
  121.       if stream(filename,'c','query exists')='' then return tryit
  122.    end
  123. end
  124. /* there have already been 1296 files created in that directory this minute */
  125. return 'error'
  126.