Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits: 3dc0a73c by Mark Sapiro at 2019-02-13T02:05:57Z Messages with Subject: Re: only are now processed correctly. - - - - - 07c95bb9 by Abhilash Raj at 2019-02-13T15:45:22Z Merge branch 'prefix' into 'master' Messages with Subject: Re: only are now processed correctly. Fixes #545 Also improves test coverage. See merge request mailman/mailman!448 - - - - - 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 ===================================== @@ -37,6 +37,7 @@ Bugs header. (Closes #518) * Outgoing SMTP connections are now closed following message delivery regardless of the max_sessions_per_connection setting. (Closes #529) +* Messages with Subject: Re: only are now processed correctly. (Closes #545) LOCALIZATION ------------ ===================================== src/mailman/handlers/subject_prefix.py ===================================== @@ -54,7 +54,10 @@ def ascii_header(mlist, msgdata, subject, prefix, prefix_pattern, ws): else: recolon = '' lines = subject_text.splitlines() - first_line = [lines[0]] + # If the subject was only the prefix or Re:, the text could be null. + first_line = [] + if lines: + first_line = [lines[0]] if recolon: first_line.insert(0, recolon) if prefix: @@ -95,7 +98,10 @@ def all_same_charset(mlist, msgdata, subject, prefix, prefix_pattern, ws): else: recolon = '' lines = subject_text.splitlines() - first_line = [lines[0]] + # If the subject was only the prefix or Re:, the text could be null. + first_line = [] + if lines: + first_line = [lines[0]] if recolon: first_line.insert(0, recolon) if prefix: ===================================== src/mailman/handlers/tests/test_subject_prefix.py ===================================== @@ -90,6 +90,23 @@ class TestSubjectPrefix(unittest.TestCase): self._process(self._mlist, msg, {}) self.assertEqual(str(msg['subject']), '[Test] Re: A test message') + def test_re_prefix_all_same(self): + # Re: prefix with non-ascii. + msg = Message() + msg['Subject'] = '=?utf-8?Q?Re:_[Test]_A_test_message?=' + old_charset = self._mlist.preferred_language.charset + self._mlist.preferred_language.charset = 'utf-8' + self._process(self._mlist, msg, {}) + self._mlist.preferred_language.charset = old_charset + self.assertEqual(str(msg['subject']), '[Test] Re: A test message') + + def test_re_prefix_mixed(self): + # Re: prefix with non-ascii and mixed charset. + msg = Message() + msg['Subject'] = '=?utf-8?Q?Re:_[Test]_A_test_message?=' + self._process(self._mlist, msg, {}) + self.assertEqual(str(msg['subject']), '[Test] Re: A test message') + def test_multiline_subject(self): # The subject appears on multiple lines. msg = Message() @@ -107,6 +124,60 @@ class TestSubjectPrefix(unittest.TestCase): '[Test] =?iso-2022-jp?b?GyRCJWEhPCVrJV4lcxsoQg==?=') self.assertEqual(str(subject), '[Test] メールマン') + def test_prefix_only(self): + # Incoming subject is only the prefix. + msg = Message() + msg['Subject'] = '[Test] ' + self._process(self._mlist, msg, {}) + subject = msg['subject'] + self.assertEqual(str(subject), '[Test] ') + + def test_prefix_only_all_same(self): + # Incoming subject is only the prefix. + msg = Message() + msg['Subject'] = '=?utf-8?Q?[Test]_?=' + old_charset = self._mlist.preferred_language.charset + self._mlist.preferred_language.charset = 'utf-8' + self._process(self._mlist, msg, {}) + self._mlist.preferred_language.charset = old_charset + subject = msg['subject'] + self.assertEqual(str(subject), '[Test] ') + + def test_prefix_only_mixed(self): + # Incoming subject is only the prefix. + msg = Message() + msg['Subject'] = '=?utf-8?Q?[Test]_?=' + self._process(self._mlist, msg, {}) + subject = msg['subject'] + self.assertEqual(str(subject), '[Test] ') + + def test_re_only(self): + # Incoming subject is only Re:. + msg = Message() + msg['Subject'] = 'Re:' + self._process(self._mlist, msg, {}) + subject = msg['subject'] + self.assertEqual(str(subject), '[Test] Re: ') + + def test_re_only_all_same(self): + # Incoming subject is only Re:. + msg = Message() + msg['Subject'] = '=?utf-8?Q?Re:?=' + old_charset = self._mlist.preferred_language.charset + self._mlist.preferred_language.charset = 'utf-8' + self._process(self._mlist, msg, {}) + self._mlist.preferred_language.charset = old_charset + subject = msg['subject'] + self.assertEqual(str(subject), '[Test] Re: ') + + def test_re_only_mixed(self): + # Incoming subject is only Re:. + msg = Message() + msg['Subject'] = '=?utf-8?Q?Re:?=' + self._process(self._mlist, msg, {}) + subject = msg['subject'] + self.assertEqual(str(subject), '[Test] Re: ') + def test_i18n_subject_with_sequential_prefix_and_re(self): # The mailing list defines a sequential prefix, and the original # Subject has a prefix with a different sequence number, *and* it also View it on GitLab: https://gitlab.com/mailman/mailman/compare/26053048a4ce3858f2ff6a1173ac2911ee567d8e...07c95bb9d4f072b76ed5c010154e0601c3458f69 -- View it on GitLab: https://gitlab.com/mailman/mailman/compare/26053048a4ce3858f2ff6a1173ac2911ee567d8e...07c95bb9d4f072b76ed5c010154e0601c3458f69 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