Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
1 change: 1 addition & 0 deletions mail_incoming_no_forward/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions mail_incoming_no_forward/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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"],
}
3 changes: 3 additions & 0 deletions mail_incoming_no_forward/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import mail_thread
from . import res_company
from . import res_config_settings
33 changes: 33 additions & 0 deletions mail_incoming_no_forward/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -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"])
]
19 changes: 19 additions & 0 deletions mail_incoming_no_forward/models/res_company.py
Original file line number Diff line number Diff line change
@@ -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.",
)
17 changes: 17 additions & 0 deletions mail_incoming_no_forward/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -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,
)
3 changes: 3 additions & 0 deletions mail_incoming_no_forward/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
7 changes: 7 additions & 0 deletions mail_incoming_no_forward/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions mail_incoming_no_forward/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Camptocamp](https://www.camptocamp.com):
- David Gallay
11 changes: 11 additions & 0 deletions mail_incoming_no_forward/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
When Odoo receives a mail on a record, it forwards a copy to every follower of
the record, sent as `<sender name> <catchall address>`.

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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mail_incoming_no_forward/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_incoming_mail_notification
10 changes: 10 additions & 0 deletions mail_incoming_no_forward/tests/common.py
Original file line number Diff line number Diff line change
@@ -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/<filename>``."""
with file_open(f"mail_incoming_no_forward/tests/eml/{filename}", mode) as eml:
return eml.read()
8 changes: 8 additions & 0 deletions mail_incoming_no_forward/tests/eml/reply.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
From: Sender <sender@example.com>
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
90 changes: 90 additions & 0 deletions mail_incoming_no_forward/tests/test_incoming_mail_notification.py
Original file line number Diff line number Diff line change
@@ -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")
27 changes: 27 additions & 0 deletions mail_incoming_no_forward/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2026 Camptocamp SA
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field
name="name"
>res.config.settings.view.form.mail_incoming_no_forward</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="mail.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//block[@id='emails']" position="inside">
<setting
help="Odoo forwards incoming mails to all the followers by email."
>
<field name="disable_incoming_mail_forward" />
</setting>
<setting
help="Forward incoming mails to internal followers notified by email."
invisible="not disable_incoming_mail_forward"
>
<field name="notify_internal_on_incoming_email" />
</setting>
</xpath>
</field>
</record>
</odoo>
4 changes: 2 additions & 2 deletions mail_layout_force/tests/test_mail_layout_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to disable mail_incoming_no_forward module instead of changing what is tested on an other module.
Why do we have this conflict ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of changing what is tested on an other module

The test is wrong, an email coming from Odoo is never of type email.
message_type='email' is for incoming
=> It must be fixed in any case

Why do we have this conflict ?

Because the test in mail_layout_force is wrong.
It tries to send an email but marks it as an incoming email (message_type='email' is for incoming).

This module prevents forwarding an incoming email to the followers
-> When it sees the message_type='email', it stops the message, which is the correct behavior.

subtype_xmlid="mail.mt_comment",
mail_auto_delete=False,
force_send=True,
Expand All @@ -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,
Expand Down