[FIX] {test_}mail: set bounced alias in bounce autoreply
Before this commit When someone tries to send a mail to a restricted alias (which can be anywhere in 'To', 'CC' or 'BCC') and if the sender is not allowed to do so, the mail bounces. However bounced mail shows info as if it bounced due to address provided in 'To', even though it is not always the case. Example you send a message to * 'To': 'valid@gmail.com' (okay) * 'Cc': 'myalias@odoo.com' (not allowed for you) Mail bounces because you are not allowed to send a mail to alias provided in 'Cc', but it shows the message that: `The following email sent to valid@gmail.com cannot be accepted because [...]`. After this commit Boucing alias is shown in message body. Above example becomes `The following email sent to myalias@odoo.com cannot be accepted [...].` Note: Because the alias can be present in `Bcc` too (which will not available in the message values we get in `message_route_verify` method), we simply use display name of the alias instead of finding mail address matching with alias from the message values. Task ID-2390310 closes odoo/odoo#69788 X-original-commit: 15325b19c15a649041db75bacbe8409ae4c58df7 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
committed by
Thibault Delavallée
parent
8f56f1ead0
commit
ebc49bc143
@@ -228,7 +228,7 @@ class Alias(models.Model):
|
||||
def _get_alias_bounced_body_fallback(self, message_dict):
|
||||
return _("""Hi,<br/>
|
||||
The following email sent to %s cannot be accepted because this is a private email address.
|
||||
Only allowed people can contact us at this address.""", message_dict.get('to'))
|
||||
Only allowed people can contact us at this address.""", self.display_name)
|
||||
|
||||
def _get_alias_bounced_body(self, message_dict):
|
||||
"""Get the body of the email return in case of bounced email.
|
||||
|
||||
@@ -397,6 +397,33 @@ class TestMailgateway(TestMailCommon):
|
||||
# Check if default (hardcoded) value is in the mail content
|
||||
self.assertSentEmail('"MAILER-DAEMON" <bounce.test@test.com>', ['whatever-2a840@postmaster.twitter.com'], body_content='The following email sent to')
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
|
||||
def test_message_process_alias_config_bounced_to(self):
|
||||
""" Check bounce message contains the bouncing alias, not a generic "to" """
|
||||
self.alias.write({'alias_contact': 'partners'})
|
||||
bounce_message_with_alias = "The following email sent to %s cannot be accepted because this is a private email address." % self.alias.display_name.lower()
|
||||
|
||||
# Bounce is To
|
||||
with self.mock_mail_gateway():
|
||||
self.format_and_process(
|
||||
MAIL_TEMPLATE, self.email_from, 'groups@example.com',
|
||||
cc='other@gmail.com', subject='Should Bounce')
|
||||
self.assertIn(bounce_message_with_alias, self._mails[0].get('body'))
|
||||
|
||||
# Bounce is CC
|
||||
with self.mock_mail_gateway():
|
||||
self.format_and_process(
|
||||
MAIL_TEMPLATE, self.email_from, 'other@gmail.com',
|
||||
cc='groups@example.com', subject='Should Bounce')
|
||||
self.assertIn(bounce_message_with_alias, self._mails[0].get('body'))
|
||||
|
||||
# Bounce is part of To
|
||||
with self.mock_mail_gateway():
|
||||
self.format_and_process(
|
||||
MAIL_TEMPLATE, self.email_from, 'other@gmail.com, groups@example.com',
|
||||
subject='Should Bounce')
|
||||
self.assertIn(bounce_message_with_alias, self._mails[0].get('body'))
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.models')
|
||||
def test_message_process_alias_defaults(self):
|
||||
""" Test alias defaults and inner values """
|
||||
|
||||
Reference in New Issue
Block a user