Add a mail() hook to NativeMailHandler. #1948
Open
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.
The existing call to the global mail() function in NativeMailHandler::send() is replaced with a call to a protected method NativeMailHandler::mail() that takes the same parameters. The provided implementation of NativeMailHandler::mail() passes through to the global mail() function, leaving existing behavior completely unchanged.
This allows subclassing NativeMailHandler so that the call to mail() can be replaced in cases where additional processing needs to happen.
Tests are mostly updated to use this method to test sent messages, but one test is added to make sure that everything gets passed through intact in the default case.
I have run into a number of cases specific to FreeBSD 14+ where its new native mailer (dma) often rejects messages generated by Monolog. The added functionality makes it much easier to shim in the needed adjustments without having to maintain an entire local copy of NativeMailHandler to alter one line.
This approach would also allow for other more general post-processing of outbound messages if needed.
Thanks!