diff --git a/mass_mailing_disable_tracking/README.rst b/mass_mailing_disable_tracking/README.rst new file mode 100644 index 0000000000..11c9b2521f --- /dev/null +++ b/mass_mailing_disable_tracking/README.rst @@ -0,0 +1,129 @@ +============================= +Mass Mailing Disable Tracking +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1e2637616e4184bea186bcb57d3a5eca2df0bad6829bd9c9379853c2a6ea2b05 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.0/mass_mailing_disable_tracking + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mass_mailing_disable_tracking + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to disable open and link click tracking in mass +mailing messages. + +Odoo Mass Mailing (aka Email Marketing) includes 2 ways of tracking +(spying on, invade the privacy of) the recipients: + +1. Tracking the “opening” of the email message by including a 1-pixel + transparent GIF image at the bottom of the message, using a URL to + the Odoo instance that uniquely identifies that message sent to that + recipient. As soon as the recipient displays the remote images of the + message, their email client downloads the tracking image and the Odoo + instance knows that that particular recipient opened that particular + message. +2. Tracking the “clicks” on the links included in the message by + converting all links of the message to a tracking URL to the Odoo + instance. As soon as the recipient clicks one of those links, their + browser will make a request to the Odoo instance, which will record + that click on that particular link for that particular recipient + before redirecting the browser to the original link address. + +This module allows to disable both of these mechanisms by preventing the +original email message to be modified by Odoo to include these tracking +mechanisms. + +Another issue that link click tracking causes is that recipients are +unable to inspect the links: they cannot know on which website they will +land before clicking on them. This, and the fact that they are tracked, +can cause some recipients to not click the links, making the mass +mailing actually less effective. + +Statistics can be useful, but respecting your recipients’ privacy is +important. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +By default, just by installing this module, open and link click tracking +is disabled for new mass mailings. + +It is still possible to enable each one separately by going to +**Settings** > **Email Marketing** and checking the corresponding +checkboxes. + +.. note:: + + This module is incompatible with the ``mail_tracking`` module. + +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 +------- + +* hugues de keyzer + +Contributors +------------ + +- hugues de keyzer + +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. + +.. |maintainer-huguesdk| image:: https://github.com/huguesdk.png?size=40px + :target: https://github.com/huguesdk + :alt: huguesdk + +Current `maintainer `__: + +|maintainer-huguesdk| + +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/mass_mailing_disable_tracking/__init__.py b/mass_mailing_disable_tracking/__init__.py new file mode 100644 index 0000000000..0c988b743b --- /dev/null +++ b/mass_mailing_disable_tracking/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2025 hugues de keyzer +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import models diff --git a/mass_mailing_disable_tracking/__manifest__.py b/mass_mailing_disable_tracking/__manifest__.py new file mode 100644 index 0000000000..eda1ad13db --- /dev/null +++ b/mass_mailing_disable_tracking/__manifest__.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2025 hugues de keyzer +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +{ + "name": "Mass Mailing Disable Tracking", + "summary": "Allow to disable open and link click tracking in mass mailing messages", + "version": "18.0.1.0.0", + "category": "Marketing/Email Marketing", + "website": "https://github.com/OCA/social", + "author": "hugues de keyzer, Odoo Community Association (OCA)", + "maintainers": ["huguesdk"], + "license": "AGPL-3", + "depends": [ + "mass_mailing", + ], + "excludes": [ + "mail_tracking", + ], + "data": [ + "views/res_config_settings_view.xml", + ], +} diff --git a/mass_mailing_disable_tracking/i18n/it.po b/mass_mailing_disable_tracking/i18n/it.po new file mode 100644 index 0000000000..6d790490ae --- /dev/null +++ b/mass_mailing_disable_tracking/i18n/it.po @@ -0,0 +1,60 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mass_mailing_disable_tracking +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-04-30 10:45+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.15.2\n" + +#. module: mass_mailing_disable_tracking +#: model_terms:ir.ui.view,arch_db:mass_mailing_disable_tracking.res_config_settings_view_form +msgid "" +"Add an invisible tracking image to mass mailing messages to track their " +"opening by the recipient" +msgstr "" +"Aggiungere un'immagine di tracciamento invisibile ai messaggi di posta " +"elettronica inviati in massa per monitorare l'apertura da parte del " +"destinatario" + +#. module: mass_mailing_disable_tracking +#: model:ir.model,name:mass_mailing_disable_tracking.model_res_config_settings +msgid "Config Settings" +msgstr "Impostazioni configurazione" + +#. module: mass_mailing_disable_tracking +#: model_terms:ir.ui.view,arch_db:mass_mailing_disable_tracking.res_config_settings_view_form +msgid "" +"Convert links in mass mailing messages to track link clicks by the recipient" +msgstr "" +"Convertire i link nei messaggi di posta elettronica inviati in massa per " +"monitorare i clic sui link da parte del destinatario" + +#. module: mass_mailing_disable_tracking +#: model:ir.model,name:mass_mailing_disable_tracking.model_mail_render_mixin +msgid "Mail Render Mixin" +msgstr "Mixin resa posta" + +#. module: mass_mailing_disable_tracking +#: model:ir.model,name:mass_mailing_disable_tracking.model_mail_mail +msgid "Outgoing Mails" +msgstr "E-mail in uscita" + +#. module: mass_mailing_disable_tracking +#: model:ir.model.fields,field_description:mass_mailing_disable_tracking.field_res_config_settings__mailing_track_links +msgid "Track Link Clicks" +msgstr "Traccia clic link" + +#. module: mass_mailing_disable_tracking +#: model:ir.model.fields,field_description:mass_mailing_disable_tracking.field_res_config_settings__mailing_track_open +msgid "Track Open" +msgstr "Traccia apertura" diff --git a/mass_mailing_disable_tracking/i18n/mass_mailing_disable_tracking.pot b/mass_mailing_disable_tracking/i18n/mass_mailing_disable_tracking.pot new file mode 100644 index 0000000000..ffce96cd8b --- /dev/null +++ b/mass_mailing_disable_tracking/i18n/mass_mailing_disable_tracking.pot @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mass_mailing_disable_tracking +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mass_mailing_disable_tracking +#: model_terms:ir.ui.view,arch_db:mass_mailing_disable_tracking.res_config_settings_view_form +msgid "" +"Add an invisible tracking image to mass mailing messages to track their " +"opening by the recipient" +msgstr "" + +#. module: mass_mailing_disable_tracking +#: model:ir.model,name:mass_mailing_disable_tracking.model_res_config_settings +msgid "Config Settings" +msgstr "" + +#. module: mass_mailing_disable_tracking +#: model_terms:ir.ui.view,arch_db:mass_mailing_disable_tracking.res_config_settings_view_form +msgid "" +"Convert links in mass mailing messages to track link clicks by the recipient" +msgstr "" + +#. module: mass_mailing_disable_tracking +#: model:ir.model,name:mass_mailing_disable_tracking.model_mail_render_mixin +msgid "Mail Render Mixin" +msgstr "" + +#. module: mass_mailing_disable_tracking +#: model:ir.model,name:mass_mailing_disable_tracking.model_mail_mail +msgid "Outgoing Mails" +msgstr "" + +#. module: mass_mailing_disable_tracking +#: model:ir.model.fields,field_description:mass_mailing_disable_tracking.field_res_config_settings__mailing_track_links +msgid "Track Link Clicks" +msgstr "" + +#. module: mass_mailing_disable_tracking +#: model:ir.model.fields,field_description:mass_mailing_disable_tracking.field_res_config_settings__mailing_track_open +msgid "Track Open" +msgstr "" diff --git a/mass_mailing_disable_tracking/models/__init__.py b/mass_mailing_disable_tracking/models/__init__.py new file mode 100644 index 0000000000..81c94f99c3 --- /dev/null +++ b/mass_mailing_disable_tracking/models/__init__.py @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: 2025 hugues de keyzer +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import mail_mail +from . import mail_render_mixin +from . import res_config_settings diff --git a/mass_mailing_disable_tracking/models/mail_mail.py b/mass_mailing_disable_tracking/models/mail_mail.py new file mode 100644 index 0000000000..0088c8bd27 --- /dev/null +++ b/mass_mailing_disable_tracking/models/mail_mail.py @@ -0,0 +1,86 @@ +# SPDX-FileCopyrightText: 2025 hugues de keyzer +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +import re + +import werkzeug.urls +from markupsafe import Markup + +from odoo import api, models, tools + +from .res_config_settings import TRACK_LINKS_PARAMETER, TRACK_OPEN_PARAMETER + +TRACKING_LINK_PREFIX = "/r/" +DO_NOT_REPLACE_PLACEHOLDER = "/__do_not_replace__/" +DUMMY_TRACKING_URL = "https://this.is.a.dummy.tracking.url/" + + +class MailMail(models.Model): + _inherit = "mail.mail" + + def _replace_in_html(self, html, to_replace, value): + # this comes from mail.render.mixin._replace_local_links() from the + # mail module. + if not html: + return html + wrapper = Markup if isinstance(html, Markup) else str + html = str(html or "") + return wrapper(html.replace(to_replace, value)) + + @api.model + def _replace_tracking_like_links(self, body, to_replace, value): + # this is the same mechanism to find and replace links as used in the + # _prepare_outgoing_body() method from the mass_mailing module. + for match in set(re.findall(tools.mail.URL_REGEX, body)): + href = match[0] + url = match[1] + parsed = werkzeug.urls.url_parse(url, scheme="http") + if parsed.scheme.startswith("http") and parsed.path.startswith(to_replace): + new_href = href.replace(url, url.replace(to_replace, value)) + body = self._replace_in_html(body, href, new_href) + return body + + def _get_tracking_url(self): + if self.env["ir.config_parameter"].sudo().get_param(TRACK_OPEN_PARAMETER): + return super()._get_tracking_url() + # return a dummy tracking url that can be replaced afterwards. it must + # be a full url, otherwise it will be considered as a local url and + # converted. + return DUMMY_TRACKING_URL + + def _prepare_outgoing_body(self): + # mail.mail._prepare_outgoing_body() in the mass_mailing module does 2 + # things: + # 1. convert tracking links by appending a mailing.trace id to them. + # 2. add an tracking image at the end of the html body. + # it does these things only if its mailing_id and mailing_trace_ids + # fields are set. + self.ensure_one() + ir_config_parameter_model = self.env["ir.config_parameter"].sudo() + track_open = ir_config_parameter_model.get_param(TRACK_OPEN_PARAMETER) + track_links = ir_config_parameter_model.get_param(TRACK_LINKS_PARAMETER) + if ( + not self.mailing_id + or not self.mailing_trace_ids + or (track_open and track_links) + ): + return super()._prepare_outgoing_body() + body_html = self.body_html + if not track_links: + # ensure that there are no links that look like tracking links to + # avoid them being replaced. + self.body_html = self._replace_tracking_like_links( + self.body_html, TRACKING_LINK_PREFIX, DO_NOT_REPLACE_PLACEHOLDER + ) + body = super()._prepare_outgoing_body() + if not track_links: + self.body_html = body_html + body = self._replace_tracking_like_links( + body, DO_NOT_REPLACE_PLACEHOLDER, TRACKING_LINK_PREFIX + ) + if not track_open: + body = self._replace_in_html( + body, f'\n\n', "" + ) + return body diff --git a/mass_mailing_disable_tracking/models/mail_render_mixin.py b/mass_mailing_disable_tracking/models/mail_render_mixin.py new file mode 100644 index 0000000000..20eb543773 --- /dev/null +++ b/mass_mailing_disable_tracking/models/mail_render_mixin.py @@ -0,0 +1,27 @@ +# SPDX-FileCopyrightText: 2025 hugues de keyzer +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import api, models + +from .res_config_settings import TRACK_LINKS_PARAMETER + + +class MailRenderMixin(models.AbstractModel): + _inherit = "mail.render.mixin" + + @api.model + def _shorten_links(self, html, link_tracker_vals, blacklist=None, base_url=None): + if self.env["ir.config_parameter"].sudo().get_param(TRACK_LINKS_PARAMETER): + return super()._shorten_links(html, link_tracker_vals, blacklist, base_url) + return html + + @api.model + def _shorten_links_text( + self, content, link_tracker_vals, blacklist=None, base_url=None + ): + if self.env["ir.config_parameter"].sudo().get_param(TRACK_LINKS_PARAMETER): + return super()._shorten_links_text( + content, link_tracker_vals, blacklist, base_url + ) + return content diff --git a/mass_mailing_disable_tracking/models/res_config_settings.py b/mass_mailing_disable_tracking/models/res_config_settings.py new file mode 100644 index 0000000000..0e3a50040d --- /dev/null +++ b/mass_mailing_disable_tracking/models/res_config_settings.py @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2025 hugues de keyzer +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import fields, models + +TRACK_OPEN_PARAMETER = "mailing.mailing.track_open" +TRACK_LINKS_PARAMETER = "mailing.mailing.track_links" + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + mailing_track_open = fields.Boolean( + "Track Open", config_parameter=TRACK_OPEN_PARAMETER + ) + mailing_track_links = fields.Boolean( + "Track Link Clicks", config_parameter=TRACK_LINKS_PARAMETER + ) diff --git a/mass_mailing_disable_tracking/pyproject.toml b/mass_mailing_disable_tracking/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/mass_mailing_disable_tracking/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mass_mailing_disable_tracking/readme/CONTRIBUTORS.md b/mass_mailing_disable_tracking/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..1d728f7db1 --- /dev/null +++ b/mass_mailing_disable_tracking/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- hugues de keyzer diff --git a/mass_mailing_disable_tracking/readme/DESCRIPTION.md b/mass_mailing_disable_tracking/readme/DESCRIPTION.md new file mode 100644 index 0000000000..be1afa357e --- /dev/null +++ b/mass_mailing_disable_tracking/readme/DESCRIPTION.md @@ -0,0 +1,32 @@ +This module allows to disable open and link click tracking in mass +mailing messages. + +Odoo Mass Mailing (aka Email Marketing) includes 2 ways of tracking +(spying on, invade the privacy of) the recipients: + +1. Tracking the “opening” of the email message by including a 1-pixel + transparent GIF image at the bottom of the message, using a URL to + the Odoo instance that uniquely identifies that message sent to that + recipient. As soon as the recipient displays the remote images of + the message, their email client downloads the tracking image and the + Odoo instance knows that that particular recipient opened that + particular message. +2. Tracking the “clicks” on the links included in the message by + converting all links of the message to a tracking URL to the Odoo + instance. As soon as the recipient clicks one of those links, their + browser will make a request to the Odoo instance, which will record + that click on that particular link for that particular recipient + before redirecting the browser to the original link address. + +This module allows to disable both of these mechanisms by preventing the +original email message to be modified by Odoo to include these tracking +mechanisms. + +Another issue that link click tracking causes is that recipients are +unable to inspect the links: they cannot know on which website they will +land before clicking on them. This, and the fact that they are tracked, +can cause some recipients to not click the links, making the mass +mailing actually less effective. + +Statistics can be useful, but respecting your recipients’ privacy is +important. diff --git a/mass_mailing_disable_tracking/readme/USAGE.md b/mass_mailing_disable_tracking/readme/USAGE.md new file mode 100644 index 0000000000..1ec8ab45bb --- /dev/null +++ b/mass_mailing_disable_tracking/readme/USAGE.md @@ -0,0 +1,9 @@ +By default, just by installing this module, open and link click tracking +is disabled for new mass mailings. + +It is still possible to enable each one separately by going to +**Settings** \> **Email Marketing** and checking the corresponding +checkboxes. + +> [!NOTE] +> This module is incompatible with the `mail_tracking` module. diff --git a/mass_mailing_disable_tracking/static/description/icon.png b/mass_mailing_disable_tracking/static/description/icon.png new file mode 100644 index 0000000000..1dcc49c24f Binary files /dev/null and b/mass_mailing_disable_tracking/static/description/icon.png differ diff --git a/mass_mailing_disable_tracking/static/description/index.html b/mass_mailing_disable_tracking/static/description/index.html new file mode 100644 index 0000000000..e01d4c0775 --- /dev/null +++ b/mass_mailing_disable_tracking/static/description/index.html @@ -0,0 +1,466 @@ + + + + + +Mass Mailing Disable Tracking + + + +
+

