diff --git a/src/postorius/static/postorius/js/held_messages.js b/src/postorius/static/postorius/js/held_messages.js index ceddb63..653c33b 100644 --- a/src/postorius/static/postorius/js/held_messages.js +++ b/src/postorius/static/postorius/js/held_messages.js @@ -7,10 +7,20 @@ $.ajax({ url: rest_url + msgid, success: function(data) { - $('#msg-title').html(data.subject); + $('#message-source-btn').attr('href', rest_url + msgid + '?raw') + $('#message-title').html(data.msg.subject); $('.modal-footer form input[name="msgid"]').attr('value', msgid); - $('#held-stripped-message').html(data.stripped_msg.body.replace(/\n/g, "
")); - $('#held-full-message').html(data.msg.replace(/\n/g, "
")); + if (data.msg.body) { + $('#held-message-content').text(data.msg.body); + } + else if (data.msg.html) { + $('#held-message-content').text(data.msg.html); + } else { + $('#held-message-content').html('

Message content could not be extracted

'); + } + $('#held-message-content').html($('#held-message-content').html().replace(/\n/g, "
")); + $('#held-message-headers').text(data.msg.headers); + $('#held-message-headers').html($('#held-message-headers').html().replace(/\n/g, "
") + '
'); $('#held-messages-modal').modal('show'); }, error : function() { @@ -23,19 +33,16 @@ }}); return false; }); - $('#toggle-full-message').click(function() { + $('#toggle-headers').click(function() { if ($(this).hasClass('active')) { - $('#held-stripped-message').removeClass('hidden'); - $('#held-full-message').addClass('hidden'); + $('#held-message-headers').addClass('hidden'); } else { - $('#held-stripped-message').addClass('hidden'); - $('#held-full-message').removeClass('hidden'); + $('#held-message-headers').removeClass('hidden'); } }); $('#held-messages-modal').on('hidden.bs.modal', function() { - $('#held-stripped-message').removeClass('hidden'); - $('#held-full-message').addClass('hidden'); - $('#msg-title').html(''); - $('#toggle-full-message').removeClass('active'); + $('#held-message-headers').addClass('hidden'); + $('#message-title').html(''); + $('#toggle-headers').removeClass('active'); }); } diff --git a/src/postorius/templates/postorius/lists/held_messages.html b/src/postorius/templates/postorius/lists/held_messages.html index 651416b..5277ba0 100644 --- a/src/postorius/templates/postorius/lists/held_messages.html +++ b/src/postorius/templates/postorius/lists/held_messages.html @@ -70,12 +70,12 @@ diff --git a/src/postorius/views/rest.py b/src/postorius/views/rest.py index 31ef3ee..95ab919 100644 --- a/src/postorius/views/rest.py +++ b/src/postorius/views/rest.py @@ -22,6 +22,7 @@ from email.Header import decode_header from base64 import b64decode from email.Parser import Parser as EmailParser +from email.parser import HeaderParser from email.utils import parseaddr from StringIO import StringIO @@ -57,6 +58,7 @@ def parse(content): p = EmailParser() msgobj = p.parsestr(content) + header_parser = HeaderParser() if msgobj['Subject'] is not None: decodefrag = decode_header(msgobj['Subject']) subj_fragments = [] @@ -99,12 +101,17 @@ ).encode('utf8','replace') else: html += part.get_payload(decode=True) + headers = [] + headers_dict = header_parser.parsestr(content) + for key in headers_dict.keys(): + headers += ['{}: {}'.format(key, headers_dict[key])] return { 'subject' : subject, 'body' : body, 'html' : html, 'from' : parseaddr(msgobj.get('From'))[1], 'to' : parseaddr(msgobj.get('To'))[1], + 'headers': '\n'.join(headers), #'attachments': attachments, } @@ -118,7 +125,8 @@ raise Http404(_('Message does not exist')) held_message = List.objects.get_or_404(fqdn_listname=list_id).get_held_message(held_id) - + if 'raw' in request.GET: + return HttpResponse(held_message.msg, content_type='text/plain') response_data = dict() response_data['sender'] = held_message.sender try: @@ -127,9 +135,8 @@ pass response_data['moderation_reasons'] = held_message.moderation_reasons response_data['hold_date'] = held_message.hold_date - response_data['msg'] = held_message.msg - response_data['stripped_msg'] = parse(held_message.msg) + response_data['msg'] = parse(held_message.msg) response_data['msgid'] = held_message.request_id response_data['subject'] = held_message.subject - return HttpResponse(json.dumps(response_data), content_type="application/json") + return HttpResponse(json.dumps(response_data), content_type='application/json')