Skip to content

fix: respect mail event replacements and initialize queued mail result - #107

Open
FlorianX wants to merge 2 commits into
sabbelasichon:mainfrom
FlorianX:fix/respect-before-mailer-sent-message-event
Open

FlorianX wants to merge 2 commits into
sabbelasichon:mainfrom
FlorianX:fix/respect-before-mailer-sent-message-event

Conversation

@FlorianX

@FlorianX FlorianX commented Oct 19, 2026 •

Copy link
Copy Markdown

Problems

  1. Listeners to BeforeMailerSentMessageEvent can replace the message or envelope, but MessengerMailer previously continued using the original arguments.
  2. TYPO3's MailMessage::send() calls getSentMessage() after submitting the email. With asynchronous Messenger routing there is no HandledStamp, so $sentMessage remained uninitialized. This caused Typed property Ssch\T3Messenger\Mailer\MessengerMailer::$sentMessage must not be accessed before initialization even though the email had already been queued successfully.
  3. Reusing the mailer after a synchronous send could expose the previous SentMessage after a queued or failed send.

Changes

  • Read the message and envelope back from the TYPO3 event before queueing, preserving the existing Symfony-event cloning behavior.
  • Initialize the nullable sent-message result to null and reset it at the start of every send attempt.
  • Preserve actual synchronous HandledStamp results and transport exception propagation. Queued submission does not manufacture a synchronous transport result.

Tests

  • Eight event regression cases cover unchanged/replaced messages and added/replaced/removed envelopes.
  • Six result-state cases cover reads before sending, queued sends including after-event listeners, synchronous results, synchronous-to-queued reuse, failed-send reuse and transport exception propagation, and the actual TYPO3 MailMessage::send() path.
  • Five original configuration tests remain green.

Validation

  • Before the result-state fix: three errors reproduce the uninitialized property (including TYPO3 MailMessage), and two failures demonstrate stale results.
  • Complete fork unit suite: 25 tests, 126 assertions, passes against the portal's existing TYPO3 13.4 dependencies on PHP 8.4.
  • Focused PHPStan Level 8 analysis of the mailer and its tests passes.
  • PHP syntax checks pass.
  • The previously reported ECS configuration issue (SetList::SYMPLIFY unavailable in the resolved version) is outside this change; no coding-standard configuration changes are included.

@FlorianX FlorianX changed the title fix: respect message and envelope replacements before queueing fix: respect mail event replacements and initialize queued mail result Oct 28, 2026
MailMessage::send() calls getSentMessage() after submitting an email. With asynchronous Messenger routing no HandledStamp is returned, leaving sentMessage uninitialized and causing an Error although the mail has already been queued.

Initialize the nullable result and reset it before each send attempt to avoid stale synchronous results. Cover queued MailMessage calls, synchronous results, repeated sends, and transport failures.
@FlorianX
FlorianX force-pushed the fix/respect-before-mailer-sent-message-event branch from 239f22b to c6aafab Compare October 28, 2026 08:37
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