From c695695368e73b4cfa660aa700ae7fbeeeae74e7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 24 Jul 2022 18:03:30 +0200 Subject: [PATCH] [Mailer] Add a comment to avoid the same wrong PR over and over again --- src/Symfony/Component/Mailer/Mailer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Component/Mailer/Mailer.php b/src/Symfony/Component/Mailer/Mailer.php index da391da5cfa4..cbdcdf296ef3 100644 --- a/src/Symfony/Component/Mailer/Mailer.php +++ b/src/Symfony/Component/Mailer/Mailer.php @@ -48,6 +48,11 @@ public function send(RawMessage $message, Envelope $envelope = null): void } if (null !== $this->dispatcher) { + // The dispatched event here has `queued` set to `true`; the goal is NOT to render the message, but to let + // listeners do something before a message is sent to the queue. + // We are using a cloned message as we still want to dispatch the **original** message, not the one modified by listeners. + // That's because the listeners will run again when the email is sent via Messenger by the transport (see `AbstractTransport`). + // Listeners should act depending on the `$queued` argument of the `MessageEvent` instance. $clonedMessage = clone $message; $clonedEnvelope = null !== $envelope ? clone $envelope : Envelope::create($clonedMessage); $event = new MessageEvent($clonedMessage, $clonedEnvelope, (string) $this->transport, true);