diff --git a/addons/mail_plugin/controllers/mail_plugin.py b/addons/mail_plugin/controllers/mail_plugin.py index dadb3cf495f..ecc88f6bf5d 100644 --- a/addons/mail_plugin/controllers/mail_plugin.py +++ b/addons/mail_plugin/controllers/mail_plugin.py @@ -153,6 +153,18 @@ class MailPluginController(http.Controller): if not normalized_email: return {'error': _('Bad Email.')} + notification_emails = request.env['mail.alias.domain'].sudo().search([]).mapped('default_from_email') + if normalized_email in notification_emails: + return { + 'partner': { + 'name': _('Notification'), + 'email': normalized_email, + 'enrichment_info': { + 'type': 'odoo_custom_error', 'info': _('This is your notification address. Search the Contact manually to link this email to a record.'), + }, + }, + } + # Search for the partner based on the email. # If multiple are found, take the first one. partner = request.env['res.partner'].search(['|', ('email', 'in', [normalized_email, email]), @@ -215,6 +227,9 @@ class MailPluginController(http.Controller): params name: name of the new partner params company: parent company id of the new partner """ + notification_emails = request.env['mail.alias.domain'].sudo().search([]).mapped('default_from_email') + if tools.email_normalize(email) in notification_emails: + raise Forbidden() # old route name "/mail_client_extension/partner/create is deprecated as of saas-14.3,it is not needed for newer # versions of the mail plugin but necessary for supporting older versions # TODO search the company again instead of relying on the one provided here? diff --git a/addons/mail_plugin/i18n/mail_plugin.pot b/addons/mail_plugin/i18n/mail_plugin.pot index 6530a084227..19a018bec9c 100644 --- a/addons/mail_plugin/i18n/mail_plugin.pot +++ b/addons/mail_plugin/i18n/mail_plugin.pot @@ -544,6 +544,13 @@ msgstr "" msgid "Not enough credits to enrich." msgstr "" +#. module: mail_plugin +#. odoo-python +#: code:addons/mail_plugin/controllers/mail_plugin.py:0 +#, python-format +msgid "Notification" +msgstr "" + #. module: mail_plugin #. odoo-javascript #: code:addons/mail_plugin/static/src/to_translate/translations_gmail.xml:0 @@ -737,6 +744,13 @@ msgstr "" msgid "This contact has no email address, no company could be enriched." msgstr "" +#. module: mail_plugin +#. odoo-python +#: code:addons/mail_plugin/controllers/mail_plugin.py:0 +#, python-format +msgid "This is your notification address. Search the Contact manually to link this email to a record." +msgstr "" + #. module: mail_plugin #. odoo-python #: code:addons/mail_plugin/controllers/mail_plugin.py:0 diff --git a/addons/mail_plugin/tests/test_controller.py b/addons/mail_plugin/tests/test_controller.py index 8afbb9541b4..5a23750156b 100644 --- a/addons/mail_plugin/tests/test_controller.py +++ b/addons/mail_plugin/tests/test_controller.py @@ -187,3 +187,22 @@ class TestMailPluginController(TestMailPluginControllerCommon): ) second_company_id = result["partner"]["company"]["id"] self.assertEqual(first_company_id, second_company_id, "Should not create a new company") + + def test_get_partner_is_default_from(self): + """When the email_from is the server default from address, we return a custom message instead of trying to match a partner record.""" + self.env['mail.alias.domain'].create({'name': 'example.com', 'default_from': 'notification'}) + mock_iap_enrich = Mock() + result = self.mock_plugin_partner_get("Test partner", "notificaTION@EXAMPLE.COM", mock_iap_enrich) + self.assertEqual( + result, + { + 'partner': { + 'name': 'Notification', + 'email': 'notification@example.com', + 'enrichment_info': { + 'type': 'odoo_custom_error', + 'info': 'This is your notification address. Search the Contact manually to link this email to a record.', + }, + }, + }, + )