summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Sapiro2017-06-30 11:54:27 -0700
committerMark Sapiro2017-06-30 11:54:27 -0700
commite92359323cda1fb118415c2ccb69679795e78465 (patch)
tree4d545de85051a8fd43ff7c4bc084b04e5e39a7ec
parent5b7eeedd19ac69976b38aec1132b1f23d963938d (diff)
downloadmailman-e92359323cda1fb118415c2ccb69679795e78465.tar.gz
mailman-e92359323cda1fb118415c2ccb69679795e78465.tar.zst
mailman-e92359323cda1fb118415c2ccb69679795e78465.zip
-rw-r--r--src/mailman/docs/NEWS.rst2
-rw-r--r--src/mailman/handlers/subject_prefix.py10
-rw-r--r--src/mailman/handlers/tests/test_subject_prefix.py15
3 files changed, 25 insertions, 2 deletions
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index 50e581239..c21f561a1 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -17,6 +17,8 @@ Bugs
* A missing html_to_plain_text_command is now properly detected and logged.
(Closes #345)
* Syntactically invalid sender addresses are now ignored. (Closes #229)
+ * An AttributeError: 'str' object has no attribute 'decode' exception in
+ subject prefixing is fixed. (Closes #359)
Interfaces
----------
diff --git a/src/mailman/handlers/subject_prefix.py b/src/mailman/handlers/subject_prefix.py
index 295ab039c..da971751e 100644
--- a/src/mailman/handlers/subject_prefix.py
+++ b/src/mailman/handlers/subject_prefix.py
@@ -69,7 +69,10 @@ def all_same_charset(mlist, msgdata, subject, prefix, prefix_pattern, ws):
for chunk, charset in decode_header(subject.encode()):
if charset is None:
charset = 'us-ascii'
- chunks.append(chunk.decode(charset))
+ if isinstance(chunk, str):
+ chunks.append(chunk)
+ else:
+ chunks.append(chunk.decode(charset))
if charset != list_charset:
return None
subject_text = EMPTYSTRING.join(chunks)
@@ -111,7 +114,10 @@ def mixed_charsets(mlist, msgdata, subject, prefix, prefix_pattern, ws):
chunk_text, chunk_charset = chunks[0]
if chunk_charset is None:
chunk_charset = 'us-ascii'
- first_text = chunk_text.decode(chunk_charset)
+ if isinstance(chunk_text, str):
+ first_text = chunk_text
+ else:
+ first_text = chunk_text.decode(chunk_charset)
first_text = re.sub(prefix_pattern, '', first_text).lstrip()
rematch = re.match(RE_PATTERN, first_text, re.I)
if rematch:
diff --git a/src/mailman/handlers/tests/test_subject_prefix.py b/src/mailman/handlers/tests/test_subject_prefix.py
index 41d0bf233..0203cabb1 100644
--- a/src/mailman/handlers/tests/test_subject_prefix.py
+++ b/src/mailman/handlers/tests/test_subject_prefix.py
@@ -22,7 +22,9 @@ import unittest
from mailman.app.lifecycle import create_list
from mailman.config import config
from mailman.email.message import Message
+from mailman.interfaces.languages import ILanguageManager
from mailman.testing.layers import ConfigLayer
+from zope.component import getUtility
class TestSubjectPrefix(unittest.TestCase):
@@ -121,3 +123,16 @@ class TestSubjectPrefix(unittest.TestCase):
subject.encode(),
'[Test 456] Re: =?iso-2022-jp?b?GyRCJWEhPCVrJV4lcxsoQg==?=')
self.assertEqual(str(subject), '[Test 456] Re: メールマン')
+
+ def test_decode_header_returns_string(self):
+ # Under some circumstances, email.header.decode_header() returns a
+ # string value. Ensure we can handle that.
+ manager = getUtility(ILanguageManager)
+ manager.add('xx', 'iso-8859-1', 'Xlandia')
+ self._mlist.preferred_language = 'xx'
+ msg = Message()
+ msg['Subject'] = 'Plain text'
+ self._process(self._mlist, msg, {})
+ subject = msg['subject']
+ self.assertEqual(subject.encode(),
+ '=?iso-8859-1?q?=5BTest=5D_?= Plain text')