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

[15.0][ADD] mail_thread_previous_message #1436

Open
wants to merge 1 commit into
base: 15.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
79 changes: 79 additions & 0 deletions mail_thread_previous_message/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
============================
Mail Thread Previous Message
============================

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

.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
:target: https://github.com/OCA/social/tree/15.0/mail_thread_previous_message
:alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-15-0/social-15-0-mail_thread_previous_message
: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=15.0
:alt: Try me on Runboat

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

Adds the mail 'In-Reply-To' header and modify the 'References' one, so
that messages are always grouped as a reply to the previous one.

**Table of contents**

.. contents::
:local:

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_thread_previous_message%0Aversion:%2015.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
-------

* Grupo Isonor

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

- `Grupo Isonor <https://www.grupoisonor.es>`__:

- Alexandre D. Díaz

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/15.0/mail_thread_previous_message>`_ 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_thread_previous_message/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions mail_thread_previous_message/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Mail Thread Previous Message",
"summary": """Adds the 'In-Reply-To' mail header
and modify the references to reflect the entire conversation""",
"category": "Social Network",
"website": "https://github.com/OCA/social",
"author": "Grupo Isonor, Odoo Community Association (OCA)",
"version": "15.0.1.0.0",
"depends": [
"mail",
],
"application": False,
"auto_install": False,
"license": "LGPL-3",
}
1 change: 1 addition & 0 deletions mail_thread_previous_message/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import mail_thread
43 changes: 43 additions & 0 deletions mail_thread_previous_message/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2024 Grupo Isonor
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from ast import literal_eval

from odoo import models


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

def _notify_by_email_add_values(self, base_mail_values):
"""All messages are a response to the previous message.
The entire conversation in the document is referenced."""
res = super()._notify_by_email_add_values(base_mail_values)
message_id = self.env["mail.message"].browse(res["mail_message_id"])
if (
not message_id
or not message_id.model
or not message_id.res_id
or message_id.is_internal
):
return res
orig_id = self.env[message_id.model].browse(message_id.res_id)
orig_non_internal_messages = orig_id.message_ids.filtered(
lambda x: not x.is_internal and x.id != message_id.id
)
if len(orig_non_internal_messages) != 0:
# Set the message as a reply to the previous message
in_reply_to = orig_non_internal_messages[0].message_id
header_in_reply_to = {
"In-Reply-To": in_reply_to,
}
headers = res.get("headers")
if headers:
headers = literal_eval(headers)
headers.update(header_in_reply_to)
res["headers"] = repr(headers)
else:
res["headers"] = repr(header_in_reply_to)

Check warning on line 39 in mail_thread_previous_message/models/mail_thread.py

View check run for this annotation

Codecov / codecov/patch

mail_thread_previous_message/models/mail_thread.py#L39

Added line #L39 was not covered by tests
# Reconstruct the references (See RFC 5322, section 3.6.4)
nref = orig_non_internal_messages.mapped("message_id")
res["references"] = " ".join(reversed(nref))
return res
2 changes: 2 additions & 0 deletions mail_thread_previous_message/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Grupo Isonor](https://www.grupoisonor.es):
- Alexandre D. Díaz
2 changes: 2 additions & 0 deletions mail_thread_previous_message/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Adds the mail 'In-Reply-To' header and modify the 'References' one, so that messages are
always grouped as a reply to the previous one.
Loading
Loading