Skip to content

Commit

Permalink
[FIX] mail_composer_cc_bcc: duplicate email
Browse files Browse the repository at this point in the history
  • Loading branch information
trisdoan committed Nov 12, 2024
1 parent 3a1a73f commit 4184143
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 29 deletions.
11 changes: 3 additions & 8 deletions mail_composer_cc_bcc/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ confusing for a lot of end users.
This module allows to properly separate To:, Cc:, and Bcc: fields in the
Mail Composer.

From Odoo 17.0, this module sends one mail per recipient and keeps same
all headers (To, Cc, Bcc) in all emails

Features
--------

- Add Cc and Bcc fields to mail composer form. Send only once to
multiple email addresses.
- Add Cc and Bcc fields to company form to use them as default in mail
composer form.
- Add Bcc field to mail template form. Use Cc and Bcc fields to lookup
Expand Down Expand Up @@ -87,12 +88,6 @@ corresponding mail composer's fields.
.. |image| image:: https://raw.githubusercontent.com/OCA/social/17.0/mail_composer_cc_bcc/static/img/mail_compose_message_default_cc_bcc.png
.. |image1| image:: https://raw.githubusercontent.com/OCA/social/17.0/mail_composer_cc_bcc/static/img/mail_compose_message_template_cc_bcc.png

Known issues / Roadmap
======================

- Extract account customization (account.invoice.send wizard) to a
specific module mail_composer_cc_bcc_account

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

Expand Down
10 changes: 7 additions & 3 deletions mail_composer_cc_bcc/models/mail_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _prepare_outgoing_list(self, recipients_follower_status=None):

# Collect recipients (RCPT TO) and update all emails
# with the same To, Cc headers (to be shown by email client as users expect)
recipients = []
recipients = set()
for m in res:
rcpt_to = None
if m["email_to"]:
Expand All @@ -64,7 +64,7 @@ def _prepare_outgoing_list(self, recipients_follower_status=None):
rcpt_to = extract_rfc2822_addresses(m["email_cc"][0])[0]

if rcpt_to:
recipients.append(rcpt_to)
recipients.add(rcpt_to)

m.update(
{
Expand All @@ -74,5 +74,9 @@ def _prepare_outgoing_list(self, recipients_follower_status=None):
}
)

self.env.context = {**self.env.context, "recipients": recipients}
self.env.context = {**self.env.context, "recipients": list(recipients)}

if len(res) > len(recipients):
res.pop()

return res
4 changes: 2 additions & 2 deletions mail_composer_cc_bcc/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ confusing for a lot of end users.
This module allows to properly separate To:, Cc:, and Bcc: fields in the
Mail Composer.

From Odoo 17.0, this module sends one mail per recipient and keeps same all headers (To, Cc, Bcc) in all emails

## Features

- Add Cc and Bcc fields to mail composer form. Send only once to
multiple email addresses.
- Add Cc and Bcc fields to company form to use them as default in mail
composer form.
- Add Bcc field to mail template form. Use Cc and Bcc fields to lookup
Expand Down
2 changes: 0 additions & 2 deletions mail_composer_cc_bcc/readme/ROADMAP.md

This file was deleted.

20 changes: 6 additions & 14 deletions mail_composer_cc_bcc/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ <h1 class="title">Email CC and BCC</h1>
confusing for a lot of end users.</p>
<p>This module allows to properly separate To:, Cc:, and Bcc: fields in the
Mail Composer.</p>
<p>From Odoo 17.0, this module sends one mail per recipient and keeps same
all headers (To, Cc, Bcc) in all emails</p>
<div class="section" id="features">
<h1>Features</h1>
<ul class="simple">
<li>Add Cc and Bcc fields to mail composer form. Send only once to
multiple email addresses.</li>
<li>Add Cc and Bcc fields to company form to use them as default in mail
composer form.</li>
<li>Add Bcc field to mail template form. Use Cc and Bcc fields to lookup
Expand All @@ -397,9 +397,8 @@ <h1>Features</h1>
<ul class="simple">
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-3">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-4">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-5">Credits</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a></li>
</ul>
</div>
<div class="section" id="configuration">
Expand All @@ -423,23 +422,16 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<blockquote>
<img alt="image1" src="https://raw.githubusercontent.com/OCA/social/17.0/mail_composer_cc_bcc/static/img/mail_compose_message_template_cc_bcc.png" /></blockquote>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h2>
<ul class="simple">
<li>Extract account customization (account.invoice.send wizard) to a
specific module mail_composer_cc_bcc_account</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h2>
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mail_composer_cc_bcc%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-5">Credits</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
</div>
</div>
<div class="section" id="authors">
Expand Down
7 changes: 7 additions & 0 deletions mail_composer_cc_bcc/tests/test_mail_cc_bcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_MailComposer_upstream_file_hash(self):
self.assertIn(func_hash, VALID_HASHES.get("mail.composer:_compute_partner_ids"))

def test_email_cc_bcc(self):
self.test_record.email = "[email protected]"
form = self.open_mail_composer_form()
composer = form.save()
# Use object to update Many2many fields (form can't do like this)
Expand All @@ -75,8 +76,14 @@ def test_email_cc_bcc(self):
with self.mock_mail_gateway():
composer._action_send_mail()

self.assertEqual(len(self._mails), 5)

# Verify recipients of mail.message
message = self.test_record.message_ids[0]

# only keep 1 email to avoid clutting db
# but actually send 1 mail per recipients
self.assertEqual(len(message.mail_ids), 1)
self.assertEqual(len(message.recipient_cc_ids), 3)
self.assertEqual(len(message.recipient_bcc_ids), 1)
# Verify notification
Expand Down

0 comments on commit 4184143

Please sign in to comment.