diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 60acd6b7416..54fb13ad08f 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -22,6 +22,7 @@ from email import message_from_string, policy from lxml import etree from werkzeug import urls from xmlrpc import client as xmlrpclib +from markupsafe import Markup from odoo import _, api, exceptions, fields, models, tools, registry, SUPERUSER_ID, Command from odoo.exceptions import MissingError @@ -2400,8 +2401,8 @@ class MailThread(models.AbstractModel): author_user = self.env.user if self.env.user.partner_id == author else author.user_ids[0] if author and author.user_ids else False if author_user: signature = author_user.signature - else: - signature = "

--
%s

" % author.name + elif author.name: + signature = Markup("

--
%s

") % author.name if force_email_company: company = force_email_company diff --git a/addons/test_mail/tests/test_message_post.py b/addons/test_mail/tests/test_message_post.py index 98a25c61c95..71352d2d5da 100644 --- a/addons/test_mail/tests/test_message_post.py +++ b/addons/test_mail/tests/test_message_post.py @@ -15,6 +15,8 @@ from odoo.tests import tagged from odoo.tools import mute_logger, formataddr from odoo.tests.common import users +from markupsafe import escape + @tagged('mail_post') class TestMessagePost(TestMailCommon, TestRecipients): @@ -108,6 +110,18 @@ class TestMessagePost(TestMailCommon, TestRecipients): self.assertNotIn(signature, found_mail.body_html) self.assertEqual(found_mail.body_html.count(signature), 0) + @users('employee') + def test_notify_by_email_add_signature_no_author_user_or_no_user(self): + self.test_message.author_id = self.env['res.partner'].sudo().create({ + 'name': 'Steve', + }).id + template_values = self.test_record._notify_by_email_prepare_rendering_context(self.test_message, {}) + self.assertNotEqual(escape(template_values['signature']), escape('

--
Steve

')) + + self.test_message.author_id = None + template_values = self.test_record._notify_by_email_prepare_rendering_context(self.test_message, {}) + self.assertEqual(template_values['signature'], '') + @users('employee') def test_notify_by_email_prepare_rendering_contextt(self): """ Verify that the template context company value is right