summaryrefslogtreecommitdiff
path: root/src/mailman/rest
diff options
context:
space:
mode:
authorSimon Hanna2017-01-11 02:19:04 +0100
committerSimon Hanna2017-01-11 11:19:38 +0100
commit56df446fc0892a7312845b711225abb6b940015d (patch)
tree3f52732775457a9f141e5c31db17a40e840966ff /src/mailman/rest
parentde98d9156210c46a4b8fbdda0332567335421595 (diff)
downloadmailman-56df446fc0892a7312845b711225abb6b940015d.tar.gz
mailman-56df446fc0892a7312845b711225abb6b940015d.tar.zst
mailman-56df446fc0892a7312845b711225abb6b940015d.zip
Diffstat (limited to 'src/mailman/rest')
-rw-r--r--src/mailman/rest/docs/post-moderation.rst27
-rw-r--r--src/mailman/rest/post_moderation.py11
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']