-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.6] Reorder message customization callbacks #22995
Conversation
This change seems to have affected our production code that was previously working great in 5.5. I would send an email, then use the withSwiftMailer callback to get a copy of the message, then use IMAP to copy the sent email to my bosses 'Sent' folder for his email address. Here was the code I was using:
After this merge, $mailString just has the headers, no body. How do I go about getting the full email so I can send it off using IMAP? |
@domanb there seem to be several hooks, that allow to intercept complete message being sent. MessageSending looks particularly promising. Prior to this change there have been no way to modify a message body before it is built. |
Great, thanks Alexander, I'll look into that and see if I can make something work. I put a hacky workaround in place for now, but it's pretty fragile, this looks much more promising. Cheers! |
Accomplishes this by firing the message callback before content is added to the message. This fixes an issue where subjects set on the message object through the callback were not able to override a mail template's subject as they're supposed to in System\Classes\MailManager because the callback was called after the MailManager's listener for mailer.beforeAddContent had already fired. The original issue was reported and fixed in octobercms/october#1665. However, that fix was then later broken by f409ad4 which was for the L5.5 upgrade in Build 420. It's also worth noting that Laravel has moved the callback to be before the content is added starting in L5.6, so this change also brings us closer in line with Laravel for the future 6.0 upgrade (see laravel/framework#22995 for that commit and background information).
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