CVS: tmda/TMDA Util.py,1.102,1.103 ChangeLog,1.283,1.284

Timothy Legant <[email protected]>
Newsgroups gmane.mail.spam.tmda.cvs
Message-ID <[email protected]>
Update of /cvsroot/tmda/tmda/TMDA
In directory sc8-pr-cvs1:/tmp/cvs-serv15010/TMDA

Modified Files:
	Util.py ChangeLog 
Log Message:
When parsing a message in Util.msg_from_file, with the HeaderParser,
add a "custom" attribute to the Message object called 'header_parsed'.
If it exists and is True (1), then the Message was read and parsed by
HeaderParser.

AutoResponse.py and Pending.py use fully parsed MIME messages, so
HeaderParsedGenerator won't work for those messages.  Made
Util.msg_as_string sensitive to 'header_parsed' attribute of Message
so that if a Message has the 'header_parsed' attribute, it is
flattened by HeaderParsedGenerator.  Otherwise, it is flattened by the
standard Generator.


Index: Util.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Util.py,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -r1.102 -r1.103
--- Util.py	31 Jul 2003 20:08:37 -0000	1.102
+++ Util.py	1 Aug 2003 07:22:53 -0000	1.103
@@ -515,7 +515,9 @@
     problems trying to parse spam with broken MIME bodies."""
     from email.Message import Message
     from email.Parser import HeaderParser
-    return HeaderParser(Message, strict=strict).parse(fp)
+    msg = HeaderParser(Message, strict=strict).parse(fp)
+    msg.header_parsed = 1
+    return msg
 
 
 def msg_as_string(msg, maxheaderlen=0, mangle_from_=0, unixfrom=0):
@@ -535,11 +537,13 @@
 
     unixfrom forces the printing of the envelope header delimiter.
     Default is False."""
-    from email.Generator import HeaderParsedGenerator
+    from email import Generator
     fp = StringIO()
-    g = HeaderParsedGenerator(fp,
-                              mangle_from_=mangle_from_,
-                              maxheaderlen=maxheaderlen)
+    if hasattr(msg, 'header_parsed') and msg.header_parsed:
+        genclass = Generator.HeaderParsedGenerator
+    else:
+        genclass = Generator.Generator
+    g = genclass(fp, mangle_from_=mangle_from_, maxheaderlen=maxheaderlen)
     g.flatten(msg, unixfrom=unixfrom)
     return fp.getvalue()
 

Index: ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/ChangeLog,v
retrieving revision 1.283
retrieving revision 1.284
diff -u -r1.283 -r1.284
--- ChangeLog	31 Jul 2003 20:08:37 -0000	1.283
+++ ChangeLog	1 Aug 2003 07:22:53 -0000	1.284
@@ -1,3 +1,15 @@
+2003-08-01  Tim Legant  <[email protected]>
+
+	* Util.py (msg_from_file): When parsing a message with the
+	HeaderParser, add a "custom" attribute to the Message object
+	called 'header_parsed'.  If it exists and is True (1), then the
+	Message was read and parsed by HeaderParser.
+
+	(msg_as_string): AutoResponse.py and Pending.py use fully parsed
+	MIME messages, so HeaderParsedGenerator won't work for those
+	messages.  Made msg_as_string sensitive to 'header_parsed'
+	attribute of Message, defined in Util.msg_from_file.
+
 2003-07-31  Tim Legant  <[email protected]>
 
 	* Util.py (msg_as_string): Use HeaderParsedGenerator rather than

_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs
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.