[5.6] Reorder message customization callbacks #22995
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Call developer-supplied callbacks in
Mailer
andMailable
a bit earlier, to allow customization of created message body and attachments.Body and attachments of SwiftMailer messages are opaque encoded blobs, which makes them hard to customize after creation. This PR ensures that callbacks, registered by
withSwiftMessage
, are executed at earlier point, before SwiftMailer message emits it's body. This enables setting email encoder (8bit/base64 etc.) and other customization of message body.The change isn't particularly disrupting, because current implementation does not allow to modify the message at all, aside from setting headers. While it's theoretically possible to interact with message from the callback by breaking encapsulation and/or converting full message to string, a brief look at uses of
withSwiftMessage
in public Github project and Laravel documentation shows that all of them are limited to fiddling with email headers and adding attachments.Fixes #22982