diff options
| author | Simon Hanna | 2017-01-11 17:25:48 +0100 |
|---|---|---|
| committer | Simon Hanna | 2017-01-11 17:29:31 +0100 |
| commit | f921ee9779f016c88cd83afb59dbc4a7a0e961cd (patch) | |
| tree | 7048fe9bf2eb81c94be014cc9cc9fbc759d985c7 | |
| parent | 56df446fc0892a7312845b711225abb6b940015d (diff) | |
| download | mailman-f921ee9779f016c88cd83afb59dbc4a7a0e961cd.tar.gz mailman-f921ee9779f016c88cd83afb59dbc4a7a0e961cd.tar.zst mailman-f921ee9779f016c88cd83afb59dbc4a7a0e961cd.zip | |
| -rw-r--r-- | src/mailman/rest/docs/post-moderation.rst | 2 | ||||
| -rw-r--r-- | src/mailman/rest/post_moderation.py | 16 |
2 files changed, 8 insertions, 10 deletions
diff --git a/src/mailman/rest/docs/post-moderation.rst b/src/mailman/rest/docs/post-moderation.rst index eb8f353a0..fcb1f0938 100644 --- a/src/mailman/rest/docs/post-moderation.rst +++ b/src/mailman/rest/docs/post-moderation.rst @@ -202,7 +202,7 @@ to the original author. Request to mailing list "Ant" rejected The subject of the message is decoded and the original subject is accessible -under 'original_subject' +under ``original_subject``. :: >>> msg = message_from_string("""\ diff --git a/src/mailman/rest/post_moderation.py b/src/mailman/rest/post_moderation.py index 876e81f0f..a747917de 100644 --- a/src/mailman/rest/post_moderation.py +++ b/src/mailman/rest/post_moderation.py @@ -17,9 +17,9 @@ """REST API for held message moderation.""" -import email.header - +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 @@ -92,14 +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 + # 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 + # 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'] |
