mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-12-02 12:13:54 +01:00
German translation + minor fix about plural forms
This commit is contained in:
@@ -2,41 +2,29 @@
|
||||
|
||||
"""
|
||||
"""
|
||||
from datetime import datetime
|
||||
import time
|
||||
import email
|
||||
import re
|
||||
import os
|
||||
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.utils.translation import ugettext as _, ungettext
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.paginator import Paginator
|
||||
from django.contrib.auth.decorators \
|
||||
import login_required
|
||||
from mailng.lib import events
|
||||
from mailng.lib import events, parameters
|
||||
from mailng.lib import _render, _ctx_ok, _ctx_ko, decode
|
||||
from mailng.lib import db
|
||||
from mailng.admin.models import Mailbox
|
||||
from lib import AMrelease
|
||||
from datetime import datetime
|
||||
import email
|
||||
import re
|
||||
import os
|
||||
import lxml.html
|
||||
from lxml.html.clean import Cleaner
|
||||
from sql_listing import *
|
||||
|
||||
attached_map = {}
|
||||
|
||||
def map_cid(url):
|
||||
map = globals()["attached_map"]
|
||||
m = re.match(".*cid:([^\"]+)", url)
|
||||
if m:
|
||||
if map.has_key(m.group(1)):
|
||||
return map[m.group(1)]
|
||||
return url
|
||||
|
||||
def init():
|
||||
events.register("UserMenuDisplay", menu)
|
||||
parameters.register("amavis_quarantine", "MAX_MESSAGES_AGE", "int", 14,
|
||||
help=_("Quarantine messages maximum age (in days) before deletion"))
|
||||
|
||||
def urls():
|
||||
return (r'^mailng/quarantine/',
|
||||
@@ -51,82 +39,27 @@ def menu(**kwargs):
|
||||
]
|
||||
return []
|
||||
|
||||
def lookup(*args):
|
||||
filter = ""
|
||||
for a in args:
|
||||
if not a:
|
||||
continue
|
||||
if a[0] == "&":
|
||||
filter += " AND "
|
||||
else:
|
||||
filter += " OR "
|
||||
filter += a[1:]
|
||||
conn = db.getconnection("amavis_quarantine")
|
||||
status, cursor = db.execute(conn, """
|
||||
SELECT msgs.from_addr, maddr.email, msgs.subject, msgs.content, quarantine.mail_id,
|
||||
msgs.time_num, msgs.content
|
||||
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
|
||||
ORDER BY msgs.time_num DESC
|
||||
""" % filter)
|
||||
return cursor
|
||||
|
||||
def render_listing(request, cursor):
|
||||
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], "time" : datetime.fromtimestamp(row[5]),
|
||||
"type" : row[6]})
|
||||
paginator = Paginator(emails, 10)
|
||||
try:
|
||||
pagenum = int(request.GET.get('page', '1'))
|
||||
except ValueError:
|
||||
pagenum = 1
|
||||
page = paginator.page(pagenum)
|
||||
return render_to_string("amavis_quarantine/listing.html", {
|
||||
"count" : len(rows),
|
||||
"emails" : page, "current_page" : pagenum,
|
||||
"last_page" : paginator._get_num_pages()
|
||||
})
|
||||
|
||||
@login_required
|
||||
def index(request, message=None):
|
||||
start = time.time()
|
||||
if not request.user.is_superuser:
|
||||
mb = Mailbox.objects.get(user=request.user.id)
|
||||
filter = "&maddr.email='%s'" % mb.full_address
|
||||
filter = ["&maddr.email='%s'" % mb.full_address]
|
||||
else:
|
||||
filter = None
|
||||
cursor = lookup(filter)
|
||||
|
||||
return _render(request, 'amavis_quarantine/index.html', {
|
||||
"content" : render_listing(request, cursor)
|
||||
})
|
||||
|
||||
@login_required
|
||||
def viewmail_plain(request, content):
|
||||
body = decode(content)
|
||||
return (True, body)
|
||||
|
||||
@login_required
|
||||
def viewmail_html(request, content):
|
||||
links = request.GET.has_key("links") and request.GET["links"] or "0"
|
||||
html = lxml.html.fromstring(content)
|
||||
if links == "0":
|
||||
html.rewrite_links(lambda x: None)
|
||||
else:
|
||||
html.rewrite_links(map_cid)
|
||||
body = lxml.html.tostring(html)
|
||||
body = Template(decode(body)).render({})
|
||||
return (False, body)
|
||||
try:
|
||||
pageid = request.GET["page"]
|
||||
if pageid == "":
|
||||
pageid = 1
|
||||
except KeyError:
|
||||
pageid = 1
|
||||
lst = SQLlisting(filter)
|
||||
return lst.render(request, pageid=int(pageid), start=start)
|
||||
|
||||
@login_required
|
||||
def getmailcontent(request, mail_id):
|
||||
from mailng.lib.email_listing import Email
|
||||
|
||||
conn = db.getconnection("amavis_quarantine")
|
||||
status, cursor = db.execute(conn, """
|
||||
SELECT mail_text
|
||||
@@ -139,41 +72,8 @@ WHERE quarantine.mail_id='%s'
|
||||
msg = email.message_from_string(content)
|
||||
links = request.GET.has_key("links") and request.GET["links"] or "0"
|
||||
mode = request.GET.has_key("mode") and request.GET["mode"] or "plain"
|
||||
contents = {"html" : "", "plain" : ""}
|
||||
for part in msg.walk():
|
||||
#print part.get_content_type()
|
||||
if part.get_content_maintype() == 'multipart':
|
||||
continue
|
||||
if part.get_content_type() in ("text/html", "text/plain"):
|
||||
contents[part.get_content_subtype()] += part.get_payload(decode=True)
|
||||
if mode != "html" or links == "0":
|
||||
continue
|
||||
|
||||
if part.get_content_maintype() == "image":
|
||||
if part.has_key("Content-Location"):
|
||||
fname = part["Content-Location"]
|
||||
if re.match("^http:", fname):
|
||||
path = fname
|
||||
else:
|
||||
path = "/%s" % os.path.join("static/tmp", fname)
|
||||
fp = open(path, "wb")
|
||||
fp.write(part.get_payload(decode=True))
|
||||
fp.close()
|
||||
m = re.match("<(.+)>", part["Content-ID"])
|
||||
if m:
|
||||
attached_map[m.group(1)] = path
|
||||
else:
|
||||
attached_map[part["Content-ID"]] = path
|
||||
|
||||
if not contents.has_key(mode) or contents[mode] == "":
|
||||
if mode == "html":
|
||||
mode = "plain"
|
||||
else:
|
||||
mode = "html"
|
||||
(pre, body) = globals()["viewmail_%s" % mode](request, contents[mode])
|
||||
return _render(request, 'amavis_quarantine/getmailcontent.html', {
|
||||
"body" : body, "pre" : pre
|
||||
})
|
||||
mail = Email(msg, mode, links)
|
||||
return mail.render(request)
|
||||
|
||||
@login_required
|
||||
def viewmail(request, mail_id):
|
||||
@@ -224,8 +124,9 @@ def delete(request, mail_id, count=1):
|
||||
status, error = db.execute(conn,
|
||||
"DELETE FROM msgs WHERE mail_id IN (%s)" % mail_id)
|
||||
if status:
|
||||
message = _("%(count)d message%(plural)s deleted successfully" \
|
||||
% ({"count" : count, "plural" : count > 1 and "s" or ""}))
|
||||
message = ungettext("%(count)d message deleted successfully",
|
||||
"%(count)d messages deleted successfully",
|
||||
count) % {"count" : count}
|
||||
else:
|
||||
message = error
|
||||
return _redirect_to_index(request, message, count)
|
||||
@@ -264,8 +165,9 @@ WHERE msgrcpt.mail_id=msgs.mail_id AND msgrcpt.rid=maddr.id AND msgs.mail_id IN
|
||||
error = result
|
||||
break
|
||||
if not error:
|
||||
message = _("%(count)d message%(plural)s released successfully" \
|
||||
% {"count" : count, "plural" : count > 1 and "s" or ""})
|
||||
message = ungettext("%(count)d message released successfully",
|
||||
"%(count)d messages released successfully",
|
||||
count) % {"count" : count}
|
||||
else:
|
||||
message = error
|
||||
return _redirect_to_index(request, message, count)
|
||||
@@ -309,7 +211,19 @@ def search(request):
|
||||
filter += " OR "
|
||||
filter += "msgs.%s LIKE '%%%s%%'" % (c, pattern)
|
||||
filter = "&(%s)" % filter
|
||||
cursor = lookup(filter)
|
||||
ctx = {"status" : "ok", "content" : render_listing(request, cursor)}
|
||||
return HttpResponse(simplejson.dumps(ctx),
|
||||
mimetype="application/json")
|
||||
lst = SQLlisting([filter])
|
||||
try:
|
||||
pageid = request.GET["page"]
|
||||
if pageid == "":
|
||||
pageid = 1
|
||||
except KeyError:
|
||||
pageid = 1
|
||||
page = lst.paginator.getpage(pageid)
|
||||
if page:
|
||||
content = lst.fetch(page.id_start, page.id_stop).render(request)
|
||||
navbar = lst.render_navbar(page)
|
||||
else:
|
||||
content = "Empty quarantine"
|
||||
navbar = ""
|
||||
ctx = {"status" : "ok", "listing" : content, "navbar" : navbar}
|
||||
return HttpResponse(simplejson.dumps(ctx), mimetype="application/json")
|
||||
|
||||
Reference in New Issue
Block a user