Mass Mailing Disable Tracking

+ + +

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

+

This module allows to disable open and link click tracking in mass +mailing messages.

+

Odoo Mass Mailing (aka Email Marketing) includes 2 ways of tracking +(spying on, invade the privacy of) the recipients:

+
    +
  1. Tracking the “opening” of the email message by including a 1-pixel +transparent GIF image at the bottom of the message, using a URL to +the Odoo instance that uniquely identifies that message sent to that +recipient. As soon as the recipient displays the remote images of the +message, their email client downloads the tracking image and the Odoo +instance knows that that particular recipient opened that particular +message.
  2. +
  3. Tracking the “clicks” on the links included in the message by +converting all links of the message to a tracking URL to the Odoo +instance. As soon as the recipient clicks one of those links, their +browser will make a request to the Odoo instance, which will record +that click on that particular link for that particular recipient +before redirecting the browser to the original link address.
  4. +
+

This module allows to disable both of these mechanisms by preventing the +original email message to be modified by Odoo to include these tracking +mechanisms.

+

Another issue that link click tracking causes is that recipients are +unable to inspect the links: they cannot know on which website they will +land before clicking on them. This, and the fact that they are tracked, +can cause some recipients to not click the links, making the mass +mailing actually less effective.

+

Statistics can be useful, but respecting your recipients’ privacy is +important.

