diff --git a/mail_incoming_no_forward/README.rst b/mail_incoming_no_forward/README.rst new file mode 100644 index 000000000..e69de29bb diff --git a/mail_incoming_no_forward/__init__.py b/mail_incoming_no_forward/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mail_incoming_no_forward/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_incoming_no_forward/__manifest__.py b/mail_incoming_no_forward/__manifest__.py new file mode 100644 index 000000000..c7ff15e9f --- /dev/null +++ b/mail_incoming_no_forward/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2026 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Incoming Mail No Forward", + "summary": "Don't forward incoming mails to the followers", + "version": "18.0.1.0.0", + "author": "Camptocamp,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/mail", + "license": "AGPL-3", + "category": "Tools", + "depends": ["mail"], + "data": ["views/res_config_settings_views.xml"], +} diff --git a/mail_incoming_no_forward/models/__init__.py b/mail_incoming_no_forward/models/__init__.py new file mode 100644 index 000000000..f624e45b4 --- /dev/null +++ b/mail_incoming_no_forward/models/__init__.py @@ -0,0 +1,3 @@ +from . import mail_thread +from . import res_company +from . import res_config_settings diff --git a/mail_incoming_no_forward/models/mail_thread.py b/mail_incoming_no_forward/models/mail_thread.py new file mode 100644 index 000000000..3ecac8eb5 --- /dev/null +++ b/mail_incoming_no_forward/models/mail_thread.py @@ -0,0 +1,33 @@ +# Copyright 2026 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class MailThread(models.AbstractModel): + _inherit = "mail.thread" + + def _notify_get_recipients(self, message, msg_vals, **kwargs): + recipients = super()._notify_get_recipients(message, msg_vals, **kwargs) + message_type = ( + msg_vals.get("message_type") if msg_vals else message.sudo().message_type + ) + if message_type == "email" and self.env.company.disable_incoming_mail_forward: + recipients = self._filter_forward_recipients(recipients) + return recipients + + def _filter_forward_recipients(self, recipients): + """Don't forward incoming mails to external followers. + + The forward leaks replies meant for the company only + and is flagged as impersonation by some mail servers. + + Senders must decide who receives the message (e.g. "Reply all"). + """ + notify_internal = self.env.company.notify_internal_on_incoming_email + return [ + recipient + for recipient in recipients + if recipient["notif"] != "email" + or (notify_internal and not recipient["share"]) + ] diff --git a/mail_incoming_no_forward/models/res_company.py b/mail_incoming_no_forward/models/res_company.py new file mode 100644 index 000000000..8a9c94e83 --- /dev/null +++ b/mail_incoming_no_forward/models/res_company.py @@ -0,0 +1,19 @@ +# Copyright 2026 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + disable_incoming_mail_forward = fields.Boolean( + string="Don't forward incoming mails to followers", + default=True, + help="Odoo forwards incoming mails to all the followers by email.", + ) + notify_internal_on_incoming_email = fields.Boolean( + string="Email internal users about incoming mails", + default=True, + help="Forward incoming mails to internal followers notified by email.", + ) diff --git a/mail_incoming_no_forward/models/res_config_settings.py b/mail_incoming_no_forward/models/res_config_settings.py new file mode 100644 index 000000000..ba52c7ca9 --- /dev/null +++ b/mail_incoming_no_forward/models/res_config_settings.py @@ -0,0 +1,17 @@ +# Copyright 2026 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + disable_incoming_mail_forward = fields.Boolean( + related="company_id.disable_incoming_mail_forward", + readonly=False, + ) + notify_internal_on_incoming_email = fields.Boolean( + related="company_id.notify_internal_on_incoming_email", + readonly=False, + ) diff --git a/mail_incoming_no_forward/pyproject.toml b/mail_incoming_no_forward/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/mail_incoming_no_forward/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_incoming_no_forward/readme/CONFIGURE.md b/mail_incoming_no_forward/readme/CONFIGURE.md new file mode 100644 index 000000000..0eaf9e4e0 --- /dev/null +++ b/mail_incoming_no_forward/readme/CONFIGURE.md @@ -0,0 +1,7 @@ +Go to *Settings > General Settings > Discuss*: + +- *Don't forward incoming mails to followers*: enabled by default. + Disable it to get the standard Odoo behaviour back. +- *Email internal users about incoming mails*: only visible when the forward is + disabled. Enabled by default: internal followers notified by email keep + receiving the incoming mails. diff --git a/mail_incoming_no_forward/readme/CONTRIBUTORS.md b/mail_incoming_no_forward/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..0d7da55dd --- /dev/null +++ b/mail_incoming_no_forward/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Camptocamp](https://www.camptocamp.com): + - David Gallay diff --git a/mail_incoming_no_forward/readme/DESCRIPTION.md b/mail_incoming_no_forward/readme/DESCRIPTION.md new file mode 100644 index 000000000..41ae12c70 --- /dev/null +++ b/mail_incoming_no_forward/readme/DESCRIPTION.md @@ -0,0 +1,11 @@ +When Odoo receives a mail on a record, it forwards a copy to every follower of +the record, sent as ` `. + +This copy: + +- leaks replies meant for the company only to the other external followers; +- is flagged as impersonation by some mail servers (e.g. Microsoft Defender). + +This module stops forwarding incoming mails to the followers by email. +The mail is still logged in the chatter, and followers notified in their Odoo +inbox are still notified. diff --git a/mail_incoming_no_forward/static/description/icon.png b/mail_incoming_no_forward/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mail_incoming_no_forward/static/description/icon.png differ diff --git a/mail_incoming_no_forward/tests/__init__.py b/mail_incoming_no_forward/tests/__init__.py new file mode 100644 index 000000000..03fd3ae9a --- /dev/null +++ b/mail_incoming_no_forward/tests/__init__.py @@ -0,0 +1 @@ +from . import test_incoming_mail_notification diff --git a/mail_incoming_no_forward/tests/common.py b/mail_incoming_no_forward/tests/common.py new file mode 100644 index 000000000..52ac9c617 --- /dev/null +++ b/mail_incoming_no_forward/tests/common.py @@ -0,0 +1,10 @@ +# Copyright 2026 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tools import file_open + + +def read_eml(filename, mode="r"): + """Return the content of ``mail_incoming_no_forward/tests/eml/``.""" + with file_open(f"mail_incoming_no_forward/tests/eml/{filename}", mode) as eml: + return eml.read() diff --git a/mail_incoming_no_forward/tests/eml/reply.eml b/mail_incoming_no_forward/tests/eml/reply.eml new file mode 100644 index 000000000..606a655ee --- /dev/null +++ b/mail_incoming_no_forward/tests/eml/reply.eml @@ -0,0 +1,8 @@ +From: Sender +To: odoo@example.com +Subject: Re: Thread +Message-ID: {message_id} +In-Reply-To: {parent_id} +Content-Type: text/plain; charset=utf-8 + +Hello back diff --git a/mail_incoming_no_forward/tests/test_incoming_mail_notification.py b/mail_incoming_no_forward/tests/test_incoming_mail_notification.py new file mode 100644 index 000000000..7c995d2b2 --- /dev/null +++ b/mail_incoming_no_forward/tests/test_incoming_mail_notification.py @@ -0,0 +1,90 @@ +# Copyright 2026 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from email import message_from_string + +from odoo.tests.common import TransactionCase, new_test_user + +from .common import read_eml + +REPLY_TEMPLATE = read_eml("reply.eml") + + +class TestIncomingMailNotification(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + partner_model = cls.env["res.partner"] + cls.record = partner_model.create({"name": "Thread"}) + cls.sender = partner_model.create( + {"name": "Sender", "email": "sender@example.com"} + ) + cls.external = partner_model.create( + {"name": "External", "email": "external@example.com"} + ) + cls.internal_email = new_test_user( + cls.env, + login="internal_email", + email="internal_email@example.com", + groups="base.group_user", + notification_type="email", + ).partner_id + cls.internal_inbox = new_test_user( + cls.env, + login="internal_inbox", + groups="base.group_user", + notification_type="inbox", + ).partner_id + cls.record.message_subscribe( + partner_ids=( + cls.sender | cls.external | cls.internal_email | cls.internal_inbox + ).ids + ) + cls.parent = cls.record.message_post( + body="Hello", + message_type="comment", + subtype_xmlid="mail.mt_comment", + ) + + def _notified(self, message): + return { + notification.res_partner_id: notification.notification_type + for notification in message.notification_ids + } + + def _receive_reply(self): + message_id = f"<{self._testMethodName}@example.com>" + raw = REPLY_TEMPLATE.format( + message_id=message_id, parent_id=self.parent.message_id + ) + self.assertEqual( + message_from_string(raw)["In-Reply-To"], self.parent.message_id + ) + self.env["mail.thread"].message_process("res.partner", raw) + reply = self.env["mail.message"].search([("message_id", "=", message_id)]) + self.assertEqual(reply.res_id, self.record.id) + return self._notified(reply) + + def test_incoming_mail_not_forwarded_to_externals(self): + notified = self._receive_reply() + self.assertNotIn(self.external, notified) + self.assertEqual(notified[self.internal_email], "email") + self.assertEqual(notified[self.internal_inbox], "inbox") + + def test_incoming_mail_internal_email_disabled(self): + self.env.company.notify_internal_on_incoming_email = False + notified = self._receive_reply() + self.assertNotIn(self.external, notified) + self.assertNotIn(self.internal_email, notified) + self.assertEqual(notified[self.internal_inbox], "inbox") + + def test_incoming_mail_forward_enabled(self): + self.env.company.disable_incoming_mail_forward = False + notified = self._receive_reply() + self.assertEqual(notified[self.external], "email") + + def test_comment_still_sent_to_externals(self): + notified = self._notified(self.parent) + self.assertEqual(notified[self.external], "email") + self.assertEqual(notified[self.internal_email], "email") diff --git a/mail_incoming_no_forward/views/res_config_settings_views.xml b/mail_incoming_no_forward/views/res_config_settings_views.xml new file mode 100644 index 000000000..029373b8b --- /dev/null +++ b/mail_incoming_no_forward/views/res_config_settings_views.xml @@ -0,0 +1,27 @@ + + + + + res.config.settings.view.form.mail_incoming_no_forward + res.config.settings + + + + + + + + + + + + + diff --git a/mail_layout_force/tests/test_mail_layout_force.py b/mail_layout_force/tests/test_mail_layout_force.py index 51836b77c..75a5e360d 100644 --- a/mail_layout_force/tests/test_mail_layout_force.py +++ b/mail_layout_force/tests/test_mail_layout_force.py @@ -57,7 +57,7 @@ def test_chatter_message_uses_default_layout(self): self.partner.message_post( body="Test Message", email_layout_xmlid=self.mail_notification_layout.xml_id, - message_type="email", + message_type="comment", subtype_xmlid="mail.mt_comment", mail_auto_delete=False, force_send=True, @@ -73,7 +73,7 @@ def test_chatter_message_uses_substituted_layout(self): self.partner.message_post( body="Test Message", email_layout_xmlid=self.mail_notification_layout.xml_id, - message_type="email", + message_type="comment", subtype_xmlid="mail.mt_comment", mail_auto_delete=False, force_send=True,