Commit d17bd16d authored by Simon Hanna's avatar Simon Hanna

Take the parsed subject from core to prevent decoding errors

parent cc1bf8f7
...@@ -9,7 +9,7 @@ var loadjs = function(rest_url, error_message) { ...@@ -9,7 +9,7 @@ var loadjs = function(rest_url, error_message) {
url: rest_url + msgid, url: rest_url + msgid,
success: function(data) { success: function(data) {
$('#message-source-btn').attr('href', rest_url + msgid + '?raw') $('#message-source-btn').attr('href', rest_url + msgid + '?raw')
$('#message-title').html(data.msg.subject); $('#message-title').html(data.subject);
$('.modal-footer form input[name="msgid"]').attr('value', msgid); $('.modal-footer form input[name="msgid"]').attr('value', msgid);
if (data.msg.body) { if (data.msg.body) {
$('#held-message-content').text(data.msg.body); $('#held-message-content').text(data.msg.body);
......
...@@ -20,7 +20,6 @@ from __future__ import absolute_import, unicode_literals ...@@ -20,7 +20,6 @@ from __future__ import absolute_import, unicode_literals
import json import json
from email.Header import decode_header
from email.parser import Parser as EmailParser from email.parser import Parser as EmailParser
from email.parser import HeaderParser from email.parser import HeaderParser
...@@ -37,16 +36,6 @@ from django_mailman3.lib.scrub import Scrubber ...@@ -37,16 +36,6 @@ from django_mailman3.lib.scrub import Scrubber
def parse(message): def parse(message):
msgobj = EmailParser().parsestr(message) msgobj = EmailParser().parsestr(message)
header_parser = HeaderParser() header_parser = HeaderParser()
if msgobj['Subject'] is not None:
decodefrag = decode_header(msgobj['Subject'])
subj_fragments = []
for s, enc in decodefrag:
if enc:
s = unicode(s, enc).encode('utf8', 'replace')
subj_fragments.append(s)
subject = ''.join(subj_fragments)
else:
subject = None
headers = [] headers = []
headers_dict = header_parser.parsestr(message) headers_dict = header_parser.parsestr(message)
...@@ -54,7 +43,6 @@ def parse(message): ...@@ -54,7 +43,6 @@ def parse(message):
headers += ['{}: {}'.format(key, headers_dict[key])] headers += ['{}: {}'.format(key, headers_dict[key])]
content = Scrubber(msgobj).scrub()[0] content = Scrubber(msgobj).scrub()[0]
return { return {
'subject': subject,
'body': content, 'body': content,
'headers': '\n'.join(headers), 'headers': '\n'.join(headers),
} }
...@@ -79,6 +67,7 @@ def get_held_message(request, list_id, held_id=-1): ...@@ -79,6 +67,7 @@ def get_held_message(request, list_id, held_id=-1):
return HttpResponse(held_message.msg, content_type='text/plain') return HttpResponse(held_message.msg, content_type='text/plain')
response_data = dict() response_data = dict()
response_data['sender'] = held_message.sender response_data['sender'] = held_message.sender
response_data['subject'] = held_message.subject
response_data['reason'] = held_message.reason response_data['reason'] = held_message.reason
response_data['hold_date'] = held_message.hold_date response_data['hold_date'] = held_message.hold_date
response_data['msg'] = parse(held_message.msg) response_data['msg'] = parse(held_message.msg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment