Barry Warsaw pushed to branch master at mailman / Mailman
Commits: e9235932 by Mark Sapiro at 2017-06-30T11:54:27-07:00 Fixed an AttributeError in subject prefixing. - - - - - eaf5894e by Barry Warsaw at 2017-06-30T21:13:03+00:00 Merge branch 'prefix' into 'master' Fixed an AttributeError in subject prefixing. Closes #359 See merge request !295 - - - - - 3 changed files: - src/mailman/docs/NEWS.rst - src/mailman/handlers/subject_prefix.py - src/mailman/handlers/tests/test_subject_prefix.py Changes: ===================================== src/mailman/docs/NEWS.rst ===================================== --- 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 ---------- ===================================== src/mailman/handlers/subject_prefix.py ===================================== --- 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: ===================================== src/mailman/handlers/tests/test_subject_prefix.py ===================================== --- 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') View it on GitLab: https://gitlab.com/mailman/mailman/compare/5b7eeedd19ac69976b38aec1132b1f23d963938d...eaf5894e673269e2f07a28e5960c9650ee205001 --- View it on GitLab: https://gitlab.com/mailman/mailman/compare/5b7eeedd19ac69976b38aec1132b1f23d963938d...eaf5894e673269e2f07a28e5960c9650ee205001 You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org