laravel-mailbox icon indicating copy to clipboard operation
laravel-mailbox copied to clipboard

Support for laravel 9

Open samtlewis opened this issue 4 years ago • 6 comments

I saw that the composer.json was updated in master to support Laravel 9 but there are a couple of other changes necessary to support L9 since the Swift Mailer was replaced with the Symfony Mailer.

The Log driver and InboundEmail files needed updates. I implemented to be backward compatible by checking the app()->version() in each instance. I also added a run-tests action to test against L6-9 on php 7.3, 8 and 8.1 I confirmed that all tests failed prior to my changes and they all pass on all supported php/laravel combinations.

samtlewis avatar Mar 12 '22 15:03 samtlewis

@samtlewis @mpociot it will be really helpful if we can merge this asap.

cmanish049 avatar Mar 14 '22 16:03 cmanish049

^ Ditto. I would love to use this on a Laravel 9 app.

toddgoates avatar Apr 08 '22 19:04 toddgoates

@samtlewis have you got this working in production or staging or even local yet? I've pulled it in and all my app does is attempt to forward any email that arrives but it throws this error: Symfony\Component\Mime\Message::setBody(): Argument #1 ($body) must be of type ?Symfony\Component\Mime\Part\AbstractPart, string given

The stacktrace ends with this:

#0 ...snip.../vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php(23): Symfony\\Component\\Mime\\Message->setBody()
#1 ...snip.../vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php(52): Illuminate\\Mail\\Message->forwardCallTo()
#2 ...snip.../vendor/laravel/framework/src/Illuminate/Mail/Message.php(368): Illuminate\\Mail\\Message->forwardDecoratedCallTo()
#3 ...snip.../vendor/beyondcode/laravel-mailbox/src/InboundEmail.php(171): Illuminate\\Mail\\Message->__call()
#4 ...snip.../vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(267): BeyondCode\\Mailbox\\InboundEmail->BeyondCode\\Mailbox\\{closure}()
#5 ...snip.../vendor/laravel/framework/src/Illuminate/Mail/MailManager.php(505): Illuminate\\Mail\\Mailer->send()
#6 ...snip.../vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(337): Illuminate\\Mail\\MailManager->__call()
#7 ...snip.../vendor/beyondcode/laravel-mailbox/src/InboundEmail.php(172): Illuminate\\Support\\Facades\\Facade::__callStatic()
#8 ...snip.../app/Providers/AppServiceProvider.php(119): BeyondCode\\Mailbox\\InboundEmail->forward()

Scratching my head at the moment!

colinmackinlay avatar Apr 23 '22 22:04 colinmackinlay

@samtlewis - I've looked again at the changes you've made and they don't seem quite right. Apologies if I'm missing something obvious.

            if (app()->version() >= 9) {
                $mailable->withSwiftMessage(function (\Swift_Message $message) {
                    $message->getHeaders()->addIdHeader('In-Reply-To', $this->id());
                });
            } else {
                $mailable->withSymfonyMessage(function (\Swift_Message $message) {
                    $message->getHeaders()->addIdHeader('In-Reply-To', $this->id());
                });
            }
  1. Shouldn't the conditional be the other way round? For Laravel 9+ it should be Symfony not Swift?
  2. When calling withSymfonyMessage it won't be a Swift_Message that is passed?

It still doesn't explain my issue with forwarding. At the moment I think we're going to have to wait until @sschlein or @mpociot have time to give the package a Laravel 9 facelift

colinmackinlay avatar Apr 24 '22 08:04 colinmackinlay

@colinmackinlay i believe you are correct. That code is backwards. I am using the ingestion functionality but not reply/forwarding. Probably should have added some tests for that.

samtlewis avatar Apr 24 '22 16:04 samtlewis

@samtlewis implemented in my fork: joelharkes/laravel-mailbox version 3.0.0

joelharkes avatar Aug 11 '22 13:08 joelharkes

Thank you, and sorry that it took so long

mpociot avatar Dec 20 '22 08:12 mpociot