------------------------------------------------------------
revno: 1016
committer: Mark Sapiro <[EMAIL PROTECTED]>
branch nick: 2.2
timestamp: Tue 2008-12-02 16:35:43 -0800
message:
  Fixed a problem in SpamDetect.py that could cause header_filter_rules
  to fail to match RFC 2047 encoded headers.
modified:
  Mailman/Handlers/SpamDetect.py
  NEWS

=== modified file 'Mailman/Handlers/SpamDetect.py'
--- a/Mailman/Handlers/SpamDetect.py    2007-01-20 03:34:42 +0000
+++ b/Mailman/Handlers/SpamDetect.py    2008-12-03 00:35:43 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 1998-2007 by the Free Software Foundation, Inc.
+# Copyright (C) 1998-2008 by the Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -26,13 +26,13 @@
 """
 
 import re
-from cStringIO import StringIO
 
-from email.Generator import Generator
+from email.Header import decode_header
 
 from Mailman import mm_cfg
 from Mailman import Errors
 from Mailman import i18n
+from Mailman.Utils import GetCharSet
 from Mailman.Handlers.Hold import hold_for_approval
 
 try:
@@ -60,34 +60,21 @@
 
 
 
-class Tee:
-    def __init__(self, outfp_a, outfp_b):
-        self._outfp_a = outfp_a
-        self._outfp_b = outfp_b
-
-    def write(self, s):
-        self._outfp_a.write(s)
-        self._outfp_b.write(s)
-
-
-# Class to capture the headers separate from the message body
-class HeaderGenerator(Generator):
-    def __init__(self, outfp, mangle_from_=True, maxheaderlen=78):
-        Generator.__init__(self, outfp, mangle_from_, maxheaderlen)
-        self._headertxt = ''
-
-    def _write_headers(self, msg):
-        sfp = StringIO()
-        oldfp = self._fp
-        self._fp = Tee(oldfp, sfp)
-        try:
-            Generator._write_headers(self, msg)
-        finally:
-            self._fp = oldfp
-        self._headertxt = sfp.getvalue()
-
-    def header_text(self):
-        return self._headertxt
+def getDecodedHeaders(msg, cset='utf-8'):
+    """Returns a string containing all the headers of msg, unfolded and
+    RFC 2047 decoded and encoded in cset.
+    """
+
+    headers = ''
+    for h, v in msg.items():
+        uvalue = u''
+        v = decode_header(re.sub('\n\s', ' ', v))
+        for frag, cs in v:
+            if not cs:
+                cs = 'us-ascii'
+            uvalue += unicode(frag, cs, 'replace')
+        headers += '%s: %s\n' % (h, uvalue.encode(cset, 'replace'))
+    return headers
 
 
 
@@ -106,13 +93,10 @@
     # TK: Collect headers in sub-parts because attachment filename
     # extension may be a clue to possible virus/spam.
     headers = ''
+    # Get the character set of the lists preferred language for headers
+    lcset = GetCharSet(mlist.preferred_language)
     for p in msg.walk():
-        g = HeaderGenerator(StringIO())
-        g.flatten(p)
-        headers += g.header_text()
-    # Now reshape headers (remove extra CR and connect multiline).
-    headers = re.sub('\n+', '\n', headers)
-    headers = re.sub('\n\s', ' ', headers)
+        headers += getDecodedHeaders(p, lcset)
     for patterns, action, empty in mlist.header_filter_rules:
         if action == mm_cfg.DEFER:
             continue

=== modified file 'NEWS'
--- a/NEWS      2008-11-20 21:09:58 +0000
+++ b/NEWS      2008-12-03 00:35:43 +0000
@@ -69,6 +69,9 @@
       cookie when CheckCookie was not given a user and the user in the cookie
       had a %xx encoded character.  Bug # 299220.
 
+    - Fixed a problem in SpamDetect.py that could cause header_filter_rules
+      to fail to match RFC 2047 encoded headers.
+
 2.1.11 (30-Jun-2008)
 
   New Features



--
Active development version (web u/i update)
https://code.launchpad.net/~mailman-coders/mailman/2.2

You are receiving this branch notification because you are subscribed to it.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to