Some work about the quarantine plugin.

This commit is contained in:
tonio
2009-07-03 18:01:00 +02:00
parent 1d1c23f63e
commit 44e276d9e5
13 changed files with 234 additions and 47 deletions
+31 -8
View File
@@ -2,10 +2,11 @@
"""
"""
from django.http import HttpResponseRedirect
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import get_object_or_404, render_to_response
from django.template.loader import render_to_string
from django.template import Template
from django.utils import simplejson
from django.conf.urls.defaults import *
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
@@ -69,7 +70,8 @@ ORDER BY msgs.time_num DESC
pagenum = 1
page = paginator.page(pagenum)
return _render(request, 'amavis_quarantine/index.html', {
"count" : len(rows), "emails" : page
"count" : len(rows), "emails" : page,
"current_page" : pagenum, "last_page" : paginator._get_num_pages()
})
@login_required
@@ -106,15 +108,30 @@ WHERE quarantine.mail_id='%s'
body = decode(text_body)
pre = True
return _render(request, 'amavis_quarantine/viewmail.html', {
"headers" : msg.items(),
"body" : body,
"pre" : pre
"headers" : msg, "alert" : msg.get("X-Amavis-Alert"),
"body" : body, "pre" : pre, "mail_id" : mail_id
})
@login_required
def viewheaders(request, mail_id):
conn = db.getconnection("amavis_quarantine")
status, cursor = db.execute(conn, """
SELECT mail_text
FROM quarantine
WHERE quarantine.mail_id='%s'
""" % mail_id)
content = ""
for part in cursor.fetchall():
content += part[0]
msg = email.message_from_string(content)
return _render(request, 'amavis_quarantine/viewheader.html', {
"headers" : msg.items()
})
@login_required
def process(request):
print request
if request.POST.has_key("deleteall"):
return
ids = ""
@@ -124,7 +141,7 @@ def process(request):
ids += ","
ids += "'%s'" % id
if ids == "":
return
return HttpResponseRedirect(reverse(index))
conn = db.getconnection("amavis_quarantine")
if request.POST.has_key("release"):
status, cursor = db.execute(conn, """
@@ -161,4 +178,10 @@ WHERE msgrcpt.mail_id=msgs.mail_id AND msgrcpt.rid=maddr.id AND msgs.mail_id IN
else:
message = error
request.user.message_set.create(message=message)
return HttpResponseRedirect(reverse(index))
try:
pagenum = int(request.POST.get('pagenum', '1'))
except ValueError:
pagenum = 1
ctx = _ctx_ok(reverse(index) + "?page=%s" % pagenum)
return HttpResponse(simplejson.dumps(ctx),
mimetype="application/json")
@@ -1,27 +1,39 @@
{% extends "layout.html" %}
{% load i18n %}
{% load amextras %}
{% block html_head %}
<link rel="stylesheet" type="text/css" href="/static/stylesheets/box.css" />
{% endblock %}
{% block content %}
<style type="text/css">
form {
margin: 0 auto;
width: 98%;
}
#quarmenu {
float: left;
width: 100%;
margin: 5px 0;
}
#listing {
float: left;
width: 100%;
padding-bottom: 10px;
}
#listheader {
float: left;
width: 100%;
margin-bottom: 10px;
}
#navbar {
float: right;
}
#actionbar {
#counter {
float: left;
}
#listing {
margin: 0 auto;
width: 98%;
font-weight: bold;
}
td {
@@ -30,6 +42,33 @@ td {
}
</style>
<script type="text/javascript">
window.addEvent("domready", function() {
mysubmit = function(event, name) {
event.stop();
new Element('input', {
'type' : 'submit', 'name' : name, style: "display:none"
}).inject($("quarlistingform"));
$("quarlistingform").set("send", {
onSuccess : function(res) {
response = JSON.decode(res);
location.href = response.url;
}
});
$("quarlistingform").send();
}
$$("a[name=delete]").addEvent("click", function(event) {
mysubmit(event, "delete");
});
$$("a[name=release]").addEvent("click", function(event) {
mysubmit(event, "release");
});
});
</script>
{% endblock %}
{% block content %}
<div class="header">
<h1>{% trans "Quarantine" %}</h1>
{% if messages %}
@@ -41,27 +80,40 @@ td {
{% endif %}
</div>
<div id="menubar" class="menu2">
{% quar_menu "" perms %}
</div>
{% url extensions.amavis_quarantine.main.process as actionurl %}
<form method="POST" action="{{ actionurl }}">
<form method="POST" action="{{ actionurl }}" id="quarlistingform">
<input type="hidden" name="pagenum" id="pagenum" value="{{ current_page }}" />
<div id="listing">
<b> Il y a {{ count }} messages dans la quarantaine.</b>
<div id="quarmenu">
<div id="actionbar">
<input type="submit" name="release" value="{% trans "Release" %}" />
<input type="submit" name="delete" value="{% trans "Delete" %}" />
<input type="submit" name="deleteall" value="{% trans "Delete all" %}" />
</div>
<div id="navbar">
{% if emails.has_previous %}
<a href="?page=1">{% trans "First" %}</a>
<a href="?page={{ emails.previous_page_number }}">{% trans "Previous" %}</a>
{% endif %}
{% if emails.has_next %}
<a href="?page={{ emails.next_page_number }}">{% trans "Next" %}</a>
{% endif %}
</div>
</div>
<table>
<div id="listheader">
<div id="counter">
Messages {{ emails.start_index }} à {{ emails.end_index }} sur {{ count }}
</div>
<div id="navbar">
{% if emails.has_previous %}
<a href="?page=1">
<img src="/static/pics/first.png" border="0" title="{% trans "First" %}" />
</a>
<a href="?page={{ emails.previous_page_number }}">
<img src="/static/pics/back.png" border="0" title="{% trans "Previous" %}" />
</a>
{% endif %}
{% if emails.has_next %}
<a href="?page={{ emails.next_page_number }}">
<img src="/static/pics/next.png" border="0" title="{% trans "Next" %}" />
</a>
<a href="?page={{ last_page }}">
<img src="/static/pics/last.png" border="0" title="{% trans "Last" %}" />
</a>
{% endif %}
</div>
</div>
<table>
<tr>
<th></th>
<th>{% trans "Type" %}</th>
@@ -74,7 +126,7 @@ td {
<td><input type="checkbox" name="selection" id="selection"
value="{{ m.mailid }}" /></td>
<td>{{ m.type }}</td>
{% if user.is_superuser %}<td>{{ m.to }}</td>{% endif %}
<td>{{ m.from }}</td>
{% url extensions.amavis_quarantine.main.viewmail m.mailid as view_url %}
<td><a href="{{ view_url }}">{{ m.subject }}</a></td>
<td>{{ m.time }}</td>
@@ -0,0 +1,43 @@
{% extends "layout_simple.html" %}
{% load i18n %}
{% block html_head %}
<style type="text/css">
table {
margin: 0 auto;
width: 100%;
border-collapse: collapse;
border-spacing: 20px;
}
table th {
background: #CEDBEC;
text-align: left;
padding: 5px;
}
table td {
border-bottom: 1px solid #C8D6E8;
padding: 5px;
}
td.odd {
background: #F7F9Fb;
}
td {
font-size: smaller;
height: 40px;
}
</style>
{% endblock %}
{% block content %}
<table border="0">
<tr><th colspan="2">{% trans "Message headers" %}</th></tr>
{% for k, v in headers %}
<tr>
<td class="odd">{{ k }}</td><td>{{ v }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}
@@ -10,7 +10,11 @@ window.addEvent("domready", function() {
{% else %}
doc.write("{{ body }}");
{% endif %}
doc.close();
doc.close();
SqueezeBox.assign($$('a.boxed'), {
parse: 'rel'
});
});
</script>
<link rel="stylesheet" type="text/css" href="/static/stylesheets/box.css" />
@@ -32,16 +36,24 @@ td.left {
</style>
{% endblock %}
{% block content %}
<div class="menu2">
{% load amextras %}
{% viewm_menu "headers" mail_id perms %}
</div>
<table border="0">
<tr>
<th colspan="2">{% trans "Message" %}</th>
</tr>
<tr><td class="left">X-Amavis-Alert</td><td>{{ alert }}</td></tr>
<tr><td class="left">From</td><td>{{ headers.from }}</td></tr>
<tr><td class="left">To</td><td>{{ headers.to }}</td></tr>
<tr><td class="left">Date</td><td>{{ headers.date }}</td></tr>
<tr><td class="left">Subject</td><td>{{ headers.subject }}</td></tr>
</table>
<iframe id="mailcontent"></iframe>
<table border="0">
<tr><th colspan="2">{% trans "Message headers" %}</th></tr>
{% for k, v in headers %}
<tr>
<td class="left">{{ k }}</td><td>{{ v }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}
@@ -0,0 +1,56 @@
from django import template
from django.template.loader import render_to_string
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from mailng.extensions import amavis_quarantine
register = template.Library()
@register.simple_tag
def viewm_menu(selection, mail_id, perms):
entries = [
{"name" : "back",
"url" : reverse(amavis_quarantine.main.index),
"img" : "/static/pics/back.png",
"label" : _("Back to list")},
{"name" : "headers",
"url" : reverse(amavis_quarantine.main.viewheaders, args=[mail_id]),
"img" : "/static/pics/add.png",
"label" : _("View full headers"),
"class" : "boxed",
"rel" : "{handler:'iframe',size:{x:600,y:500}}"},
{"name" : "release",
"url" : "",
"img" : "/static/pics/release.png",
"label" : _("Release")},
{"name" : "delete",
"url" : "",
"img" : "/static/pics/remove.png",
"label" : _("Delete")}
]
return render_to_string('main/menu.html',
{"selection" : selection, "entries" : entries,
"perms" : perms})
@register.simple_tag
def quar_menu(selection, perms):
entries = [
{"name" : "release",
"url" : "",
"img" : "/static/pics/release.png",
"label" : _("Release")},
{"name" : "delete",
"url" : "",
"img" : "/static/pics/remove.png",
"label" : _("Delete")},
{"name" : "deleteall",
"url" : "",
"img" : "/static/pics/remove.png",
"label" : _("Delete all")},
]
return render_to_string('main/menu.html',
{"selection" : selection, "entries" : entries,
"perms" : perms})
+2 -1
View File
@@ -2,6 +2,7 @@ from django.conf.urls.defaults import *
urlpatterns = patterns('mailng.extensions.amavis_quarantine.main',
(r'^$', 'index'),
(r'^view/(?P<mail_id>[\w\-\+]+)/$', 'viewmail'),
(r'^viewmail/(?P<mail_id>[\w\-\+]+)/$', 'viewmail'),
(r'^viewheaders/(?P<mail_id>[\w\-\+]+)/$', 'viewheaders'),
(r'^process/$', 'process')
)
Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 650 B

+1 -1
View File
@@ -2,7 +2,7 @@
<ul>
{% for entry in entries %}
<li {% ifequal selection entry.name %}class="selected"{% endifequal %}>
<a href="{{ entry.url }}"
<a href="{{ entry.url }}" name="{{ entry.name }}"
{% if entry.class %}class={{ entry.class }}{% endif %}
{% if entry.rel %}rel={{ entry.rel }}{% endif %}>
<img src="{{ entry.img }}" border="0" />