CVS: tmda/TMDA ChangeLog,1.307,1.308 FilterParser.py,1.63,1.64

"Jason R. Mastaler" <[email protected]>
Newsgroups gmane.mail.spam.tmda.cvs
Message-ID <[email protected]>
Update of /cvsroot/tmda/tmda/TMDA
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29355

Modified Files:
	ChangeLog FilterParser.py 
Log Message:
New feature; a 'pipe-headers' incoming filter file source.  Identical
to 'pipe' except that it only pipes the headers to the program,
instead of the headers + body.

For performance reasons, 'pipe-headers' should be used instead of
'pipe' unless the user absolutely needs to process the message body.

Also, this should fix the often reported IOError with 'pipe'
and large messages with broken programs that cause SIGPIPE. e.g,

IOError: [Errno 32] Broken pipe



Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/ChangeLog,v
retrieving revision 1.307
retrieving revision 1.308
diff -u -r1.307 -r1.308
--- ChangeLog	18 Jan 2004 03:40:40 -0000	1.307
+++ ChangeLog	30 Jan 2004 07:29:42 -0000	1.308
@@ -1,3 +1,8 @@
+2004-01-30  Jason R. Mastaler  <[email protected]>
+
+	* FilterParser.py (_FilterFile.__init__): Add 'pipe-headers'.
+	(FilterParser.firstmatch): Ditto.
+
 2004-01-17  Jason R. Mastaler  <[email protected]>
 
 	* Defaults.py (TMDARC): ~/.tmdarc is deprecated.

Index: FilterParser.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/FilterParser.py,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- FilterParser.py	1 Jan 2004 23:22:19 -0000	1.63
+++ FilterParser.py	30 Jan 2004 07:29:42 -0000	1.64
@@ -223,7 +223,7 @@
 
     most_sources = re.compile(r"""
     ( (?:to|from)-(?:file|cdb|dbm|ezmlm|mailman|sql)
-    | size | pipe
+    | size | pipe-headers | pipe
     | (?:to|from) (?!-) )
     """, re.VERBOSE | re.IGNORECASE)
 
@@ -279,6 +279,7 @@
         'body-file'    : ('case', 'optional'),
         'headers-file' : ('case', 'optional'),
         'size'         : None,
+        'pipe-headers' : None,
         'pipe'         : None
         }
 
@@ -583,7 +584,7 @@
 	Parse a single rule from a filter file.  If successful, return a tuple
 	with five fields.  The five fields are:
 	
-	  source    - string: to*, from*, body*, headers*, size, pipe
+	  source    - string: to*, from*, body*, headers*, size, pipe, pipe-headers
           args      - any arguments that might be specified
 	  match     - string: the email address to be matched against, a
                       filename or a regular expression enclosed within
@@ -1033,6 +1034,31 @@
                     break
             # A match is found if the command exits with a zero exit
             # status.
+            if source == 'pipe-headers' and msg_headers:
+                cmd = popen2.Popen3(match, 1, bufsize=-1)
+                cmdout, cmdin, cmderr = cmd.fromchild, cmd.tochild, cmd.childerr
+                cmdin.write(msg_headers)
+                cmdin.flush()
+                cmdin.close()
+                err = cmderr.read().strip()
+                cmderr.close()
+                out = cmdout.read().strip()
+                cmdout.close()
+                r = cmd.wait()
+                if r == 0:
+                    found_match = 1
+                    break
+                else:
+                    # non-zero exit status
+                    if os.WIFEXITED(r):
+                        pass
+                    # raise an exception if the process exited due to
+                    # a signal.
+                    elif os.WIFSIGNALED(r):
+                        raise Error, 'command "%s" abnormal exit signal %s (%s)' \
+                              % (match, os.WTERMSIG(r), err or '')
+            # A match is found if the command exits with a zero exit
+            # status.
             if source == 'pipe' and msg_body and msg_headers:
                 cmd = popen2.Popen3(match, 1, bufsize=-1)
                 cmdout, cmdin, cmderr = cmd.fromchild, cmd.tochild, cmd.childerr
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.