← Back to Pull requests

[19.0][FIX] mail_composer_cc_bcc: one email per recipient, no Bcc disclosure #2

Open
unknown opened this pull request with 352 lines diff across 4 files
View on GitHub
unknown unknown commented on Aug 05, 2026 19:50 UTC
Author

Follow-up to my review on OCA/mail#104, pushed as commits as @NICO-SOLUTIONS suggested.

This branch builds on @Borruso's camptocamp/mail#1 — his commit is included unchanged, because his two fixes (renaming the override to _prepare_email_message__, which 19.0 renamed, and copying the headers dict) are what make the Bcc emails reach the SMTP server at all. Merging this brings both; if you would rather keep them separate, tell me and I will rebase onto 19.0-mail_composer_cc_bcc once #1 is in.

My commit adds two things on top.

1. One email per recipient (currently the last one is silently lost)

When mail.email_to is empty Odoo builds an extra Cc-only email (odoo/odoo@46bad8f0). Here it is a duplicate: every Cc partner is a recipient and already gets its own email. It was being dropped by comparing lengths:

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

recipients is a set, and a Cc partner is counted once for the Cc-only entry and once for its own, so the count is short by one and pop() removes the last entry — the last recipient's email — instead of the duplicate. With one To, two Cc and two Bcc partners on 19.0:

| | before | after |
|---|---|---|
| emails handed to the SMTP server | 5 | 5 |
| cc1@ | 2 copies | 1 |
| bcc2@ | nothing | 1 |

Filtering the Cc-only entry explicitly (res = [m for m in res if m["email_to"]]) fixes both, and the length heuristic goes away.

2. Drop X-Msg-To-Add

New in 19.0: MailThread._notify_by_email_get_headers() fills that header with every external recipient, and IrMailServer._alter_message__() merges it into the To header at send time to enable Reply-All. Since this module builds the whole To/Cc itself, the header has to go — otherwise the Cc and Bcc addresses end up in the To of every email. I verified this A/B: with the header kept, every recipient (including the plain To one) receives To: to@…, cc1@…, bcc1@…, bcc2@….

Tests

Two tests, both failing before this commit and passing after:

  • test_email_cc_bcc_one_email_per_recipient — 5 recipients → 5 emails, same To/Cc on all of them, no Bcc address visible in any To/Cc, and each Bcc recipient gets its own email.

  • test_email_cc_bcc_no_reply_all_header — no X-Msg-To-Add survives.
  • The existing test_email_cc_bcc asserted len(self._mails) == 5 and passed either way, because the count was right while the recipients were not.

    How this was checked

    Official odoo:19 image (build 19.0.20260723), fresh database, only this module installed, and the SMTP session replaced by a stub recording exactly what Odoo hands to the server (send_message(message, smtp_from, smtp_to_list)) — so the envelopes and headers above are the real ones, not a reading of the code. Full module test suite green (9 tests).

    Diff: 352 lines (+264 / -88) across 4 files Reviewer: NICO-SOLUTIONS Review duration: 168897m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.49) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.49 · 352 lines diff across 4 files
    0.49
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.351
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #2"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.5% (MEDIUM) · Higher = larger blast radius
    49.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.4% · Safe to merge
    27.4%