[REM] base: revert the rewriting of the FROM of the emails sent

Purpose
=======
Revert the commit a757cab857
because the rewriting of the FROM of the emails sent will
be done in a smarter way in master.

Task-2367946
odoo/odoo#61853
odoo/upgrade#1903
This commit is contained in:
std-odoo
2021-08-13 12:26:16 +00:00
committed by Thibault Delavallée
parent 347111c7b8
commit 10a1466cd5
2 changed files with 0 additions and 104 deletions
-34
View File
@@ -305,12 +305,7 @@ class IrMailServer(models.Model):
if references:
msg['references'] = references
msg['Subject'] = subject
email_from, return_path = self._get_email_from(email_from)
msg['From'] = email_from
if return_path:
headers.setdefault('Return-Path', return_path)
del msg['Reply-To']
msg['Reply-To'] = reply_to or email_from
msg['To'] = email_to
@@ -338,35 +333,6 @@ class IrMailServer(models.Model):
msg.add_attachment(fcontent, maintype, subtype, filename=fname)
return msg
def _get_email_from(self, email_from):
"""Logic which determines which email to use when sending the email.
- If the system parameter `mail.force.smtp.from` is set we encapsulate all
outgoing email from
- If the previous system parameter is not set and if both `mail.dynamic.smtp.from`
and `mail.catchall.domain` are set, we encapsulate the FROM only if the domain
of the email is not the same as the domain of the catchall parameter
- Otherwise we do not encapsulate the email and given email_from is used as is
:param email_from: The initial FROM headers
:return: The FROM to used in the headers and optionally the Return-Path
"""
force_smtp_from = self.env['ir.config_parameter'].sudo().get_param('mail.force.smtp.from')
dynamic_smtp_from = self.env['ir.config_parameter'].sudo().get_param('mail.dynamic.smtp.from')
catchall_domain = self.env['ir.config_parameter'].sudo().get_param('mail.catchall.domain')
if force_smtp_from:
rfc2822_force_smtp_from = extract_rfc2822_addresses(force_smtp_from)
rfc2822_force_smtp_from = rfc2822_force_smtp_from[0] if rfc2822_force_smtp_from else None
return encapsulate_email(email_from, force_smtp_from), rfc2822_force_smtp_from
elif dynamic_smtp_from and catchall_domain and email_domain_extract(email_from) != catchall_domain:
rfc2822_dynamic_smtp_from = extract_rfc2822_addresses(dynamic_smtp_from)
rfc2822_dynamic_smtp_from = rfc2822_dynamic_smtp_from[0] if rfc2822_dynamic_smtp_from else None
return encapsulate_email(email_from, dynamic_smtp_from), rfc2822_dynamic_smtp_from
return email_from, None
@api.model
def _get_default_bounce_address(self):
'''Compute the default bounce address.
-70
View File
@@ -457,76 +457,6 @@ class EmailConfigCase(TransactionCase):
)
self.assertEqual(message["From"], "settings@example.com")
def test_email_from_rewrite(self):
get_email_from = self.env['ir.mail_server']._get_email_from
set_param = self.env['ir.config_parameter'].set_param
# Standard case, no setting
set_param('mail.force.smtp.from', False)
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')
self.assertFalse(return_path)
email_from, return_path = get_email_from('"Admin" <admin@test.example.com>')
self.assertEqual(email_from, '"Admin" <admin@test.example.com>')
self.assertFalse(return_path)
# We always force the email FROM
set_param('mail.force.smtp.from', 'email_force@domain.com')
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>')
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>')
self.assertEqual(return_path, 'email_force@domain.com')
# We always force the email FROM (notification email contains a name part)
set_param('mail.force.smtp.from', '"Your notification bot" <email_force@domain.com>')
set_param('mail.dynamic.smtp.from', False)
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>',
msg='Should drop the name part of the forced email')
self.assertEqual(return_path, 'email_force@domain.com')
# We dynamically force the email FROM
set_param('mail.force.smtp.from', False)
set_param('mail.dynamic.smtp.from', 'notification@odoo.example.com')
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>',
msg='Domain is not the same as the catchall domain, we should force the email FROM')
self.assertEqual(return_path, 'notification@odoo.example.com')
email_from, return_path = get_email_from('"Admin" <admin@odoo.example.com>')
self.assertEqual(email_from, '"Admin" <admin@odoo.example.com>',
msg='Domain is the same as the catchall domain, we should not force the email FROM')
self.assertFalse(return_path)
# We dynamically force the email FROM (notification email contains a name part)
set_param('mail.force.smtp.from', False)
set_param('mail.dynamic.smtp.from', '"Your notification bot" <notification@odoo.example.com>')
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>',
msg='Domain is not the same as the catchall domain, we should force the email FROM')
self.assertEqual(return_path, 'notification@odoo.example.com')
email_from, return_path = get_email_from('"Admin" <admin@odoo.example.com>')
self.assertEqual(email_from, '"Admin" <admin@odoo.example.com>',
msg='Domain is the same as the catchall domain, we should not force the email FROM')
self.assertFalse(return_path)
class TestEmailMessage(TransactionCase):
def test_as_string(self):