Barry Warsaw pushed to branch master at mailman / Mailman
Commits: 56df446f by Simon Hanna at 2017-01-11T11:19:38+01:00 Decode RFC2047 encoded Subject when accessing held messages - - - - - f921ee97 by Simon Hanna at 2017-01-11T17:29:31+01:00 Style fixes - - - - - f22a4a15 by Barry Warsaw at 2017-01-15T20:34:48+00:00 Merge branch 'decode-subject' into 'master' Decode RFC2047 encoded Subject when accessing held messages Closes #219 and postorius#143 See merge request !235 - - - - - 2 changed files: - src/mailman/rest/docs/post-moderation.rst - src/mailman/rest/post_moderation.py Changes: ===================================== src/mailman/rest/docs/post-moderation.rst ===================================== --- a/src/mailman/rest/docs/post-moderation.rst +++ b/src/mailman/rest/docs/post-moderation.rst @@ -50,6 +50,7 @@ When a message gets held for moderator approval, it shows up in this list. <BLANKLINE> Something else. <BLANKLINE> + original_subject: Something reason: Because request_id: 1 self_link: http://localhost:9001/3.0/lists/ant.example.com/held/1 @@ -81,6 +82,7 @@ message. This will include the text of the message. <BLANKLINE> Something else. <BLANKLINE> + original_subject: Something reason: Because request_id: 1 self_link: http://localhost:9001/3.0/lists/ant.example.com/held/1 @@ -126,6 +128,7 @@ The message is still in the moderation queue. <BLANKLINE> Something else. <BLANKLINE> + original_subject: Something reason: Because request_id: 1 self_link: http://localhost:9001/3.0/lists/ant.example.com/held/1 @@ -197,3 +200,27 @@ to the original author. 1 >>> print(messages[0].msg['subject']) Request to mailing list "Ant" rejected + +The subject of the message is decoded and the original subject is accessible +under ``original_subject``. +:: + + >>> msg = message_from_string("""\ + ... From: a...@example.com + ... To: a...@example.com + ... Subject: =?iso-8859-1?q?p=F6stal?= + ... Message-ID: <beta> + ... + ... Something else. + ... """) + + >>> from mailman.app.moderator import hold_message + >>> request_id = hold_message(ant, msg, {'extra': 7}, 'Because') + >>> transaction.commit() + + >>> results = call_http(url(request_id)) + >>> print(results['subject']) + pöstal + >>> print(results['original_subject']) + =?iso-8859-1?q?p=F6stal?= + ===================================== src/mailman/rest/post_moderation.py ===================================== --- a/src/mailman/rest/post_moderation.py +++ b/src/mailman/rest/post_moderation.py @@ -17,6 +17,9 @@ """REST API for held message moderation.""" +from contextlib import suppress +from email.errors import MessageError +from email.header import decode_header, make_header from mailman.app.moderator import handle_message from mailman.interfaces.action import Action from mailman.interfaces.messages import IMessageStore @@ -89,6 +92,12 @@ class _HeldMessageBase(_ModerationBase): resource[key[5:]] = resource.pop(key) elif key.startswith('_mod_'): del resource[key] + # Store the original header and then try decoding it. + resource['original_subject'] = resource['subject'] + # If we can't decode the header, leave the subject unchanged. + with suppress(LookupError, MessageError): + resource['subject'] = str( + make_header(decode_header(resource['subject']))) # Also, held message resources will always be this type, so ignore # this key value. del resource['type'] View it on GitLab: https://gitlab.com/mailman/mailman/compare/de98d9156210c46a4b8fbdda0332567335421595...f22a4a158bc3ac9fe3cd46f21761bb5e87e1edd0
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org