diff --git a/mail_thread_previous_message/README.rst b/mail_thread_previous_message/README.rst new file mode 100644 index 0000000000..8d395e68b0 --- /dev/null +++ b/mail_thread_previous_message/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Grupo Isonor + +Contributors +------------ + +- `Grupo Isonor `__: + + - 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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_thread_previous_message/__init__.py b/mail_thread_previous_message/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mail_thread_previous_message/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_thread_previous_message/__manifest__.py b/mail_thread_previous_message/__manifest__.py new file mode 100644 index 0000000000..a82daeb76a --- /dev/null +++ b/mail_thread_previous_message/__manifest__.py @@ -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", +} diff --git a/mail_thread_previous_message/models/__init__.py b/mail_thread_previous_message/models/__init__.py new file mode 100644 index 0000000000..b70a9f2d08 --- /dev/null +++ b/mail_thread_previous_message/models/__init__.py @@ -0,0 +1 @@ +from . import mail_thread diff --git a/mail_thread_previous_message/models/mail_thread.py b/mail_thread_previous_message/models/mail_thread.py new file mode 100644 index 0000000000..205a9b311a --- /dev/null +++ b/mail_thread_previous_message/models/mail_thread.py @@ -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) + # 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 diff --git a/mail_thread_previous_message/readme/CONTRIBUTORS.md b/mail_thread_previous_message/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..75b7cb2fb4 --- /dev/null +++ b/mail_thread_previous_message/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Grupo Isonor](https://www.grupoisonor.es): + - Alexandre D. Díaz diff --git a/mail_thread_previous_message/readme/DESCRIPTION.md b/mail_thread_previous_message/readme/DESCRIPTION.md new file mode 100644 index 0000000000..f5917bc3ea --- /dev/null +++ b/mail_thread_previous_message/readme/DESCRIPTION.md @@ -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. diff --git a/mail_thread_previous_message/static/description/index.html b/mail_thread_previous_message/static/description/index.html new file mode 100644 index 0000000000..d2c382cd09 --- /dev/null +++ b/mail_thread_previous_message/static/description/index.html @@ -0,0 +1,427 @@ + + + + + +Mail Thread Previous Message + + + +
+

Mail Thread Previous Message

+ + +

Beta License: LGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

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

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Grupo Isonor
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/setup/mail_thread_previous_message/odoo/addons/mail_thread_previous_message b/setup/mail_thread_previous_message/odoo/addons/mail_thread_previous_message new file mode 120000 index 0000000000..28acb80427 --- /dev/null +++ b/setup/mail_thread_previous_message/odoo/addons/mail_thread_previous_message @@ -0,0 +1 @@ +../../../../mail_thread_previous_message \ No newline at end of file diff --git a/setup/mail_thread_previous_message/setup.py b/setup/mail_thread_previous_message/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/mail_thread_previous_message/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)