Barry Warsaw pushed to branch master at mailman / Mailman

Commits:
49158a23 by Mark Sapiro at 2017-05-24T17:58:34-07:00
Refactor Header object test to create the message without cheating.

- - - - -
3df8d518 by Mark Sapiro at 2017-05-24T22:25:11-07:00
Ensure the held message subject is a string.

- - - - -
792f1eb7 by Barry Warsaw at 2017-05-25T15:35:46+00:00
Merge branch 'header' into 'master'

Refactor Header object test to create the message without cheating.

See merge request !283
- - - - -


2 changed files:

- src/mailman/app/moderator.py
- src/mailman/chains/tests/test_headers.py


Changes:

=====================================
src/mailman/app/moderator.py
=====================================
--- 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.


=====================================
src/mailman/chains/tests/test_headers.py
=====================================
--- 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: a...@example.com
 To: t...@example.com
-Subject: =?unknown-8bit?q?Become_smarter_now_=96_Increase__your_brain...?=
+Subject: Bad \x96 subject
 Message-ID: <ant>
 
 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 = []



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/3596e9f971e289270ec372266cd0d891b61b56e6...792f1eb7d511b3b4ec8564c9fcbfc87acd0de9a4

---
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/3596e9f971e289270ec372266cd0d891b61b56e6...792f1eb7d511b3b4ec8564c9fcbfc87acd0de9a4
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

Reply via email to