+

Table of contents

+ +
+

Usage

+

By default, just by installing this module, open and link click tracking +is disabled for new mass mailings.

+

It is still possible to enable each one separately by going to +Settings > Email Marketing and checking the corresponding +checkboxes.

+
+

Note

+

This module is incompatible with the mail_tracking module.

+
+
+
+

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

+
    +
  • hugues de keyzer
  • +
+
+
+

Contributors

+
    +
  • hugues de keyzer
  • +
+
+
+

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.

+

Current maintainer:

+

huguesdk

+

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/mass_mailing_disable_tracking/tests/__init__.py b/mass_mailing_disable_tracking/tests/__init__.py new file mode 100644 index 0000000000..773b3ba9bc --- /dev/null +++ b/mass_mailing_disable_tracking/tests/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2025 hugues de keyzer +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import test_mass_mailing_disable_tracking diff --git a/mass_mailing_disable_tracking/tests/test_mass_mailing_disable_tracking.py b/mass_mailing_disable_tracking/tests/test_mass_mailing_disable_tracking.py new file mode 100644 index 0000000000..087a064152 --- /dev/null +++ b/mass_mailing_disable_tracking/tests/test_mass_mailing_disable_tracking.py @@ -0,0 +1,133 @@ +# SPDX-FileCopyrightText: 2025 hugues de keyzer +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +import re + +from markupsafe import Markup + +from odoo import Command +from odoo.tests.common import TransactionCase + +from odoo.addons.mass_mailing_disable_tracking.models.res_config_settings import ( + TRACK_LINKS_PARAMETER, + TRACK_OPEN_PARAMETER, +) + + +class TestMassMailingDisableTracking(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.test_mailing_list = cls.env["mailing.list"].create( + { + "name": "dummy test mailing list", + } + ) + cls.test_mailing_contact = cls.env["mailing.contact"].create( + { + "name": "dummy test mailing contact", + "email": "test@example.net", + "list_ids": [Command.set([cls.test_mailing_list.id])], + } + ) + cls.markup = Markup( + '

