Skip to content
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

fix server error 500 when save to sent items is null #12

Merged
merged 3 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
```

Expand Down
6 changes: 0 additions & 6 deletions config/msgraph-mail.php

This file was deleted.

5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ parameters:
message: "#^Parameter \\#1 \\$message of static method Symfony\\\\Component\\\\Mime\\\\MessageConverter\\:\\:toEmail\\(\\) expects Symfony\\\\Component\\\\Mime\\\\Message, Symfony\\\\Component\\\\Mime\\\\RawMessage given\\.$#"
count: 1
path: src/MicrosoftGraphTransport.php

-
message: "#^Parameter \\#2 \\$html of method InnoGE\\\\LaravelMsGraphMail\\\\MicrosoftGraphTransport\\:\\:prepareAttachments\\(\\) expects string\\|null, resource\\|string\\|null given\\.$#"
count: 1
path: src/MicrosoftGraphTransport.php
3 changes: 1 addition & 2 deletions src/LaravelMsGraphMailServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public function configurePackage(Package $package): void
* More info: https://github.com/spatie/laravel-package-tools
*/
$package
->name('laravel-msgraph-mail')
->hasConfigFile();
->name('laravel-msgraph-mail');
}

public function boot(): void
Expand Down
16 changes: 2 additions & 14 deletions src/MicrosoftGraphTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ 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);
}

/**
* @param Collection<Address> $recipients
* @return array
*/
protected function transformEmailAddresses(Collection $recipients): array
{
Expand All @@ -69,10 +68,6 @@ protected function transformEmailAddresses(Collection $recipients): array
->toArray();
}

/**
* @param Address $address
* @return array
*/
protected function transformEmailAddress(Address $address): array
{
return [
Expand All @@ -83,21 +78,14 @@ protected function transformEmailAddress(Address $address): array
}

/**
* @param Email $email
* @param Envelope $envelope
* @return Collection<Address>
*/
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 = [];
Expand Down
6 changes: 3 additions & 3 deletions src/Services/MicrosoftGraphApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

Expand Down
3 changes: 2 additions & 1 deletion tests/MicrosoftGraphTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'address' => '[email protected]',
'name' => 'Taylor Otwell',
],
'save_to_sent_items' => null,
]);
Config::set('mail.default', 'microsoft-graph');

Expand Down Expand Up @@ -318,7 +319,7 @@
'subject' => 'Dev Test',
'body' => [
'contentType' => 'HTML',
'content' => '<b>Test</b><img src="cid:' . $inlineImageContentId . '">'.PHP_EOL,
'content' => '<b>Test</b><img src="cid:'.$inlineImageContentId.'">'.PHP_EOL,
],
'toRecipients' => [
[
Expand Down
2 changes: 0 additions & 2 deletions tests/Stubs/TestMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public function content()

/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments(): array
{
Expand Down
2 changes: 0 additions & 2 deletions tests/Stubs/TestMailWithInlineImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public function content()

/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments(): array
{
Expand Down