mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-27 11:24:28 +01:00
fix: using MEDIA_URL inside templates.
wip: #36, using tinyMCE (django-tinymce) to write messages in HTML. Currently, compose a new message is working pretty well. Answering or forwarding a message is still a mess...
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{% extends "common/email_listing.html" %}
|
||||
{% load i18n %}
|
||||
{% block css %}
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/quarantine.css" />
|
||||
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/quarantine.css" />
|
||||
{% endblock %}
|
||||
{% block js %}
|
||||
mysubmit = function(event, name) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{% extends "layout_simple.html" %}
|
||||
{% load i18n %}
|
||||
{% block html_head %}
|
||||
<script src="/static/js/form.js" type="text/javascript"></script>
|
||||
<script src="{{ MEDIA_URL }}js/form.js" type="text/javascript"></script>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="/static/css/calendar.css" />
|
||||
<script type="text/javascript" src="/static/js/calendar.js"></script>
|
||||
href="{{ MEDIA_URL }}css/calendar.css" />
|
||||
<script type="text/javascript" src="{{ MEDIA_URL }}js/calendar.js"></script>
|
||||
<style type="text/css">
|
||||
#id_subject {
|
||||
width: 250px;
|
||||
|
||||
@@ -109,8 +109,6 @@ class Grapher(object):
|
||||
|
||||
if not os.path.exists(path):
|
||||
print "[graph] Impossible to create %s graph" %path
|
||||
else:
|
||||
print "[graph] %s graph created" %path
|
||||
|
||||
def make_defaults(self, target, tpl=traffic_avg_template):
|
||||
end = "%d" % int(time.mktime(time.localtime()))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% load i18n %}
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/calendar.css" />
|
||||
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/calendar.css" />
|
||||
<style type="text/css">
|
||||
#selectors {
|
||||
}
|
||||
@@ -76,7 +76,7 @@ window.addEvent("domready", function() {
|
||||
$("customsend").addEvent("click", get_graph);
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript" src="/static/js/calendar.js"></script>
|
||||
<script type="text/javascript" src="{{ MEDIA_URL }}js/calendar.js"></script>
|
||||
|
||||
<div id="selectors">
|
||||
{% if admin %}
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
{% endif %}
|
||||
{% for elems in graphs %}
|
||||
<h3>{{ elems.label }}</h3>
|
||||
<p><img src="/static/stats/{{ elems.name }}_{{ domain }}_AVERAGE_{% ifequal period 'custom' %}{{ period_name }}{% else %}{{ period }}{% endifequal %}.png"
|
||||
<p><img src="{{ MEDIA_URL }}stats/{{ elems.name }}_{{ domain }}_AVERAGE_{% ifequal period 'custom' %}{{ period_name }}{% else %}{{ period }}{% endifequal %}.png"
|
||||
alt="{% trans 'No statistics available' %}" /></p>
|
||||
{% endfor %}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import sys, os
|
||||
reload(sys)
|
||||
sys.setdefaultencoding("utf-8")
|
||||
|
||||
@@ -11,7 +11,9 @@ import ssl
|
||||
from datetime import datetime, timedelta
|
||||
from email.header import decode_header
|
||||
import email.utils
|
||||
import lxml
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.conf import settings
|
||||
from modoboa.lib import decode, tables, imap_utf7, Singleton
|
||||
from modoboa.lib.email_listing import MBconnector, EmailListing, Email
|
||||
from modoboa.lib import tables, imap_utf7, parameters
|
||||
@@ -458,6 +460,39 @@ class ImapEmail(Email):
|
||||
"attachments" : attachments != [] and attachments or None
|
||||
})
|
||||
|
||||
def find_images_in_body(body):
|
||||
"""Looks for images inside a HTML body
|
||||
|
||||
Before sending a message in HTML format, it is necessary to find
|
||||
all img tags contained in the body in order to rewrite them. For
|
||||
example, icons provided by tinyMCE are stored on the server
|
||||
filesystem and not accessible from the outside. We must embark
|
||||
them as parts off the MIME message if we want recipients to
|
||||
display them correctly.
|
||||
|
||||
:param body: the HTML body to parse
|
||||
"""
|
||||
from email.mime.image import MIMEImage
|
||||
html = lxml.html.fromstring(body)
|
||||
parts = []
|
||||
for tag in html.iter("img"):
|
||||
src = tag.get("src")
|
||||
fname = os.path.basename(src)
|
||||
cid = "%s@modoboa" % os.path.splitext(fname)[0]
|
||||
tag.set("src", "cid:%s" % cid)
|
||||
|
||||
path = "%s/%s" % (settings.MODOBOA_DIR, re.sub("\.\./", "", src))
|
||||
fp = open(path, "rb")
|
||||
p = MIMEImage(fp.read())
|
||||
fp.close()
|
||||
p["Content-ID"] = "<%s>" % cid
|
||||
ct = p["Content-Type"]
|
||||
p.replace_header("Content-Type", '%s; name="%s"' % (ct, fname))
|
||||
parts.append(p)
|
||||
|
||||
return lxml.html.tostring(html), parts
|
||||
|
||||
|
||||
def encrypt(clear):
|
||||
from Crypto.Cipher import AES
|
||||
import base64
|
||||
|
||||
@@ -40,6 +40,9 @@ def init():
|
||||
help=_("Folder where copies of sent messages go"))
|
||||
parameters.register_user("webmail", "SIGNATURE", type="text", default="",
|
||||
help=_("User defined email signature"))
|
||||
parameters.register_user("webmail", "EDITOR", type="list", deflt="text",
|
||||
values=[("html", "html"), ("plain", "text")],
|
||||
help=_("The default editor to use when composing a message"))
|
||||
|
||||
def destroy():
|
||||
events.unregister("UserMenuDisplay", menu)
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
{% include "common/genericform.html" %}
|
||||
</div>
|
||||
{% if body %}
|
||||
<textarea id="id_body" name="id_body">{% if bodyheader %}{{ bodyheader }}{% endif %}
|
||||
<textarea id="id_body" name="id_body" class="editor">{% if bodyheader %}{{ bodyheader }}{% endif %}
|
||||
{{ body }}
|
||||
</textarea>
|
||||
{% else %}
|
||||
<textarea id="id_body" name="id_body"></textarea>
|
||||
<textarea id="id_body" name="id_body" class="editor"></textarea>
|
||||
{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends "common/email_listing.html" %}
|
||||
{% load i18n %}
|
||||
{% block css %}
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/webmail.css" />
|
||||
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}/css/webmail.css" />
|
||||
{% endblock %}
|
||||
{% block js %}
|
||||
quota_pb = new ProgressBar({
|
||||
@@ -86,8 +86,14 @@
|
||||
current_anchor.update();
|
||||
}
|
||||
});
|
||||
tinyMCE.triggerSave();
|
||||
$("composemail").send();
|
||||
});
|
||||
if (resp.editor == "html") {
|
||||
new Request({url: "{% url tinymce-js 'common' %}",
|
||||
onSuccess: function(resp) { eval(resp); }
|
||||
}).get();
|
||||
}
|
||||
window.fireEvent("resize");
|
||||
}
|
||||
|
||||
|
||||
@@ -211,12 +211,14 @@ def render_compose(request, form, posturl, bodyheader=None, body=None,
|
||||
insert_signature=False):
|
||||
menu = compose_menu("", __get_current_url(request),
|
||||
request.user.get_all_permissions())
|
||||
editor = parameters.get_user(request.user, "webmail", "EDITOR")
|
||||
if insert_signature:
|
||||
if body == None:
|
||||
body = ""
|
||||
signature = parameters.get_user(request.user, "webmail", "SIGNATURE")
|
||||
if signature != "":
|
||||
body += "\n---\n%s" % signature
|
||||
body += editor == "plain" and "\n---\n%s" % signature \
|
||||
or "<br/>---<br/>%s" % re.sub("\n", "<br/>", signature)
|
||||
|
||||
content = render_to_string("webmail/compose.html", {
|
||||
"form" : form, "bodyheader" : bodyheader, "body" : body,
|
||||
@@ -225,7 +227,8 @@ def render_compose(request, form, posturl, bodyheader=None, body=None,
|
||||
mbc = IMAPconnector(user=request.user.username,
|
||||
password=request.session["password"])
|
||||
ctx = getctx("ok", level=2, menu=menu, listing=content,
|
||||
folders=__render_folders(mbc, request))
|
||||
folders=__render_folders(mbc, request),
|
||||
editor=editor)
|
||||
return HttpResponse(simplejson.dumps(ctx), mimetype="application/json")
|
||||
|
||||
def send_mail(request, withctx=False, origmsg=None, posturl=None):
|
||||
@@ -237,8 +240,19 @@ def send_mail(request, withctx=False, origmsg=None, posturl=None):
|
||||
from email.utils import make_msgid, formatdate
|
||||
import smtplib
|
||||
|
||||
msg = MIMEText(request.POST["id_body"].encode("utf-8"),
|
||||
_charset="utf-8")
|
||||
subtype = parameters.get_user(request.user, "webmail", "EDITOR")
|
||||
body = request.POST["id_body"]
|
||||
if subtype == "html":
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
msg = MIMEMultipart(_subtype="related")
|
||||
body, images = find_images_in_body(body)
|
||||
msg.attach(MIMEText(body.encode("utf-8"), _subtype=subtype,
|
||||
_charset="utf-8"))
|
||||
for img in images:
|
||||
msg.attach(img)
|
||||
else:
|
||||
msg = MIMEText(body.encode("utf-8"), _subtype=subtype)
|
||||
|
||||
msg["Subject"] = request.POST["subject"]
|
||||
msg["From"] = request.POST["from_"]
|
||||
msg["To"] = request.POST["to"]
|
||||
|
||||
Reference in New Issue
Block a user