hello, this is a link

' + "

this is not a link: https://odoo-community.org/

" + '

' + "this is a link that looks like a tracking link

" + ) + cls.test_mailing_mailing = cls.env["mailing.mailing"].create( + { + "name": "dummy test mailing mailing", + "subject": "dummy test subject", + "contact_list_ids": [Command.set([cls.test_mailing_list.id])], + "body_html": cls.markup, + "keep_archives": True, + } + ) + cls.base_url = cls.env["ir.config_parameter"].get_param("web.base.url") + + def _get_last_mail_id(self): + return self.env["mail.mail"].search([], order="id desc", limit=1).id + + def _get_new_mail_messages(self, last_mail_id): + return self.env["mail.mail"].search([("id", ">", last_mail_id or 0)]) + + def _send_mail(self): + last_mail_id = self._get_last_mail_id() + self.test_mailing_mailing.action_send_mail() + mail_mail = self._get_new_mail_messages(last_mail_id) + # the tracking image and link replacement are added while preparing + # the outgoing body. compute the sent body by calling + # _prepare_outgoing_body() directly. + return mail_mail.ensure_one()._prepare_outgoing_body() + + def test_disable_tracking(self): + self.env["ir.config_parameter"].set_param(TRACK_OPEN_PARAMETER, False) + self.env["ir.config_parameter"].set_param(TRACK_LINKS_PARAMETER, False) + mail = self._send_mail() + # nothing should be transformed. this includes links starting with /r/ + # that must not get a mailing.track id appended to them. + self.assertRegex(str(mail), rf"\s*?{str(self.markup)}\s*?") + + def test_disable_tracking_with_special_links(self): + self.env["ir.config_parameter"].set_param(TRACK_OPEN_PARAMETER, False) + self.env["ir.config_parameter"].set_param(TRACK_LINKS_PARAMETER, False) + self.test_mailing_mailing.body_html = Markup( + str(self.markup) + + '

