From 49158a23a7ef0b376ec86a6522700349fe9278fc Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Wed, 24 May 2017 17:58:34 -0700 Subject: Refactor Header object test to create the message without cheating. --- src/mailman/chains/tests/test_headers.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/mailman/chains/tests/test_headers.py b/src/mailman/chains/tests/test_headers.py index 3da7a2435..cd4c932cc 100644 --- a/src/mailman/chains/tests/test_headers.py +++ b/src/mailman/chains/tests/test_headers.py @@ -19,7 +19,7 @@ import unittest -from email.header import Header +from email import message_from_bytes from mailman.app.lifecycle import create_list from mailman.chains.headers import HeaderMatchRule, make_link from mailman.config import config @@ -212,23 +212,18 @@ This is junk def test_get_all_returns_non_string(self): # Test case where msg.get_all() returns header instance. - msg = mfs("""\ + msg = message_from_bytes(b"""\ From: anne@example.com To: test@example.com -Subject: =?unknown-8bit?q?Become_smarter_now_=96_Increase__your_brain...?= +Subject: Bad \x96 subject Message-ID: body -""") - # XXX In the wild we have seen a message instance in which the subject - # header value is an email.header.Header instance rather than a - # string. We don't know how to recreate that here so we cheat. - msg['Subject'] = Header( - 'Become_smarter_now \x96 Increase your brain...', 'utf-8') +""", Message) msgdata = {} header_matches = IHeaderMatchList(self._mlist) - header_matches.append('Subject', '=\?utf', 'hold') + header_matches.append('Subject', 'Bad', 'hold') # This event subscriber records the event that occurs when the message # is processed by the owner chain. events = [] -- cgit v1.2.3-70-g09d2 From 3df8d5182b44148bbd4b43f5474cd67b2ca699f9 Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Wed, 24 May 2017 22:25:11 -0700 Subject: Ensure the held message subject is a string. --- src/mailman/app/moderator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mailman/app/moderator.py b/src/mailman/app/moderator.py index 03028cb85..0676cb4f5 100644 --- a/src/mailman/app/moderator.py +++ b/src/mailman/app/moderator.py @@ -79,7 +79,8 @@ def hold_message(mlist, msg, msgdata=None, reason=None): msgdata['_mod_message_id'] = message_id msgdata['_mod_listid'] = mlist.list_id msgdata['_mod_sender'] = msg.sender - msgdata['_mod_subject'] = msg.get('subject', _('(no subject)')) + # The subject can sometimes be a Header instance. Stringify it. + msgdata['_mod_subject'] = str(msg.get('subject', _('(no subject)'))) msgdata['_mod_reason'] = reason msgdata['_mod_hold_date'] = now().isoformat() # Now hold this request. We'll use the message_id as the key. -- cgit v1.2.3-70-g09d2