diff --git a/src/postorius/static/postorius/js/held_messages.js b/src/postorius/static/postorius/js/held_messages.js new file mode 100644 index 0000000..9f7aaec --- /dev/null +++ b/src/postorius/static/postorius/js/held_messages.js @@ -0,0 +1,40 @@ +var loadjs = function(rest_url, error_message) { + $('#all-messages-checkbox').change(function() { + $('.message-checkbox').prop('checked', this.checked); + }); + $('.show-modal-btn').click(function() { + var msgid = $(this).data('msgid'); + $.ajax({ + url: rest_url + msgid, + success: function(data) { + $('#msg-title').html(data.subject); + $('#held-stripped-message').html(data.stripped_msg.replace(/\n/g, "
")); + $('#held-full-message').html(data.msg.replace(/\n/g, "
")); + $('#held-messages-modal').modal('show'); + }, + error : function() { + alert(error_message); + }, + statusCode: { + 500: function() { + alert(error_message); + } + }}); + return false; + }); + $('#toggle-full-message').click(function() { + if ($(this).hasClass('active')) { + $('#held-stripped-message').removeClass('hidden'); + $('#held-full-message').addClass('hidden'); + } else { + $('#held-stripped-message').addClass('hidden'); + $('#held-full-message').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'); + }); +} diff --git a/src/postorius/templates/postorius/lists/held_messages.html b/src/postorius/templates/postorius/lists/held_messages.html index 46d5de6..5543b11 100644 --- a/src/postorius/templates/postorius/lists/held_messages.html +++ b/src/postorius/templates/postorius/lists/held_messages.html @@ -1,6 +1,7 @@ {% extends postorius_base_template %} {% load i18n %} {% load nav_helpers %} +{% load staticfiles %} {% block subtitle %} {% trans 'Held messages' %} | {{ list.fqdn_listname }} @@ -55,26 +56,10 @@ {{ msg.hold_date }} - {% trans 'View' %} + {% trans 'View' %} {% trans 'Accept' %} {% trans 'Reject' %} {% trans 'Discard' %} - {% endfor %} @@ -83,15 +68,36 @@ {% include 'postorius/lib/pagination.html' with page=held_messages %} - {% else %} + + {% else %}

{% trans 'There are currently no held messages.' %}

{% endif %} {% endblock %} {% block additionaljs %} + {% endblock %} diff --git a/src/postorius/urls.py b/src/postorius/urls.py index 8568480..0b7bf66 100644 --- a/src/postorius/urls.py +++ b/src/postorius/urls.py @@ -23,6 +23,7 @@ from postorius.views import list as list_views from postorius.views import user as user_views from postorius.views import domain as domain_views +from postorius.views import rest as rest_views list_patterns = [ @@ -105,4 +106,6 @@ url(r'^users/address_activation/(?P[A-Za-z0-9]+)/$', user_views.address_activation_link, name='address_activation_link'), + url(r'^api/list/(?P[^/]+)/held_message/$', rest_views.get_held_message, name='uncomplete_rest_held_message'), + url(r'^api/list/(?P[^/]+)/held_message/(?P\d+)/$', rest_views.get_held_message, name='rest_held_message'), ] diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index 5146215..6851acd 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -382,7 +382,7 @@ @login_required @list_moderator_required -def list_moderation(request, list_id): +def list_moderation(request, list_id, held_id=-1): mailing_list = utils.get_client().get_list(list_id) if request.method == 'POST': form = MultipleChoiceForm(request.POST) diff --git a/src/postorius/views/rest.py b/src/postorius/views/rest.py new file mode 100644 index 0000000..df9ddda --- /dev/null +++ b/src/postorius/views/rest.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 1998-2015 by the Free Software Foundation, Inc. +# +# This file is part of Postorius. +# +# Postorius is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# Postorius is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# Postorius. If not, see . +import json + +from email import message_from_string + +from django.http import HttpResponse, Http404 + +from django.contrib.auth.decorators import login_required +from django.utils.translation import gettext as _ +from postorius.auth.decorators import * + + +def _strip_email(email_text): + """Strip most of the headers from the email for the + held messages view. + + Only these headers would be kept: + - To + - From + - Date + - CC + - Subject + + If available, show only the text part of the email. + + TODO: maxking - modify this later to extract text from HTML + to be displayed there. + """ + msg = message_from_string(email_text) + + content_type = msg.get_content_type() + if content_type == 'multipart/alternative': + for part in msg.walk(): + if part.get_content_type() == 'text/plain': + msg.set_payload(part.as_string()) + + show_headers = ['To', 'From', 'Date', 'CC', 'Subject'] + for header in msg.keys(): + if header not in show_headers: + del msg[header] + + return msg.as_string() + +@login_required +@list_moderator_required +def get_held_message(request, list_id, held_id=-1): + """Return a held message as a json object + """ + if held_id == -1: + raise Http404(_('Message does not exist')) + + held_message = List.objects.get_or_404(fqdn_listname=list_id).get_held_message(held_id) + + response_data = dict() + response_data['sender'] = held_message.sender + try: + response_data['reasons'] = held_message.reasons + except AttributeError: + 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'] = _strip_email(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")