diff options
| author | Barry Warsaw | 2017-01-15 20:34:48 +0000 |
|---|---|---|
| committer | Barry Warsaw | 2017-01-15 20:34:48 +0000 |
| commit | f22a4a158bc3ac9fe3cd46f21761bb5e87e1edd0 (patch) | |
| tree | 7048fe9bf2eb81c94be014cc9cc9fbc759d985c7 | |
| parent | de98d9156210c46a4b8fbdda0332567335421595 (diff) | |
| parent | f921ee9779f016c88cd83afb59dbc4a7a0e961cd (diff) | |
| download | mailman-f22a4a158bc3ac9fe3cd46f21761bb5e87e1edd0.tar.gz mailman-f22a4a158bc3ac9fe3cd46f21761bb5e87e1edd0.tar.zst mailman-f22a4a158bc3ac9fe3cd46f21761bb5e87e1edd0.zip | |
| -rw-r--r-- | src/mailman/rest/docs/post-moderation.rst | 27 | ||||
| -rw-r--r-- | src/mailman/rest/post_moderation.py | 9 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/mailman/rest/docs/post-moderation.rst b/src/mailman/rest/docs/post-moderation.rst index 8a1bdd2e4..fcb1f0938 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..a747917de 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.""" +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'] |
