Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] tools.mail: ignore original email during encapsulation #79979

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 9 additions & 7 deletions odoo/addons/base/tests/test_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,14 @@ def test_email_from_rewrite(self):
set_param('mail.dynamic.smtp.from', False)
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" <email_force@domain.com>')
# name + email -> encapsulated with name only
email_from, return_path = get_email_from('"Admin" <admin@test.example.com>')
self.assertEqual(email_from, '"Admin" <email_force@domain.com>')
self.assertEqual(return_path, 'email_force@domain.com')

email_from, return_path = get_email_from('"Admin" <admin@test.example.com>')
self.assertEqual(email_from, '"Admin (admin@test.example.com)" <email_force@domain.com>')
# no-name + email -> encapsulated with local part of email only
email_from, return_path = get_email_from('admin@test.example.com')
self.assertEqual(email_from, '"admin" <email_force@domain.com>')
self.assertEqual(return_path, 'email_force@domain.com')

# We always force the email FROM (notification email contains a name part)
Expand All @@ -483,7 +485,7 @@ def test_email_from_rewrite(self):
set_param('mail.catchall.domain', 'odoo.example.com')

email_from, return_path = get_email_from('"Admin" <admin@test.example.com>')
self.assertEqual(email_from, '"Admin (admin@test.example.com)" <email_force@domain.com>',
self.assertEqual(email_from, '"Admin" <email_force@domain.com>',
msg='Should drop the name part of the forced email')
self.assertEqual(return_path, 'email_force@domain.com')

Expand All @@ -493,7 +495,7 @@ def test_email_from_rewrite(self):
set_param('mail.catchall.domain', 'odoo.example.com')

email_from, return_path = get_email_from('"Admin" <admin@test.example.com>')
self.assertEqual(email_from, '"Admin (admin@test.example.com)" <notification@odoo.example.com>',
self.assertEqual(email_from, '"Admin" <notification@odoo.example.com>',
msg='Domain is not the same as the catchall domain, we should force the email FROM')
self.assertEqual(return_path, 'notification@odoo.example.com')

Expand All @@ -508,7 +510,7 @@ def test_email_from_rewrite(self):
set_param('mail.catchall.domain', 'odoo.example.com')

email_from, return_path = get_email_from('"Admin" <admin@test.example.com>')
self.assertEqual(email_from, '"Admin (admin@test.example.com)" <notification@odoo.example.com>',
self.assertEqual(email_from, '"Admin" <notification@odoo.example.com>',
msg='Domain is not the same as the catchall domain, we should force the email FROM')
self.assertEqual(return_path, 'notification@odoo.example.com')

Expand Down
9 changes: 5 additions & 4 deletions odoo/tools/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ def encapsulate_email(old_email, new_email):
e.g.
* Old From: "Admin" <admin@gmail.com>
* New From: notifications@odoo.com
* Output: "Admin (admin@gmail.com)" <notifications@odoo.com>
* Output: "Admin" <notifications@odoo.com>
"""
old_email_split = getaddresses([old_email])
if not old_email_split or not old_email_split[0]:
Expand All @@ -631,10 +631,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,
Expand Down