Skip to content

Fix EmailTask undefined-method errors for serialized Message settings#474

Merged
dereuromark merged 2 commits intomasterfrom
fix/email-task-undefined-setters
Apr 17, 2026
Merged

Fix EmailTask undefined-method errors for serialized Message settings#474
dereuromark merged 2 commits intomasterfrom
fix/email-task-undefined-setters

Conversation

@dereuromark
Copy link
Copy Markdown
Owner

@dereuromark dereuromark commented Apr 17, 2026

Summary

Fixes #473.

Building on #472, this tackles pre-existing bugs in the same code path that were shadowed by the named-parameter crash. Once address settings stopped throwing first, the generic settings loop started calling undefined methods and re-hitting the named-param issue on non-address keys:

Error: Call to undefined method Cake\Mailer\Message::setAppCharset()
Error: Unknown named parameter $X-Custom  (headers map)

Fix

Before the generic settings loop, handle the mismatched/unsafe keys explicitly:

Settings key Action
htmlMessage Message::setBodyHtml()
textMessage Message::setBodyText()
appCharset Message::setCharset() when no explicit charset is also provided (appCharset has no dedicated setter anywhere)
readReceipt added to the address-setter list so associative email => name inputs work without PHP 8 named-parameter issues
headers Message::setHeaders() called with the map as a single positional argument, so string header names are not interpreted as named parameters

The generic call_user_func_array fallback is kept, so any custom set* keys consumers currently rely on continue to work unchanged.

Covered all 20 entries in Message::$serializableProperties:

  • 8 address-shape keys (to/from/cc/bcc/replyTo/sender/returnPath/readReceipt) — routed through the address path from Fix EmailTask named-parameter error for associative address arrays #472
  • 3 keys without matching setters (htmlMessage/textMessage/appCharset) — routed to their real Message methods
  • 1 key with an associative-value named-param risk (headers) — routed as a single positional argument
  • 8 straightforward scalar keys (subject/emailFormat/emailPattern/domain/messageId/charset/headerCharset/attachments) — continue via the existing generic/special-case paths (verified safe: non-associative values, no named-param risk)

Regression tests cover a payload that mirrors Message::__serialize() output and a settings-level associative headers map.

Keys coming from Message::__serialize()/jsonSerialize (htmlMessage,
textMessage, appCharset) don't map to set<Prop>() methods on Mailer or
Message, so passing them via queued JSON payloads failed with
'Call to undefined method'.

Route these keys to their real setters explicitly before the generic
loop:

- htmlMessage -> Message::setBodyHtml()
- textMessage -> Message::setBodyText()
- appCharset  -> Message::setCharset() when no explicit charset is given
- readReceipt -> Mailer::setReadReceipt() (address-shape, named-param safe)
@dereuromark dereuromark added this to the 8.x milestone Apr 17, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 17, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.22%. Comparing base (6eda87a) to head (5e29c24).

Files with missing lines Patch % Lines
src/Queue/Task/EmailTask.php 93.33% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #474      +/-   ##
============================================
+ Coverage     77.15%   77.22%   +0.06%     
- Complexity      944      949       +5     
============================================
  Files            45       45              
  Lines          3182     3196      +14     
============================================
+ Hits           2455     2468      +13     
- Misses          727      728       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

An associative `headers` map inside the settings array hits the same PHP 8
named-parameter problem as the address maps: string keys would otherwise be
interpreted as named arguments when the generic loop spreads them into
`setHeaders()`. Forward the map as a single positional argument instead.
@dereuromark dereuromark merged commit 5410512 into master Apr 17, 2026
16 checks passed
@dereuromark dereuromark deleted the fix/email-task-undefined-setters branch April 17, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unknown methods in EmailTask

2 participants