Skip to content

Commit a211b30

Browse files
authored
Merge pull request #12 from InnoGE/fix-server-error-500-when-save-to-sent-items-is-null
fix server error 500 when save to sent items is null
2 parents 58de8a5 + defcf0f commit a211b30

9 files changed

+14
-31
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ First you need to add a new entry to the mail drivers array in your `config/mail
5353
'address' => env('MAIL_FROM_ADDRESS'),
5454
'name' => env('MAIL_FROM_NAME'),
5555
],
56-
'save_to_sent_items' => env('MAIL_SAVE_TO_SENT_ITEMS'),
56+
'save_to_sent_items' => env('MAIL_SAVE_TO_SENT_ITEMS', false),
5757
],
5858
```
5959

config/msgraph-mail.php

-6
This file was deleted.

phpstan-baseline.neon

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ parameters:
44
message: "#^Parameter \\#1 \\$message of static method Symfony\\\\Component\\\\Mime\\\\MessageConverter\\:\\:toEmail\\(\\) expects Symfony\\\\Component\\\\Mime\\\\Message, Symfony\\\\Component\\\\Mime\\\\RawMessage given\\.$#"
55
count: 1
66
path: src/MicrosoftGraphTransport.php
7+
8+
-
9+
message: "#^Parameter \\#2 \\$html of method InnoGE\\\\LaravelMsGraphMail\\\\MicrosoftGraphTransport\\:\\:prepareAttachments\\(\\) expects string\\|null, resource\\|string\\|null given\\.$#"
10+
count: 1
11+
path: src/MicrosoftGraphTransport.php

src/LaravelMsGraphMailServiceProvider.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public function configurePackage(Package $package): void
1818
* More info: https://github.com/spatie/laravel-package-tools
1919
*/
2020
$package
21-
->name('laravel-msgraph-mail')
22-
->hasConfigFile();
21+
->name('laravel-msgraph-mail');
2322
}
2423

2524
public function boot(): void

src/MicrosoftGraphTransport.php

+2-14
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ protected function doSend(SentMessage $message): void
5252
'sender' => $this->transformEmailAddress($envelope->getSender()),
5353
'attachments' => $attachments,
5454
],
55-
'saveToSentItems' => config('mail.mailers.microsoft-graph.save_to_sent_items', false),
55+
'saveToSentItems' => config('mail.mailers.microsoft-graph.save_to_sent_items', false) ?? false,
5656
];
5757

5858
$this->microsoftGraphApiService->sendMail($this->from, $payload);
5959
}
6060

6161
/**
6262
* @param Collection<Address> $recipients
63-
* @return array
6463
*/
6564
protected function transformEmailAddresses(Collection $recipients): array
6665
{
@@ -69,10 +68,6 @@ protected function transformEmailAddresses(Collection $recipients): array
6968
->toArray();
7069
}
7170

72-
/**
73-
* @param Address $address
74-
* @return array
75-
*/
7671
protected function transformEmailAddress(Address $address): array
7772
{
7873
return [
@@ -83,21 +78,14 @@ protected function transformEmailAddress(Address $address): array
8378
}
8479

8580
/**
86-
* @param Email $email
87-
* @param Envelope $envelope
8881
* @return Collection<Address>
8982
*/
9083
protected function getRecipients(Email $email, Envelope $envelope): Collection
9184
{
9285
return collect($envelope->getRecipients())
93-
->filter(fn (Address $address) => !in_array($address, array_merge($email->getCc(), $email->getBcc()), true));
86+
->filter(fn (Address $address) => ! in_array($address, array_merge($email->getCc(), $email->getBcc()), true));
9487
}
9588

96-
/**
97-
* @param Email $email
98-
* @param string|null $html
99-
* @return array
100-
*/
10189
protected function prepareAttachments(Email $email, ?string $html): array
10290
{
10391
$attachments = [];

src/Services/MicrosoftGraphApiService.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
class MicrosoftGraphApiService
1212
{
1313
public function __construct(protected readonly string $tenantId,
14-
protected readonly string $clientId,
15-
protected readonly string $clientSecret,
16-
protected readonly int $accessTokenTtl
14+
protected readonly string $clientId,
15+
protected readonly string $clientSecret,
16+
protected readonly int $accessTokenTtl
1717
) {
1818
}
1919

tests/MicrosoftGraphTransportTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
'address' => '[email protected]',
2121
'name' => 'Taylor Otwell',
2222
],
23+
'save_to_sent_items' => null,
2324
]);
2425
Config::set('mail.default', 'microsoft-graph');
2526

@@ -318,7 +319,7 @@
318319
'subject' => 'Dev Test',
319320
'body' => [
320321
'contentType' => 'HTML',
321-
'content' => '<b>Test</b><img src="cid:' . $inlineImageContentId . '">'.PHP_EOL,
322+
'content' => '<b>Test</b><img src="cid:'.$inlineImageContentId.'">'.PHP_EOL,
322323
],
323324
'toRecipients' => [
324325
[

tests/Stubs/TestMail.php

-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public function content()
5050

5151
/**
5252
* Get the attachments for the message.
53-
*
54-
* @return array
5553
*/
5654
public function attachments(): array
5755
{

tests/Stubs/TestMailWithInlineImage.php

-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public function content()
5050

5151
/**
5252
* Get the attachments for the message.
53-
*
54-
* @return array
5553
*/
5654
public function attachments(): array
5755
{

0 commit comments

Comments
 (0)