------------------------------------------------------------
revno: 1338
committer: Mark Sapiro <[email protected]>
branch nick: 2.1
timestamp: Sun 2012-02-05 13:37:29 -0800
message:
Backported 2.2 branch fix for 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
--
lp:mailman/2.1
https://code.launchpad.net/~mailman-coders/mailman/2.1
Your team Mailman Checkins is subscribed to branch lp:mailman/2.1.
To unsubscribe from this branch go to
https://code.launchpad.net/~mailman-coders/mailman/2.1/+edit-subscription
=== modified file 'Mailman/Handlers/SpamDetect.py'
--- Mailman/Handlers/SpamDetect.py 2007-01-20 03:34:42 +0000
+++ Mailman/Handlers/SpamDetect.py 2012-02-05 21:37:29 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 1998-2007 by the Free Software Foundation, Inc.
+# Copyright (C) 1998-2012 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'
--- NEWS 2012-02-05 21:19:39 +0000
+++ NEWS 2012-02-05 21:37:29 +0000
@@ -81,6 +81,9 @@
Bug Fixes and other patches
+ - Backported 2.2 branch fix for a problem in SpamDetect.py that could
+ cause header_filter_rules to fail to match RFC 2047 encoded headers.
+
- Fix for bug #629738 could cause a crash in the admindb details display
if the decoded message body contained characters not in the character
set of the list's preferred language. Fixed. Bug #910440.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org