[mail] Ajout du markup html qui du coup ne met pas de partie plain text dans le mail

This commit is contained in:
Valentin Samir 2014-11-08 16:09:52 +01:00
parent ddc3820cd6
commit 8451e193f6
2 changed files with 10 additions and 6 deletions

View file

@ -21,7 +21,7 @@ if '/usr/scripts' not in sys.path:
from gestion import secrets_new as secrets
default_language = 'fr'
template_path = os.path.join(os.path.dirname(__file__), 'template') + '/'
template_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'template') + '/'
html_template = template_path + 'html'
html_mutilang_template = template_path + 'html_multilang'
text_mutilang_template = template_path + 'text_multilang'
@ -47,6 +47,7 @@ templateEnv.filters['name'] = given_name
# file extension to rendering function map
markup = {
'md' : markdown,
'html' : lambda x:x,
}
### For an example:
@ -80,6 +81,7 @@ def gen_local_body(fname, params, lang):
return templateEnv.get_template(fname).render(params)
def body(mail, lang1, lang2, mk, params, charset):
ret = []
file1 = template_path + mail + '/body/' + lang1
file2 = template_path + mail + '/body/' + lang2
if mk:
@ -87,17 +89,19 @@ def body(mail, lang1, lang2, mk, params, charset):
file2 = file2 + '.' + mk
if lang1 == lang2 or not os.path.isfile(file2): # No alt language
txt = gen_local_body(file1, params, lang1)
ret = [ submessage(txt.encode(charset), 'plain', charset) ]
if mk != "html":
ret.append(submessage(txt.encode(charset), 'plain', charset))
if mk: # compute the html version
html = templateEnv.get_template(html_template).render({'body': markup[mk](txt)})
ret.append(submessage(html.encode(charset), 'html', charset))
else:
txt1 = gen_local_body(file1, params, lang1)
txt2 = gen_local_body(file2, params, lang2)
params_txt=dict(params)
params_txt.update({'body1': txt1, 'body2':txt2})
txt = templateEnv.get_template(text_mutilang_template).render(params_txt)
ret=[ submessage(txt.encode(charset), 'plain', charset) ]
if mk != "html":
params_txt=dict(params)
params_txt.update({'body1': txt1, 'body2':txt2})
txt = templateEnv.get_template(text_mutilang_template).render(params_txt)
ret.append(submessage(txt.encode(charset), 'plain', charset))
if mk: # compute the html version
params_html=dict(params)
params_html.update({'lang1':lang1, 'lang2':lang2, 'body1': markup[mk](txt1), 'body2': markup[mk](txt2)})