summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/rest/docs/post-moderation.rst27
-rw-r--r--src/mailman/rest/post_moderation.py9
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']