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.
_______________________________________________
Spambayes-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/spambayes-checkins

Reply via email to