From de3b0d0bb15b33e3d2b8cfaac8161cff6aa231c0 Mon Sep 17 00:00:00 2001 From: Tim Geisendoerfer Date: Sun, 5 Nov 2023 15:58:47 +0100 Subject: [PATCH] fix server error 500 when save to sent items is null --- README.md | 2 +- config/msgraph-mail.php | 6 ------ src/LaravelMsGraphMailServiceProvider.php | 3 +-- src/MicrosoftGraphTransport.php | 16 ++-------------- src/Services/MicrosoftGraphApiService.php | 6 +++--- tests/MicrosoftGraphTransportTest.php | 3 ++- tests/Stubs/TestMail.php | 2 -- tests/Stubs/TestMailWithInlineImage.php | 2 -- 8 files changed, 9 insertions(+), 31 deletions(-) delete mode 100644 config/msgraph-mail.php diff --git a/README.md b/README.md index df299b9..86f61fc 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ First you need to add a new entry to the mail drivers array in your `config/mail 'address' => env('MAIL_FROM_ADDRESS'), 'name' => env('MAIL_FROM_NAME'), ], - 'save_to_sent_items' => env('MAIL_SAVE_TO_SENT_ITEMS'), + 'save_to_sent_items' => env('MAIL_SAVE_TO_SENT_ITEMS', false), ], ``` diff --git a/config/msgraph-mail.php b/config/msgraph-mail.php deleted file mode 100644 index e4571c5..0000000 --- a/config/msgraph-mail.php +++ /dev/null @@ -1,6 +0,0 @@ -name('laravel-msgraph-mail') - ->hasConfigFile(); + ->name('laravel-msgraph-mail'); } public function boot(): void diff --git a/src/MicrosoftGraphTransport.php b/src/MicrosoftGraphTransport.php index 1e82dda..ad9c7ef 100644 --- a/src/MicrosoftGraphTransport.php +++ b/src/MicrosoftGraphTransport.php @@ -52,7 +52,7 @@ protected function doSend(SentMessage $message): void 'sender' => $this->transformEmailAddress($envelope->getSender()), 'attachments' => $attachments, ], - 'saveToSentItems' => config('mail.mailers.microsoft-graph.save_to_sent_items', false), + 'saveToSentItems' => config('mail.mailers.microsoft-graph.save_to_sent_items', false) ?? false, ]; $this->microsoftGraphApiService->sendMail($this->from, $payload); @@ -60,7 +60,6 @@ protected function doSend(SentMessage $message): void /** * @param Collection
$recipients - * @return array */ protected function transformEmailAddresses(Collection $recipients): array { @@ -69,10 +68,6 @@ protected function transformEmailAddresses(Collection $recipients): array ->toArray(); } - /** - * @param Address $address - * @return array - */ protected function transformEmailAddress(Address $address): array { return [ @@ -83,21 +78,14 @@ protected function transformEmailAddress(Address $address): array } /** - * @param Email $email - * @param Envelope $envelope * @return Collection
*/ protected function getRecipients(Email $email, Envelope $envelope): Collection { return collect($envelope->getRecipients()) - ->filter(fn (Address $address) => !in_array($address, array_merge($email->getCc(), $email->getBcc()), true)); + ->filter(fn (Address $address) => ! in_array($address, array_merge($email->getCc(), $email->getBcc()), true)); } - /** - * @param Email $email - * @param string|null $html - * @return array - */ protected function prepareAttachments(Email $email, ?string $html): array { $attachments = []; diff --git a/src/Services/MicrosoftGraphApiService.php b/src/Services/MicrosoftGraphApiService.php index cde8a34..c65b20e 100644 --- a/src/Services/MicrosoftGraphApiService.php +++ b/src/Services/MicrosoftGraphApiService.php @@ -11,9 +11,9 @@ class MicrosoftGraphApiService { public function __construct(protected readonly string $tenantId, - protected readonly string $clientId, - protected readonly string $clientSecret, - protected readonly int $accessTokenTtl + protected readonly string $clientId, + protected readonly string $clientSecret, + protected readonly int $accessTokenTtl ) { } diff --git a/tests/MicrosoftGraphTransportTest.php b/tests/MicrosoftGraphTransportTest.php index db7f6af..dba0ba9 100644 --- a/tests/MicrosoftGraphTransportTest.php +++ b/tests/MicrosoftGraphTransportTest.php @@ -20,6 +20,7 @@ 'address' => 'taylor@laravel.com', 'name' => 'Taylor Otwell', ], + 'save_to_sent_items' => null, ]); Config::set('mail.default', 'microsoft-graph'); @@ -318,7 +319,7 @@ 'subject' => 'Dev Test', 'body' => [ 'contentType' => 'HTML', - 'content' => 'Test'.PHP_EOL, + 'content' => 'Test'.PHP_EOL, ], 'toRecipients' => [ [ diff --git a/tests/Stubs/TestMail.php b/tests/Stubs/TestMail.php index 0054df1..7a05440 100644 --- a/tests/Stubs/TestMail.php +++ b/tests/Stubs/TestMail.php @@ -50,8 +50,6 @@ public function content() /** * Get the attachments for the message. - * - * @return array */ public function attachments(): array { diff --git a/tests/Stubs/TestMailWithInlineImage.php b/tests/Stubs/TestMailWithInlineImage.php index 39a29f2..f22f305 100644 --- a/tests/Stubs/TestMailWithInlineImage.php +++ b/tests/Stubs/TestMailWithInlineImage.php @@ -50,8 +50,6 @@ public function content() /** * Get the attachments for the message. - * - * @return array */ public function attachments(): array {