this is an unsubscribe link

' + '

this is a view link

' + '

this is a local link

' + ) + mail = self._send_mail() + # unsubscribe and view links should still be converted and local links + # should become full urls. + self.assertRegex( + str(mail), + rf"(?s).*?{re.escape(str(self.markup))}" + rf".*?

" + "this is an unsubscribe link

" + rf".*?

" + "this is a view link

" + rf".*?

" + "this is a local link

.*?", + ) + + def test_enable_open_tracking_only(self): + self.env["ir.config_parameter"].set_param(TRACK_OPEN_PARAMETER, True) + self.env["ir.config_parameter"].set_param(TRACK_LINKS_PARAMETER, False) + mail = self._send_mail() + # check that the tracking image is present. + self.assertRegex( + str(mail), + rf"\s*?{str(self.markup)}\s*?" + rf'\s*?', + ) + + def test_enable_links_tracking_only(self): + self.env["ir.config_parameter"].set_param(TRACK_OPEN_PARAMETER, False) + self.env["ir.config_parameter"].set_param(TRACK_LINKS_PARAMETER, True) + mail = self._send_mail() + # check that links are correctly converted. + self.assertRegex( + str(mail), + rf'this is a link.+?' + "this is not a link: https://odoo-community.org/.+?" + rf'this is a link that ' + "looks like a tracking link", + ) + + def test_enable_tracking(self): + self.env["ir.config_parameter"].set_param(TRACK_OPEN_PARAMETER, True) + self.env["ir.config_parameter"].set_param(TRACK_LINKS_PARAMETER, True) + mail = self._send_mail() + # should work as if the module is not installed. + self.assertRegex( + str(mail), + rf'this is a link.+?' + "this is not a link: https://odoo-community.org/.+?" + rf'this is a link that ' + r"looks like a tracking link.+?\s*?" + rf'\s*?', + ) diff --git a/mass_mailing_disable_tracking/views/res_config_settings_view.xml b/mass_mailing_disable_tracking/views/res_config_settings_view.xml new file mode 100644 index 0000000000..d0f1473064 --- /dev/null +++ b/mass_mailing_disable_tracking/views/res_config_settings_view.xml @@ -0,0 +1,44 @@ + + + + + res.config.settings.view.form.inherit.mass.mailing.disable.tracking + res.config.settings + + + +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+