diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py
index 9adab6d3976..d540971c3b4 100644
--- a/addons/email_template/email_template.py
+++ b/addons/email_template/email_template.py
@@ -28,6 +28,8 @@ from osv import osv
from osv import fields
import tools
from tools.translate import _
+from tools.html_sanitize import html_sanitize
+from tools import html2plaintext
from urllib import quote as quote
_logger = logging.getLogger(__name__)
@@ -134,7 +136,7 @@ class email_template(osv.osv):
"This is useful for CRM leads for example"),
# Overridden mail.message.common fields for technical reasons:
- 'model': fields.related('model_id','model', type='char', string='Related Document Model',
+ 'model': fields.related('model_id', 'model', type='char', string='Related Document Model',
size=128, select=True, store=True, readonly=True),
# we need a separate m2m table to avoid ID collisions with the original mail.message entries
#'attachment_ids': fields.many2many('ir.attachment', 'email_template_attachment_rel', 'email_template_id',
@@ -143,7 +145,7 @@ class email_template(osv.osv):
# "emails created from this template"),
# Overridden mail.message.common fields to make tooltips more appropriate:
- #'subject':fields.char('Subject', size=512, translate=True, help="Subject (placeholders may be used here)",),
+ 'subject': fields.char('Subject', translate=True, help="Subject (placeholders may be used here)",),
'email_from': fields.char('From', size=128, help="Sender address (placeholders may be used here)"),
'email_to': fields.char('To', size=256, help="Comma-separated recipient addresses (placeholders may be used here)"),
'email_cc': fields.char('Cc', size=256, help="Carbon copy recipients (placeholders may be used here)"),
@@ -151,13 +153,7 @@ class email_template(osv.osv):
'mail_server_id': fields.many2one('ir.mail_server', 'Outgoing Mail Server', readonly=False,
help="Optional preferred server for outgoing mails. If not set, the highest "
"priority one will be used."),
- #'body': fields.text('Text Contents', translate=True, help="Plaintext version of the message (placeholders may be used here)"),
'body_html': fields.text('Rich-text Contents', translate=True, help="Rich-text/HTML version of the message (placeholders may be used here)"),
- #'message_id': fields.char('Message-Id', size=256, help="Message-ID SMTP header to use in outgoing messages based on this template. "
- # "Please note that this overrides the 'Resource Tracking' option, "
- # "so if you simply need to track replies to outgoing emails, enable "
- # "that option instead.\n"
- # "Placeholders must be used here, as this value always needs to be unique!"),
# Fake fields used to implement the placeholder assistant
'model_object_field': fields.many2one('ir.model.fields', string="Field",
@@ -300,7 +296,6 @@ class email_template(osv.osv):
context = {}
values = {
'subject': False,
- 'body': False,
'body_html': False,
'email_from': False,
'email_to': False,
@@ -314,7 +309,6 @@ class email_template(osv.osv):
'attachment_ids': False,
'message_id': False,
'state': 'outgoing',
- 'content_subtype': 'plain',
}
if not template_id:
return values
@@ -322,15 +316,15 @@ class email_template(osv.osv):
report_xml_pool = self.pool.get('ir.actions.report.xml')
template = self.get_email_template(cr, uid, template_id, res_id, context)
- for field in ['subject', 'body', 'body_html', 'email_from',
- 'email_to', 'email_cc', 'reply_to',
- 'message_id']:
+ for field in ['subject', 'body_html', 'email_from',
+ 'email_to', 'email_cc', 'reply_to']:
values[field] = self.render_template(cr, uid, getattr(template, field),
template.model, res_id, context=context) \
or False
if values['body_html']:
- values.update(content_subtype='html')
+ values['body'] = html_sanitize(values['body_html'])
+ values['body_text'] = html2plaintext(values['body_html'])
if template.user_signature:
signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature
diff --git a/addons/email_template/email_template_view.xml b/addons/email_template/email_template_view.xml
index a03bd3351ed..cd75a719197 100644
--- a/addons/email_template/email_template_view.xml
+++ b/addons/email_template/email_template_view.xml
@@ -22,10 +22,7 @@
-
-
-
-
+
diff --git a/addons/email_template/wizard/mail_compose_message.py b/addons/email_template/wizard/mail_compose_message.py
index 7dbb47e8380..11e726c537b 100644
--- a/addons/email_template/wizard/mail_compose_message.py
+++ b/addons/email_template/wizard/mail_compose_message.py
@@ -95,17 +95,21 @@ class mail_compose_message(osv.osv_memory):
else: # restore defaults
values = self.default_get(cr, uid, fields, context=context)
- if values.get('body_html') is not None:
+ if values.get('body_html') and not values.get('body'):
values['body'] = values.get('body_html')
+
values.update(use_template=use_template, template_id=template_id)
+ print 'returning ', values
+
return {'value': values}
def toggle_template(self, cr, uid, ids, context=None):
""" hit toggle template mode button: calls onchange_use_template to
emulate an on_change, then writes the value to update the form. """
for record in self.browse(cr, uid, ids, context=context):
- onchange_res = self.onchange_use_template(cr, uid, ids, not record.use_template, context=context)['value']
+ onchange_res = self.onchange_use_template(cr, uid, ids, not record.use_template,
+ record.template_id, record.composition_mode, record.res_id, context=context)['value']
record.write(onchange_res)
return True
diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py
index f128662aac1..7f3a8a880ea 100644
--- a/addons/mail/mail_mail.py
+++ b/addons/mail/mail_mail.py
@@ -54,10 +54,10 @@ class mail_mail(osv.Model):
'auto_delete': fields.boolean('Auto Delete',
help="Permanently delete this email after sending it, to save space"),
'references': fields.text('References', help='Message references, such as identifiers of previous messages', readonly=1),
- 'email_from': fields.char('From', size=128, help='Message sender, taken from user preferences.'),
+ 'email_from': fields.char('From', help='Message sender, taken from user preferences.'),
'email_to': fields.text('To', help='Message recipients'),
- 'email_cc': fields.char('Cc', size=256, help='Carbon copy message recipients'),
- 'reply_to':fields.char('Reply-To', size=256, help='Preferred response address for the message'),
+ 'email_cc': fields.char('Cc', help='Carbon copy message recipients'),
+ 'reply_to':fields.char('Reply-To', help='Preferred response address for the message'),
'body_html': fields.text('Rich-text Contents', help="Rich-text/HTML message"),
}
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py
index ae597b509ee..e5748a723e6 100644
--- a/addons/mail/wizard/mail_compose_message.py
+++ b/addons/mail/wizard/mail_compose_message.py
@@ -75,11 +75,11 @@ class mail_compose_message(osv.TransientModel):
active_ids = context.get('active_ids')
# get default values according to the composition mode
- if composition_mode in ['reply']:
+ if composition_mode == 'reply':
vals = self.get_message_data(cr, uid, active_id, context=context)
- elif composition_mode in ['comment'] and model and res_id:
+ elif composition_mode == 'comment' and model and res_id:
vals = self.get_record_data(cr, uid, model, res_id, context=context)
- elif composition_mode in ['mass_mail'] and model and active_ids:
+ elif composition_mode == 'mass_mail' and model and active_ids:
vals = {'model': model, 'res_id': res_id, 'content_subtype': 'html'}
else:
vals = {'model': model, 'res_id': res_id}