Important update of the plugin engine.

New plugin that allows the handling of an Amavisd-new SQL quarantine.

NB: a DB connections manager has been added inside the lib because
Django does not support multiple connections at the same time. The
main consequence is that we don't use an ORM and that we have to
rewrite a small wrapper that supports several DB (mysql, postgresql, etc.).
Adding a dependancy to an existing ORM module (like SQLalchemy) is
heavy, we don't want that for now.
This commit is contained in:
Antoine Nguyen
2009-06-26 17:13:35 +02:00
parent fc74d34c1d
commit fcab20b608
17 changed files with 227 additions and 19 deletions
+9
View File
@@ -2,6 +2,8 @@
import os
import re
extensions = []
def loadextensions():
from django.conf import settings
@@ -12,3 +14,10 @@ def loadextensions():
continue
module = __import__(m.group(1), globals(), locals(), ['main'])
module.main.init()
globals()['extensions'] += [module]
def loadmenus():
result = ()
for mod in extensions:
result += mod.main.urls()
return result
+64
View File
@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
"""
"""
from django.shortcuts import get_object_or_404, render_to_response
from django.conf.urls.defaults import *
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator
from mailng.lib import events
from mailng.lib import _render, _ctx_ok, _ctx_ko
from mailng.lib import db
from mailng.admin.models import Mailbox
def init():
events.register("UserMenuDisplay", menu)
def urls():
return (r'^mailng/quarantine/',
include('mailng.extensions.amavis_quarantine.urls'))
def menu(**kwargs):
return [
{"name" : _("Quarantine"),
"url" : reverse(index),
"img" : "/static/pics/quarantine.png"}
]
def index(request):
if not request.user.is_superuser:
mb = Mailbox.objects.get(user=request.user.id)
filter = "AND maddr.email='%s'" % mb.full_address
else:
filter = ""
cursor = db.getconnection("amavis_quarantine").cursor()
cursor.execute("""
SELECT msgs.from_addr, maddr.email, msgs.subject, msgs.content, quarantine.mail_id
FROM quarantine, maddr, msgrcpt, msgs
WHERE quarantine.mail_id=msgrcpt.mail_id
AND msgrcpt.rid=maddr.id
AND msgrcpt.mail_id=msgs.mail_id
AND quarantine.chunk_ind=1
%s
""" % filter)
emails = []
rows = cursor.fetchall()
for row in rows:
emails.append({"from" : row[0], "to" : row[1],
"subject" : row[2], "content" : row[3],
"mailid" : row[4]})
# cursor.execute("SELECT count(*) AS cnt FROM quarantine")
# row = cursor.fetchone()
# cnt = row[0]
paginator = Paginator(emails, 10)
try:
pagenum = int(request.GET.get('page', '1'))
except ValueError:
pagenum = 1
page = paginator.page(pagenum)
return _render(request, 'amavis_quarantine/index.html', {
"count" : len(rows), "emails" : page
})
@@ -0,0 +1,71 @@
{% extends "layout.html" %}
{% load i18n %}
{% block html_head %}
<link rel="stylesheet" type="text/css" href="/static/stylesheets/box.css" />
{% endblock %}
{% block content %}
<style type="text/css">
#quarmenu {
float: left;
width: 100%;
margin: 5px 0;
}
#navbar {
float: right;
}
#actionbar {
float: left;
}
td {
font-size: smaller;
height: 40px;
}
</style>
<div class="header">
<h1>{% trans "Quarantine" %}</h1>
{% if messages %}
<div id="infos">
{% for m in messages %}
{{ m }}
{% endfor %}
</div>
{% endif %}
</div>
<div id="subcontent">
<b> Il y a {{ count }} messages dans la quarantaine.</b>
<div id="quarmenu">
<div id="actionbar">
<input type="button" name="release" value="{% trans "Release" %}" />
<input type="button" name="delete" value="{% trans "Delete" %}" />
<input type="button" name="deleteall" value="{% trans "Delete all" %}" />
</div>
<div id="navbar">
{% if emails.has_previous %}
<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>
<tr>
<th></th>
<th width="150px">{% trans "From" %}</th>
<th width="150px">{% trans "To" %}</th>
<th>{% trans "Subject" %}</th>
</tr>
{% for m in emails.object_list %}
<tr class="{% cycle 'odd' 'even' %}">
<td><input type="checkbox" name="selection" id="selection" /></td>
<td>{{ m.from }}</td><td>{{ m.to }}</td><td>{{ m.subject }}</td></tr>
{% endfor %}
</table>
</div>
{% endblock %}
+5
View File
@@ -0,0 +1,5 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('mailng.extensions.amavis_quarantine.main',
(r'^$', 'index'),
)
+3
View File
@@ -16,6 +16,9 @@ def init():
events.register("CreateMailbox", onCreateMailbox)
events.register("DeleteMailbox", onDeleteMailbox)
def urls():
return ()
def onCreateDomain(**kwargs):
dom = kwargs["dom"]
transport = Transport()