From montanaro at users.sourceforge.net Sun Dec 6 20:36:06 2009 From: montanaro at users.sourceforge.net (montanaro at users.sourceforge.net) Date: Sun, 06 Dec 2009 19:36:06 +0000 Subject: [Spambayes-checkins] SF.net SVN: spambayes:[3255] trunk/spambayes/spambayes Message-ID: Revision: 3255 http://spambayes.svn.sourceforge.net/spambayes/?rev=3255&view=rev Author: montanaro Date: 2009-12-06 19:36:06 +0000 (Sun, 06 Dec 2009) Log Message: ----------- stop allowing "From" to be mangled. Modified Paths: -------------- trunk/spambayes/spambayes/mboxutils.py trunk/spambayes/spambayes/message.py Modified: trunk/spambayes/spambayes/mboxutils.py =================================================================== --- trunk/spambayes/spambayes/mboxutils.py 2009-11-09 02:59:10 UTC (rev 3254) +++ trunk/spambayes/spambayes/mboxutils.py 2009-12-06 19:36:06 UTC (rev 3255) @@ -171,20 +171,22 @@ shouldn't matter. """ - if isinstance(obj, email.Message.Message): + from spambayes.message import Message + + if isinstance(obj, Message): return obj # Create an email Message object. if hasattr(obj, "read"): obj = obj.read() try: - msg = email.message_from_string(obj) + msg = email.message_from_string(obj, _class=Message) except email.Errors.MessageParseError: # Wrap the raw text in a bare Message object. Since the # headers are most likely damaged, we can't use the email # package to parse them, so just get rid of them first. headers = extract_headers(obj) obj = obj[len(headers):] - msg = email.Message.Message() + msg = Message() msg.set_payload(obj) return msg @@ -203,10 +205,23 @@ bit of rearranging, but that should work nicely, and mean that all this code is together in one place. """ + + from spambayes.message import Message + if isinstance(msg, str): return msg + + if isinstance(msg, Message): + return msg.as_string() + try: - return msg.as_string(unixfrom) + warnings.warn("Use spambayes.message.Message instead") + import email.generator + import StringIO + f = StringIO.StringIO() + gen = email.generator.Generator(f, mangle_from_=False) + gen.flatten(msg) + return f.getvalue() except TypeError: ty, val, tb = sys.exc_info() exclines = traceback.format_exception(ty, val, tb)[1:] Modified: trunk/spambayes/spambayes/message.py =================================================================== --- trunk/spambayes/spambayes/message.py 2009-11-09 02:59:10 UTC (rev 3254) +++ trunk/spambayes/spambayes/message.py 2009-12-06 19:36:06 UTC (rev 3255) @@ -415,7 +415,7 @@ """Make sure data uses CRLF for line termination.""" return CRLF_RE.sub('\r\n', data) - def as_string(self, unixfrom=False, mangle_from_=True): + def as_string(self, unixfrom=False, mangle_from_=False): # The email package stores line endings in the "internal" Python # format ('\n'). It is up to whoever transmits that information to # convert to appropriate line endings (according to RFC822, that is This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. From montanaro at users.sourceforge.net Fri Dec 18 14:01:13 2009 From: montanaro at users.sourceforge.net (montanaro at users.sourceforge.net) Date: Fri, 18 Dec 2009 13:01:13 +0000 Subject: [Spambayes-checkins] SF.net SVN: spambayes:[3256] trunk/spambayes/spambayes Message-ID: Revision: 3256 http://spambayes.svn.sourceforge.net/spambayes/?rev=3256&view=rev Author: montanaro Date: 2009-12-18 13:01:12 +0000 (Fri, 18 Dec 2009) Log Message: ----------- revert - it borks the From_ line... Modified Paths: -------------- trunk/spambayes/spambayes/mboxutils.py trunk/spambayes/spambayes/message.py Modified: trunk/spambayes/spambayes/mboxutils.py =================================================================== --- trunk/spambayes/spambayes/mboxutils.py 2009-12-06 19:36:06 UTC (rev 3255) +++ trunk/spambayes/spambayes/mboxutils.py 2009-12-18 13:01:12 UTC (rev 3256) @@ -171,22 +171,20 @@ shouldn't matter. """ - from spambayes.message import Message - - if isinstance(obj, Message): + if isinstance(obj, email.Message.Message): return obj # Create an email Message object. if hasattr(obj, "read"): obj = obj.read() try: - msg = email.message_from_string(obj, _class=Message) + msg = email.message_from_string(obj) except email.Errors.MessageParseError: # Wrap the raw text in a bare Message object. Since the # headers are most likely damaged, we can't use the email # package to parse them, so just get rid of them first. headers = extract_headers(obj) obj = obj[len(headers):] - msg = Message() + msg = email.Message.Message() msg.set_payload(obj) return msg @@ -205,23 +203,10 @@ bit of rearranging, but that should work nicely, and mean that all this code is together in one place. """ - - from spambayes.message import Message - if isinstance(msg, str): return msg - - if isinstance(msg, Message): - return msg.as_string() - try: - warnings.warn("Use spambayes.message.Message instead") - import email.generator - import StringIO - f = StringIO.StringIO() - gen = email.generator.Generator(f, mangle_from_=False) - gen.flatten(msg) - return f.getvalue() + return msg.as_string(unixfrom) except TypeError: ty, val, tb = sys.exc_info() exclines = traceback.format_exception(ty, val, tb)[1:] Modified: trunk/spambayes/spambayes/message.py =================================================================== --- trunk/spambayes/spambayes/message.py 2009-12-06 19:36:06 UTC (rev 3255) +++ trunk/spambayes/spambayes/message.py 2009-12-18 13:01:12 UTC (rev 3256) @@ -415,7 +415,7 @@ """Make sure data uses CRLF for line termination.""" return CRLF_RE.sub('\r\n', data) - def as_string(self, unixfrom=False, mangle_from_=False): + def as_string(self, unixfrom=False, mangle_from_=True): # The email package stores line endings in the "internal" Python # format ('\n'). It is up to whoever transmits that information to # convert to appropriate line endings (according to RFC822, that is This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.