home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / ELM23-2 / ELM23-2.ZIP / bin / rmailm.cmd < prev    next >
OS/2 REXX Batch file  |  1997-02-02  |  2KB  |  117 lines

  1. /* REXX: rmailm.cmd */
  2.  
  3. /* Author:  Kai-Uwe Rommel <rommel@ars.de>
  4.  * Created: Fri Aug 23 1996
  5.  *
  6.  * mail filter for Elm with rmail transport
  7.  *
  8.  * $Id: rmailm.cmd,v 1.2 1997/02/02 10:56:09 rommel Exp rommel $
  9.  * $Revision: 1.2 $
  10.  */
  11.  
  12. /*
  13.  * $Log: rmailm.cmd,v $
  14.  * Revision 1.2  1997/02/02 10:56:09  rommel
  15.  * handle both remote and local cases
  16.  * 
  17.  */
  18.  
  19. Parse Arg arg1 arg2 arg3
  20.  
  21. /* determine the UUCP system name of our local machine */
  22.  
  23. Queue = RxQueue('create')
  24. Call RxQueue 'Set', Queue
  25. '@uuname -d | rxqueue 'Queue
  26. Parse Pull ourname
  27. Call RxQueue 'Delete', Queue
  28.  
  29. /* handle rmail with -f argument or input from stdin */
  30.  
  31. temp = ''
  32.  
  33. If arg1 = '-f'           /* with file argument */
  34. Then Do
  35.   
  36.   file = arg2
  37.   recipients = arg3
  38.   
  39. End
  40. Else Do                /* processing stdin */
  41.   
  42.   tempdir = Value('TEMP', , 'OS2ENVIRONMENT')'\'
  43.   temp = SysTempFileName(tempdir'rmail???.tmp')
  44.  
  45.   Do Forever
  46.   
  47.     line = LineIn('stdin')
  48.   
  49.     If Stream('stdin', 'S') = 'NOTREADY'
  50.     Then Leave
  51.   
  52.     Call LineOut temp, line
  53.   
  54.   End
  55.  
  56.   Call Stream temp, 'C', 'CLOSE'
  57.   
  58.   file = temp
  59.   recipients = arg1' 'arg2' 'arg3
  60.   
  61. End
  62.  
  63. /* take care of % expansion for batch files */
  64.  
  65. Do Forever
  66.   
  67.   percent = Pos('%', recipients)
  68.  
  69.   If percent = 0
  70.   Then Leave
  71.   
  72.   recipients = Overlay('$', recipients, percent)
  73.   recipients = Insert('$', recipients, percent)
  74.   
  75. End
  76.  
  77. recipients = Translate(recipients, '%', '$')
  78.  
  79. /* separate recipients into local and remote ones */
  80.  
  81. local = ''
  82. remote = ''
  83.  
  84. Do i=1 To Words(recipients)
  85.   
  86.   addr = Word(recipients, i)
  87.   Parse Var addr username '@' sysname
  88.   
  89.   If sysname = ourname
  90.   Then local = local' 'addr
  91.   Else remote = remote' 'addr
  92.   
  93. End
  94.  
  95. /* deliver to local recipients */
  96.  
  97. If remote \= ''
  98. Then Do
  99.   '@call sndfilt 'file
  100.   '@rmail -f 'file' 'remote
  101. End
  102.  
  103. /* spool to remote recipients */
  104.  
  105. If local \= ''
  106. Then Do
  107.   '@call rcvfilt 'file
  108.   '@rmail -f 'file' 'local
  109. End
  110.  
  111. /* clean up */
  112.  
  113. If temp \= ''
  114. Then Call SysFileDelete temp
  115.  
  116. /* end of rmailm.cmd */
  117.