Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][ADD] mail_prevent_bounce_loop #1419

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
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
110 changes: 110 additions & 0 deletions mail_prevent_bounce_loop/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
========================
Mail Prevent Bounce Loop
========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a2c5d232ac1c492e303d58e122afb9f061be446596049b2431a4105fd481f04e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
:target: https://github.com/OCA/social/tree/17.0/mail_prevent_bounce_loop
:alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-17-0/social-17-0-mail_prevent_bounce_loop
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module helps to prevent infinite loop between odoo and
autoresponder, which is currently raised in
`here <https://github.com/odoo/odoo/issues/132666>`__

- Case 1: odoo sends an invoice email to customer mail address,
autoresponder sends auto-reply mail (without enough information for
odoo to detect it as an auto-reply: headers
`-loop-detection-bounce-email@/-loop-detection-bounce-email <https://github.com/odoo/odoo/blob/9be0c5348bfeb338bcba95b2a9c01e0d7dd14306/addons/mail/models/mail_thread.py#L1373>`__).
Odoo receives and send another one, resulting ping-pong situation.
- Case 2: a cron, Notification: Send scheduled message notifications.
When odoo receives automatic reply, the cron (running by default
every hour) sends notifications to all involved followers of the
mail, which then leads to the above issue

Users can avoid the issue by disabling bounce mail at partner level.

**Table of contents**

.. contents::
:local:

Usage
=====

To never send a bounce email to a specific email address, you can tick
no_bounce_email as below:

|no_bounce_email|

To never send email notification when receiving auto-reply email from a
specific email address identified as an auto-reply address, you can tick
is_automatic_reply_address as below:

|is_automatic_reply|

Comment on lines +57 to +65
Copy link
Contributor

Choose a reason for hiding this comment

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

in odoo this seems to be not well displayed:

image

.. |no_bounce_email| image:: https://raw.githubusercontent.com/OCA/social/17.0/mail_prevent_bounce_loop/static/img/no_bounce_email.png
.. |is_automatic_reply| image:: https://raw.githubusercontent.com/OCA/social/17.0/mail_prevent_bounce_loop/static/img/is_automatic_reply.png

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_prevent_bounce_loop%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Camptocamp

Contributors
------------

- `Camptocamp <https://www.camptocamp.com>`__

- Anna <[email protected]>
- Tri Doan <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/social <https://github.com/OCA/social/tree/17.0/mail_prevent_bounce_loop>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions mail_prevent_bounce_loop/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions mail_prevent_bounce_loop/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Mail Prevent Bounce Loop",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social",
"category": "Social Network",
"license": "AGPL-3",
"application": False,
"installable": True,
"version": "17.0.1.0.0",
"depends": ["mail"],
"data": [
"views/res_partner.xml",
],
}
2 changes: 2 additions & 0 deletions mail_prevent_bounce_loop/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import res_partner
from . import mail_thread
61 changes: 61 additions & 0 deletions mail_prevent_bounce_loop/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2024 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

import logging

from odoo import models

_logger = logging.getLogger(__name__)


class MailThread(models.AbstractModel):
_inherit = "mail.thread"

def _routing_create_bounce_email(
self, email_from, body_html, message, **mail_values
):
partner = self._mail_find_partner_from_emails([email_from])
if partner and partner[0].no_bounce_email:
_logger.info("No bounce email sent to %s", email_from)
return True
super()._routing_create_bounce_email(
email_from, body_html, message, **mail_values
)

def _notify_thread_by_email(
self,
message,
recipients_data,
msg_vals=False,
mail_auto_delete=True,
model_description=False,
force_email_company=False,
force_email_lang=False,
resend_existing=False,
force_send=True,
send_after_commit=True,
subtitles=None,
**kwargs,
):
email_from = message.email_from
email_from_partner = self._mail_find_partner_from_emails([email_from])
if email_from_partner and email_from_partner[0].is_automatic_reply_address:
_logger.info(
"No notification sent to followers for email received from %s",
email_from,
)
return True
return super()._notify_thread_by_email(
message,
recipients_data,
msg_vals,
mail_auto_delete,
model_description,
force_email_company,
force_email_lang,
resend_existing,
force_send,
send_after_commit,
subtitles,
**kwargs,
)
16 changes: 16 additions & 0 deletions mail_prevent_bounce_loop/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import fields, models


class ResPartner(models.Model):
_inherit = "res.partner"

no_bounce_email = fields.Boolean(
help="When checked, bounced emails will not be forwarded to this address"
)
is_automatic_reply_address = fields.Boolean(
Copy link
Member

Choose a reason for hiding this comment

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

I find this name a little misleading, better use one that expresses what this does, as in no_chatter_forward or similar

help="When checked, any email received from this address will not be forwarded"
"to the followers of a conversation (chatter)",
)
3 changes: 3 additions & 0 deletions mail_prevent_bounce_loop/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions mail_prevent_bounce_loop/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [Camptocamp](https://www.camptocamp.com)
- Anna \<<[email protected]>\>
- Tri Doan \<<[email protected]>\>
11 changes: 11 additions & 0 deletions mail_prevent_bounce_loop/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This module helps to prevent infinite loop between odoo and
autoresponder, which is currently raised in [here](<https://github.com/odoo/odoo/issues/132666>)
- Case 1: odoo sends an invoice email to customer mail address, autoresponder sends auto-reply mail (without enough information for
odoo to detect it as an auto-reply: headers [-loop-detection-bounce-email@/-loop-detection-bounce-email](https://github.com/odoo/odoo/blob/9be0c5348bfeb338bcba95b2a9c01e0d7dd14306/addons/mail/models/mail_thread.py#L1373)). Odoo receives and
send another one, resulting ping-pong situation.
- Case 2: a cron, Notification: Send scheduled
message notifications. When odoo receives automatic reply, the cron
(running by default every hour) sends notifications to all involved
followers of the mail, which then leads to the above issue

Users can avoid the issue by disabling bounce mail at partner level.
10 changes: 10 additions & 0 deletions mail_prevent_bounce_loop/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
To never send a bounce email to a specific email address, you can tick
no_bounce_email as below:

![no_bounce_email](../static/img/no_bounce_email.png)

To never send email notification when receiving auto-reply email from a
specific email address identified as an auto-reply address, you can tick is_automatic_reply_address as
below:

![is_automatic_reply](../static/img/is_automatic_reply.png)
Loading
Loading