diff options
| -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'] |
