diff --git a/odoo/addons/base/tests/test_mail.py b/odoo/addons/base/tests/test_mail.py index eb20b0b633918..71a92c23ddcb2 100644 --- a/odoo/addons/base/tests/test_mail.py +++ b/odoo/addons/base/tests/test_mail.py @@ -409,11 +409,11 @@ def test_email_from_rewrite(self): set_param('mail.catchall.domain', 'odoo.example.com') email_from, return_path = get_email_from('admin@test.example.com') - self.assertEqual(email_from, '"admin@test.example.com" ') + self.assertEqual(email_from, 'admin ') self.assertEqual(return_path, 'email_force@domain.com') email_from, return_path = get_email_from('"Admin" ') - self.assertEqual(email_from, '"Admin (admin@test.example.com)" ') + self.assertEqual(email_from, 'Admin ') self.assertEqual(return_path, 'email_force@domain.com') # We always force the email FROM (notification email contains a name part) @@ -422,7 +422,7 @@ def test_email_from_rewrite(self): set_param('mail.catchall.domain', 'odoo.example.com') email_from, return_path = get_email_from('"Admin" ') - self.assertEqual(email_from, '"Admin (admin@test.example.com)" ', + self.assertEqual(email_from, 'Admin ', msg='Should drop the name part of the forced email') self.assertEqual(return_path, 'email_force@domain.com') @@ -432,7 +432,7 @@ def test_email_from_rewrite(self): set_param('mail.catchall.domain', 'odoo.example.com') email_from, return_path = get_email_from('"Admin" ') - self.assertEqual(email_from, '"Admin (admin@test.example.com)" ', + self.assertEqual(email_from, 'Admin ', msg='Domain is not the same as the catchall domain, we should force the email FROM') self.assertEqual(return_path, 'notification@odoo.example.com') @@ -447,7 +447,7 @@ def test_email_from_rewrite(self): set_param('mail.catchall.domain', 'odoo.example.com') email_from, return_path = get_email_from('"Admin" ') - self.assertEqual(email_from, '"Admin (admin@test.example.com)" ', + self.assertEqual(email_from, 'Admin ', msg='Domain is not the same as the catchall domain, we should force the email FROM') self.assertEqual(return_path, 'notification@odoo.example.com') diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index 93d330c77bf1c..69be2b3f894bb 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -594,7 +594,7 @@ def encapsulate_email(old_email, new_email): e.g. * Old From: "Admin" * New From: notifications@odoo.com - * Output: "Admin (admin@gmail.com)" + * Output: "Admin" """ old_email_split = getaddresses([old_email]) if not old_email_split or not old_email_split[0]: @@ -604,10 +604,11 @@ def encapsulate_email(old_email, new_email): if not new_email_split or not new_email_split[0]: return - if old_email_split[0][0]: - name_part = '%s (%s)' % old_email_split[0] + old_name, old_email = old_email_split[0] + if old_name: + name_part = old_name else: - name_part = old_email_split[0][1] + name_part = old_email.split("@")[0] return formataddr(( name_part,