This commit is contained in:
tonio
2010-05-05 13:18:12 +02:00
parent 7480e479e7
commit 6adbc5c6be
9 changed files with 64 additions and 25 deletions
+3 -3
View File
@@ -115,7 +115,7 @@ def index(request, message=None):
@login_required
def getmailcontent(request, mail_id):
from mailng.lib.email_listing import Email
from sql_listing import SQLemail
conn = db.getconnection("amavis_quarantine")
status, cursor = db.execute(conn, """
@@ -129,9 +129,9 @@ 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"
mail = Email(msg, mode, links)
mail = SQLemail(msg, mode, links)
return _render(request, "common/viewmail.html", {
"headers" : "",
"headers" : mail.render_headers(),
"mailbody" : mail.body,
"pre" : mail.pre
})
+19 -1
View File
@@ -3,7 +3,7 @@
from datetime import datetime
from django.utils.translation import ugettext as _
from mailng.lib import tables, db
from mailng.lib.email_listing import MBconnector, EmailListing
from mailng.lib.email_listing import MBconnector, EmailListing, Email
class Qtable(tables.Table):
tableid = "emails"
@@ -92,3 +92,21 @@ class SQLlisting(EmailListing):
def __init__(self, filter, **kwargs):
self.mbc = SQLconnector(filter)
EmailListing.__init__(self, **kwargs)
class SQLemail(Email):
def __init__(self, msg, *args, **kwargs):
Email.__init__(self, msg, *args, **kwargs)
fields = ["X-Amavis-Alert", "Subject", "From", "To", "Date"]
for f in fields:
label = f
if not msg.has_key(f):
f = f.upper()
if not msg.has_key(f):
self.headers += [{"name" : label, "value" : ""}]
continue
self.headers += [{"name" : label, "value" : msg[f]}]
try:
label = re.sub("-", "_", label)
setattr(self, label, msg[f])
except:
pass
+15 -2
View File
@@ -349,8 +349,8 @@ class ImapListing(EmailListing):
self.mbc.criterions = ["(%s)" % criterions]
class ImapEmail(Email):
def __init__(self, msg, addrfull=False, **kwargs):
Email.__init__(self, msg, **kwargs)
def __init__(self, msg, addrfull=False, *args, **kwargs):
Email.__init__(self, msg, *args, **kwargs)
fields = ["Subject", "From", "To", "Reply-To", "Cc", "Date"]
for f in fields:
@@ -371,3 +371,16 @@ class ImapEmail(Email):
except:
pass
def render_headers(self, **kwargs):
attachments = []
for part in self.attachments:
decoded = decode_header(part.get_filename())
if decoded[0][1] is None:
attachments += [decoded[0][0]]
else:
attachments += [unicode(decoded[0][0], decoded[0][1])]
return render_to_string("webmail/headers.html", {
"headers" : self.headers,
"folder" : kwargs["folder"], "mail_id" : kwargs["mail_id"],
"attachments" : attachments != [] and attachments or None
})
+6 -7
View File
@@ -1,9 +1,8 @@
{% extends "common/mailheaders.html" %}
{% load i18n %}
<table id="emailheaders">
{% for hdr in headers %}
<tr><th width="130px">{{ hdr.name }}</th><td>{{ hdr.value }}</td></tr>
{% endfor %}
{% if attachments %}
{% block extraheaders %}
{% if attachments %}
<tr>
<th>{% trans "Attachments" %}</th>
<td>
@@ -13,5 +12,5 @@
{% endfor %}
</td>
</tr>
{% endif %}
</table>
{% endif %}
{% endblock %}