From ef2263ad6a66a9a7f1d4fb46f94b21ac402f95cf Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Thu, 17 Apr 2014 20:18:10 +0200 Subject: [PATCH] CKeditor compatibility. see #547 --- modoboa/extensions/webmail/lib.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modoboa/extensions/webmail/lib.py b/modoboa/extensions/webmail/lib.py index 5770086d0..18f9c67d5 100644 --- a/modoboa/extensions/webmail/lib.py +++ b/modoboa/extensions/webmail/lib.py @@ -598,6 +598,8 @@ def html2plaintext(content): :param content: some HTML content """ + if not content: + return "" html = lxml.html.fromstring(content) plaintext = "" for ch in html.iter(): @@ -662,10 +664,14 @@ def send_mail(request, posturl=None): if editormode == "html": msg = MIMEMultipart(_subtype="related") submsg = MIMEMultipart(_subtype="alternative") - textbody = html2plaintext(body) + if body: + textbody = html2plaintext(body) + body, images = find_images_in_body(body) + else: + textbody = "" + images = [] submsg.attach(MIMEText(textbody.encode(charset), _subtype="plain", _charset=charset)) - body, images = find_images_in_body(body) submsg.attach(MIMEText(body.encode(charset), _subtype=editormode, _charset=charset)) msg.attach(submsg)