Skip to content

🪲 BUG-#68: Avoid mutating caller EmailMessage when adding From header - #77

Merged
FernandoCelmer merged 2 commits into
developfrom
feature/68
May 17, 2026
Merged

🪲 BUG-#68: Avoid mutating caller EmailMessage when adding From header#77
FernandoCelmer merged 2 commits into
developfrom
feature/68

Conversation

@FernandoCelmer

Copy link
Copy Markdown
Member

Summary

  • Sender.send_message now deepcopy's the caller's EmailMessage before injecting the From header when missing
  • Prevents duplicate From: headers on retry and silent mutation of caller-owned objects
  • Tests cover both the non-mutation invariant and the two-call retry path

Closes #68

Test plan

  • pytest tests/clients/smtp/test_send.py — 10 passed

@FernandoCelmer FernandoCelmer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Code Review

Code issues found: 0

copy.deepcopy before injecting From is the minimal correct fix. Both tests are meaningful:

  1. Caller's message is left untouched.
  2. Two consecutive sends produce one From header on the wire — no header duplication on retry.

One minor non-blocking observation for the future (not required to merge): deepcopy of an EmailMessage with large attachments is O(payload size). Since the copy only happens when From is missing, this is fine in practice — but if you ever start mutating other headers, consider email.message_from_bytes(msg.as_bytes()) or a shallow rebuild instead.

Closes #68.

@FernandoCelmer
FernandoCelmer merged commit 41e4f71 into develop May 17, 2026
11 checks passed
@FernandoCelmer
FernandoCelmer deleted the feature/68 branch May 17, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant