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

  1. /* REXX: sndfilt.cmd */
  2.  
  3. /* Author:  Kai-Uwe Rommel <rommel@ars.de>
  4.  * Created: Fri Aug 23 1996
  5.  *
  6.  * outbound mail filter for Elm with sendmail transport
  7.  *
  8.  * $Id: sndfilt.cmd,v 1.10 1997/01/26 18:43:39 rommel Exp rommel $
  9.  * $Revision: 1.10 $
  10.  */
  11.  
  12. /*
  13.  * $Log: sndfilt.cmd,v $
  14.  * Revision 1.10  1997/01/26 18:43:39  rommel
  15.  * do no longer distinguish between local and foreign recipients
  16.  *
  17.  * Revision 1.9  1997/01/26 18:24:22  rommel
  18.  * fixed tab character quoting, if no other 8-bit characters
  19.  *
  20.  * Revision 1.8  1996/10/13 10:02:37  rommel
  21.  * do not encode if there are only 7-bit characters
  22.  *
  23.  * Revision 1.7  1996/09/11 06:28:25  rommel
  24.  * fix duplication of MIME header lines
  25.  *
  26.  * Revision 1.6  1996/09/05 05:49:07  rommel
  27.  * add forgotten Mime-Version header
  28.  *
  29.  * Revision 1.5  1996/09/04 13:37:03  rommel
  30.  * removed debug line
  31.  *
  32.  * Revision 1.4  1996/09/04 13:35:47  rommel
  33.  * added forgotten Latin-1 translation (for german umlauts only for now)
  34.  * encoding now for all non-7-bit-printable characters
  35.  *
  36.  * Revision 1.3  1996/09/04 08:08:23  rommel
  37.  * use MIME encoding instead of transscription for german umlauts
  38.  *
  39.  * Revision 1.2  1996/08/28 20:52:34  rommel
  40.  * fixed trailing empty line buglet
  41.  *
  42.  * Revision 1.1  1996/08/23 16:51:52  rommel
  43.  * Initial revision
  44.  * 
  45.  */
  46.  
  47. /* cp850 to Latin-1 recoding only for german umlauts at the moment */
  48.  
  49. cp850  = 'äöüÄÖÜß'
  50. latin1 = 'e4f6fcc4d6dcdf'X
  51.  
  52. Parse Arg file sender receivers
  53.  
  54. file = Translate(file, '\', '/')
  55. path = FileSpec('d', file) || FileSpec('p', file)
  56. name = FileSpec('n', file)
  57. temp = path'flt'SubStr(name, 4)
  58.  
  59. header = 1
  60. changes = 0
  61.  
  62. Do Forever
  63.  
  64.   line = LineIn(file)
  65.   
  66.   If Stream(file, 'S') = 'NOTREADY'
  67.   Then Leave
  68.  
  69.   If header = 1
  70.   Then Do
  71.     
  72.     line = Translate(line, ' ', '09'X)
  73.     Parse Upper Var line key val1 val2
  74.     
  75.     /* remove old MIME header lines */
  76.     
  77.     If key = 'CONTENT-TRANSFER-ENCODING:' | key = 'CONTENT-TYPE:' | key = 'MIME-VERSION:'
  78.     Then Iterate
  79.     
  80.     If line = ''
  81.     Then Do
  82.       
  83.       header = 0
  84.       
  85.       /* write new MIME lines */
  86.  
  87.       Call LineOut temp,'Mime-Version: 1.0'      
  88.       Call LineOut temp,'Content-Type: text/plain; charset="iso-8859-1"'
  89.       Call LineOut temp,'Content-Transfer-Encoding: quoted-printable'
  90.       
  91.     End
  92.     
  93.   End
  94.   Else Do
  95.     
  96.     line = Encode(Translate(line, latin1, cp850))
  97.     
  98.   End
  99.   
  100.   Call LineOut temp,line
  101.  
  102. End
  103.  
  104. Call Stream file, 'C', 'CLOSE'
  105. Call Stream temp, 'C', 'CLOSE'
  106.  
  107. /* if there were no 8-bit characters, forget everything */
  108.  
  109. If changes = 0
  110. Then Do
  111.   '@del 'temp
  112. End
  113. Else Do
  114.   '@del 'file
  115.   '@ren 'temp' 'name
  116. End
  117.  
  118. Exit
  119.  
  120. Encode: Procedure Expose changes
  121.  
  122.   Parse Arg string
  123.   
  124.   Do x = Length(string) To 1 By -1
  125.     
  126.     c = SubStr(string, x, 1)
  127.     
  128.     If C2D(c) < 32 | 126 < C2D(c) | c = '='
  129.     Then Do
  130.       
  131.       string = Left(string, x - 1) || '=' || C2X(c) || SubStr(string, x + 1)
  132.       
  133.       /* = is a 7-bit character and would really need to be encoded
  134.      but it is the quoting character, so it needs to be encoded in the
  135.      case that _other_ characters need to be encoded, otherwise not */
  136.       
  137.       If c \= '=' & C2D(c) \= 9
  138.       Then changes = changes + 1
  139.       
  140.     End
  141.     
  142.   End
  143.   
  144. Return string
  145.  
  146. /* end of sndfilt.cmd */
  147.