diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/rest/docs/post-moderation.rst | 27 | ||||
| -rw-r--r-- | src/mailman/rest/post_moderation.py | 11 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/mailman/rest/docs/post-moderation.rst b/src/mailman/rest/docs/post-moderation.rst index 8a1bdd2e4..eb8f353a0 100644 --- 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: anne@example.com + ... To: ant@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?= + diff --git a/src/mailman/rest/post_moderation.py b/src/mailman/rest/post_moderation.py index 67df9f78b..876e81f0f 100644 --- a/src/mailman/rest/post_moderation.py +++ b/src/mailman/rest/post_moderation.py @@ -17,6 +17,9 @@ """REST API for held message moderation.""" +import email.header + +from email.errors import MessageError from mailman.app.moderator import handle_message from mailman.interfaces.action import Action from mailman.interfaces.messages import IMessageStore @@ -89,6 +92,14 @@ 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'] + try: + resource['subject'] = email.header.make_header( + email.header.decode_header(resource['subject'])).__str__() + except (LookupError, MessageError): + # If we can't decode the header, leave the subject unchanged + pass # Also, held message resources will always be this type, so ignore # this key value. del resource['type'] |
