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
115 changes: 115 additions & 0 deletions mail_visible_email/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
======================================
Make emails for to, cc and bcc visible
======================================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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%2Fmail-lightgray.png?logo=github
:target: https://github.com/OCA/mail/tree/18.0/mail_visible_email
:alt: OCA/mail
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_visible_email
: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/mail&target_branch=18.0
:alt: Try me on Runboat

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

In Odoo mails it is often unclear who were the other recipients of mails
received, or what the actual mail addresses were of mails sent.

This module adds the following fields to mail_message:

- email_to
- email_cc
- email_bcc

For both incoming and outgoing mails, the actual to and cc headers from
the mails will be stored here. For outgoing mails also the bcc header.

In case we receive a mail because we received it on an address that was
in the bcc of the email sent, the address will actually be shown on the
email_to field. This is because there is no bcc header in an incoming
mail, we will have the address in the Delivered-To header.

Note that we will only store the unadorned email (without partner name),
as this will be the relevant part, and the partner names are visible on
other fields.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Configuration
=============

This module has no separate configuration options.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/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/mail/issues/new?body=module:%20mail_visible_email%0Aversion:%2018.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
-------

* Therp BV

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

- `Therp BV <https://therp.nl>`__:

- Ronald Portier <ronald@therp.nl>

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-NL66278| image:: https://github.com/NL66278.png?size=40px
:target: https://github.com/NL66278
:alt: NL66278

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-NL66278|

This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/18.0/mail_visible_email>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions mail_visible_email/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
23 changes: 23 additions & 0 deletions mail_visible_email/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2025 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Make emails for to, cc and bcc visible",
"summary": "Save and show the actual email addresses used in mail.message.",
"version": "18.0.1.0.0",
"development_status": "Alpha",
"category": "Email",
"website": "https://github.com/OCA/mail",
"author": "Therp BV, Odoo Community Association (OCA)",
"maintainers": ["NL66278"],
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"mail",
"mail_composer_cc_bcc",
"test_mail",
],
"data": [
"views/mail_message_views.xml",
],
}
5 changes: 5 additions & 0 deletions mail_visible_email/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import mail_thread
from . import mail_message
from . import mail_mail
57 changes: 57 additions & 0 deletions mail_visible_email/models/mail_mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2025 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, models, tools


def list_emails(partners):
return [
tools.mail.email_normalize(p.email)
for p in partners
if p.email and tools.mail.email_normalize(p.email)
]


class MailMail(models.Model):
_inherit = "mail.mail"

@api.model_create_multi
def create(self, values_list):
mails = super().create(values_list)
for mail in mails:
message_vals = {}
email_values = mail._get_email_values()
for fname in ("email_to", "email_cc", "email_bcc"):
emails = email_values.get(fname, [])
if emails:
message_vals[fname] = mail._append_email(fname, emails)
if message_vals:
mail.mail_message_id.write(message_vals)
return mails

def _get_email_values(self):
"""Return normalized email lists for to, cc and bcc.
- Composer send: recipient_cc_ids/recipient_bcc_ids are set on mail.mail
at create time by the composer's _prepare_mail_values.
- Template send (send_mail): email_to, email_cc, email_bcc
are written directly to mail.mail at create time from the rendered
template values.
"""
self.ensure_one()
cc_bcc = self.recipient_cc_ids + self.recipient_bcc_ids
to_partners = self.recipient_ids - cc_bcc
return {
"email_to": list_emails(to_partners)
or tools.mail.email_normalize_all(self.email_to or ""),
"email_cc": list_emails(self.recipient_cc_ids)
or tools.mail.email_normalize_all(self.email_cc or ""),
"email_bcc": list_emails(self.recipient_bcc_ids)
or tools.mail.email_normalize_all(self.email_bcc or ""),
}

def _append_email(self, fieldname, emails):
"""Merge new emails with any already stored on mail.message."""
self.ensure_one()
existing = self.mail_message_id[fieldname]
if existing:
emails += existing.split(",")
return ",".join(dict.fromkeys(filter(None, emails)))
24 changes: 24 additions & 0 deletions mail_visible_email/models/mail_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2025 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class MailMessage(models.Model):
_inherit = "mail.message"

email_to = fields.Char(
string="To",
readonly=True,
help="original email addresses in 'to' header",
)
email_cc = fields.Char(
string="Cc",
readonly=True,
help="original email addresses in 'cc' header",
)
email_bcc = fields.Char(
string="Bcc",
readonly=True,
help="original email addresses in 'bcc' header",
)
32 changes: 32 additions & 0 deletions mail_visible_email/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2025 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models

_VISIBLE_EMAIL_FIELDS = {"email_to", "email_cc", "email_bcc"}


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

@api.model
def _message_route_process(self, message, message_dict, routes):
"""Intercept message_dict to write 'to' and 'cc' to mail.message.

Smtp does not deliver messages with a bcc header. If a message is
received from a bcc address, this address will be in the raw
Delivered-To header, which message_parse adds to the 'to' key
of message_dict.
"""
message_dict["email_to"] = message_dict.get("to", False)
message_dict["email_cc"] = message_dict.get("cc", False)
return super()._message_route_process(message, message_dict, routes)

def _get_message_create_ignore_field_names(self):
return super()._get_message_create_ignore_field_names() | _VISIBLE_EMAIL_FIELDS

def _message_post_after_hook(self, message, msg_values):
vals = {k: msg_values[k] for k in _VISIBLE_EMAIL_FIELDS if msg_values.get(k)}
if vals:
message.write(vals)
return super()._message_post_after_hook(message, msg_values)
3 changes: 3 additions & 0 deletions mail_visible_email/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions mail_visible_email/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module has no separate configuration options.

4 changes: 4 additions & 0 deletions mail_visible_email/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [Therp BV](https://therp.nl):

> - Ronald Portier \<<ronald@therp.nl>\>

21 changes: 21 additions & 0 deletions mail_visible_email/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
In Odoo mails it is often unclear who were the other recipients of mails
received, or what the actual mail addresses were of mails sent.

This module adds the following fields to mail_message:

- email_to
- email_cc
- email_bcc

For both incoming and outgoing mails, the actual to and cc headers
from the mails will be stored here. For outgoing mails also the bcc
header.

In case we receive a mail because we received it on an address that was
in the bcc of the email sent, the address will actually be shown on the
email_to field. This is because there is no bcc header in an incoming mail,
we will have the address in the Delivered-To header.

Note that we will only store the unadorned email (without partner name),
as this will be the relevant part, and the partner names are visible on
other fields.
Binary file added mail_visible_email/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading