From 76ac0348b59584cffbda5c53fcbca99e7948a67d Mon Sep 17 00:00:00 2001 From: prateek banga Date: Wed, 29 Nov 2023 21:57:06 +0530 Subject: [PATCH 1/6] adds extra param for emaill --- Dockerfile | 2 +- .../Messaging/Adapter/Email/Mailgun.php | 25 ++++++--- src/Utopia/Messaging/Adapter/Email/Mock.php | 2 +- .../Messaging/Adapter/Email/Sendgrid.php | 38 ++++++++++---- src/Utopia/Messaging/Messages/Email.php | 51 +++++++++++++++++-- tests/Messaging/Adapter/Email/EmailTest.php | 8 +-- tests/Messaging/Adapter/Email/MailgunTest.php | 5 +- .../Messaging/Adapter/Email/SendgridTest.php | 5 +- 8 files changed, 108 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index b348ffe9..ce0eb906 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ RUN composer install \ --no-scripts \ --prefer-dist -FROM php:8.1-cli-alpine +FROM php:8.2-cli-alpine WORKDIR /usr/local/src/ diff --git a/src/Utopia/Messaging/Adapter/Email/Mailgun.php b/src/Utopia/Messaging/Adapter/Email/Mailgun.php index 4cb4eccc..93786f4f 100644 --- a/src/Utopia/Messaging/Adapter/Email/Mailgun.php +++ b/src/Utopia/Messaging/Adapter/Email/Mailgun.php @@ -45,6 +45,22 @@ protected function process(EmailMessage $message): string $domain = $this->isEU ? $euDomain : $usDomain; + $body = [ + 'to' => \implode(',', $message->getTo()), + 'from' => "{$message->getFrom()}<{$message->getSenderEmailAddress()}>", + 'subject' => $message->getSubject(), + 'text' => $message->isHtml() ? null : $message->getContent(), + 'html' => $message->isHtml() ? $message->getContent() : null, + ]; + + if (! \is_null($message->getCcName()) && ! \is_null($message->getCcEmail())) { + $body['cc'] = "{$message->getCcName()}<{$message->getCcEmail()}>"; + } + + if (! \is_null($message->getBccName()) && ! \is_null($message->getBccEmail())) { + $body['bcc'] = "{$message->getBccName()}<{$message->getBccEmail()}>"; + } + $response = new Response($this->getType()); $result = $this->request( @@ -52,14 +68,9 @@ protected function process(EmailMessage $message): string url: "https://$domain/v3/{$this->domain}/messages", headers: [ 'Authorization: Basic '.base64_encode('api:'.$this->apiKey), + 'h:Reply-To: '.$message->getReplyTo(), ], - body: \http_build_query([ - 'to' => \implode(',', $message->getTo()), - 'from' => $message->getFrom(), - 'subject' => $message->getSubject(), - 'text' => $message->isHtml() ? null : $message->getContent(), - 'html' => $message->isHtml() ? $message->getContent() : null, - ]), + body: \http_build_query($body), ); $statusCode = $result['statusCode']; diff --git a/src/Utopia/Messaging/Adapter/Email/Mock.php b/src/Utopia/Messaging/Adapter/Email/Mock.php index 079700e4..2f01cc1d 100644 --- a/src/Utopia/Messaging/Adapter/Email/Mock.php +++ b/src/Utopia/Messaging/Adapter/Email/Mock.php @@ -40,7 +40,7 @@ protected function process(EmailMessage $message): string $mail->Subject = $message->getSubject(); $mail->Body = $message->getContent(); $mail->AltBody = \strip_tags($message->getContent()); - $mail->setFrom($message->getFrom(), 'Utopia'); + $mail->setFrom($message->getSenderEmailAddress(), 'Utopia'); $mail->addReplyTo($message->getFrom(), 'Utopia'); $mail->isHTML($message->isHtml()); diff --git a/src/Utopia/Messaging/Adapter/Email/Sendgrid.php b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php index 6d06fce9..c8a099ad 100644 --- a/src/Utopia/Messaging/Adapter/Email/Sendgrid.php +++ b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php @@ -37,6 +37,30 @@ public function getMaxMessagesPerRequest(): int */ protected function process(EmailMessage $message): string { + $personalizations = [ + [ + 'to' => \array_map( + fn ($to) => ['email' => $to], + $message->getTo() + ), + 'subject' => $message->getSubject(), + ], + ]; + + if (! \is_null($message->getCcName()) && ! \is_null($message->getCcEmail())) { + $personalizations[0]['cc'] = [ + 'name' => $message->getCcName(), + 'email' => $message->getCcEmail(), + ]; + } + + if (! \is_null($message->getBccName()) && ! \is_null($message->getBccEmail())) { + $personalizations[0]['bcc'] = [ + 'name' => $message->getBccName(), + 'email' => $message->getBccEmail(), + ]; + } + $response = new Response($this->getType()); $result = $this->request( method: 'POST', @@ -46,17 +70,13 @@ protected function process(EmailMessage $message): string 'Content-Type: application/json', ], body: \json_encode([ - 'personalizations' => [ - [ - 'to' => \array_map( - fn ($to) => ['email' => $to], - $message->getTo() - ), - 'subject' => $message->getSubject(), - ], + 'personalizations' => $personalizations, + 'reply_to' => [ + 'email' => $message->getReplyTo(), ], 'from' => [ - 'email' => $message->getFrom(), + 'name' => $message->getFrom(), + 'email' => $message->getSenderEmailAddress(), ], 'content' => [ [ diff --git a/src/Utopia/Messaging/Messages/Email.php b/src/Utopia/Messaging/Messages/Email.php index 8e79c10c..aaee9dd8 100644 --- a/src/Utopia/Messaging/Messages/Email.php +++ b/src/Utopia/Messaging/Messages/Email.php @@ -10,7 +10,13 @@ class Email implements Message * @param array $to The recipients of the email. * @param string $subject The subject of the email. * @param string $content The content of the email. - * @param string|null $from The sender of the email. + * @param string $from The name of sender. + * @param string $senderEmailAddress The email address of sender. + * @param string|null $ccName The CC Name of the email. + * @param string|null $ccEmail The CC Email of the email. + * @param string|null $bccName The BCC Name of the email. + * @param string|null $bccEmail The BCC Email of the email. + * @param string $replyTo The reply to of the email. * @param array|null $attachments The attachments of the email. * @param bool $html Whether the message is HTML or not. */ @@ -18,10 +24,19 @@ public function __construct( private array $to, private string $subject, private string $content, - private ?string $from = null, + private string $from, + private string $senderEmailAddress, + private ?string $replyTo = null, + private ?string $ccName = null, + private ?string $ccEmail = null, + private ?string $bccName = null, + private ?string $bccEmail = null, private ?array $attachments = null, private bool $html = false ) { + if (\is_null($this->replyTo)) { + $this->replyTo = $this->senderEmailAddress; + } } /** @@ -42,11 +57,41 @@ public function getContent(): string return $this->content; } - public function getFrom(): ?string + public function getFrom(): string { return $this->from; } + public function getSenderEmailAddress(): string + { + return $this->senderEmailAddress; + } + + public function getReplyTo(): string + { + return $this->replyTo; + } + + public function getCcName(): ?string + { + return $this->ccName; + } + + public function getCcEmail(): ?string + { + return $this->ccEmail; + } + + public function getBccName(): ?string + { + return $this->bccName; + } + + public function getBccEmail(): ?string + { + return $this->bccEmail; + } + /** * @return array|null */ diff --git a/tests/Messaging/Adapter/Email/EmailTest.php b/tests/Messaging/Adapter/Email/EmailTest.php index 25069992..c4013e40 100644 --- a/tests/Messaging/Adapter/Email/EmailTest.php +++ b/tests/Messaging/Adapter/Email/EmailTest.php @@ -15,13 +15,15 @@ public function testSendEmail(): void $to = 'tester@localhost.test'; $subject = 'Test Subject'; $content = 'Test Content'; - $from = 'sender@localhost.test'; + $from = 'Test Sender'; + $senderEmailAddress = 'sender@localhost.test'; $message = new Email( to: [$to], subject: $subject, content: $content, - from: $from + from: $from, + senderEmailAddress: $senderEmailAddress, ); $response = \json_decode($sender->send($message), true); @@ -30,7 +32,7 @@ public function testSendEmail(): void $this->assertResponse($response); $this->assertEquals($to, $lastEmail['to'][0]['address']); - $this->assertEquals($from, $lastEmail['from'][0]['address']); + $this->assertEquals($senderEmailAddress, $lastEmail['from'][0]['address']); $this->assertEquals($subject, $lastEmail['subject']); $this->assertEquals($content, \trim($lastEmail['text'])); } diff --git a/tests/Messaging/Adapter/Email/MailgunTest.php b/tests/Messaging/Adapter/Email/MailgunTest.php index d9f6d550..2b09a195 100644 --- a/tests/Messaging/Adapter/Email/MailgunTest.php +++ b/tests/Messaging/Adapter/Email/MailgunTest.php @@ -22,13 +22,14 @@ public function testSendEmail(): void $to = \getenv('TEST_EMAIL'); $subject = 'Test Subject'; $content = 'Test Content'; - $from = 'sender@'.$domain; + $senderEmailAddress = 'sender@'.$domain; $message = new Email( to: [$to], subject: $subject, content: $content, - from: $from, + from: 'Test Sender', + senderEmailAddress: $senderEmailAddress, ); $response = (array) \json_decode($sender->send($message), true); diff --git a/tests/Messaging/Adapter/Email/SendgridTest.php b/tests/Messaging/Adapter/Email/SendgridTest.php index bcad2c38..e6261a78 100644 --- a/tests/Messaging/Adapter/Email/SendgridTest.php +++ b/tests/Messaging/Adapter/Email/SendgridTest.php @@ -16,13 +16,14 @@ public function testSendEmail(): void $to = \getenv('TEST_EMAIL'); $subject = 'Test Subject'; $content = 'Test Content'; - $from = \getenv('TEST_FROM_EMAIL'); + $senderEmailAddress = \getenv('TEST_FROM_EMAIL'); $message = new Email( to: [$to], subject: $subject, content: $content, - from: $from, + from: 'prateek', + senderEmailAddress: $senderEmailAddress, ); $response = \json_decode($sender->send($message), true); From 9559e91d4fba6bdd7b211f17f8bff64ae79bb32b Mon Sep 17 00:00:00 2001 From: prateek banga Date: Thu, 30 Nov 2023 15:22:40 +0530 Subject: [PATCH 2/6] makes bcc and cc as array, adds reply name in replyto --- .../Messaging/Adapter/Email/Mailgun.php | 16 ++-- src/Utopia/Messaging/Adapter/Email/Mock.php | 4 +- .../Messaging/Adapter/Email/Sendgrid.php | 31 ++++--- src/Utopia/Messaging/Messages/Email.php | 85 ++++++++++++------- tests/Messaging/Adapter/Email/EmailTest.php | 10 +-- tests/Messaging/Adapter/Email/MailgunTest.php | 6 +- .../Messaging/Adapter/Email/SendgridTest.php | 6 +- 7 files changed, 93 insertions(+), 65 deletions(-) diff --git a/src/Utopia/Messaging/Adapter/Email/Mailgun.php b/src/Utopia/Messaging/Adapter/Email/Mailgun.php index 93786f4f..fda3e29c 100644 --- a/src/Utopia/Messaging/Adapter/Email/Mailgun.php +++ b/src/Utopia/Messaging/Adapter/Email/Mailgun.php @@ -47,18 +47,22 @@ protected function process(EmailMessage $message): string $body = [ 'to' => \implode(',', $message->getTo()), - 'from' => "{$message->getFrom()}<{$message->getSenderEmailAddress()}>", + 'from' => "{$message->getFromName()}<{$message->getFromEmail()}>", 'subject' => $message->getSubject(), 'text' => $message->isHtml() ? null : $message->getContent(), 'html' => $message->isHtml() ? $message->getContent() : null, ]; - if (! \is_null($message->getCcName()) && ! \is_null($message->getCcEmail())) { - $body['cc'] = "{$message->getCcName()}<{$message->getCcEmail()}>"; + if (! \is_null($message->getCC())) { + foreach ($message->getCC() as $cc) { + $body['cc'] = "{$body['cc']},{$cc['name']}<{$cc['email']}>"; + } } - if (! \is_null($message->getBccName()) && ! \is_null($message->getBccEmail())) { - $body['bcc'] = "{$message->getBccName()}<{$message->getBccEmail()}>"; + if (! \is_null($message->getBCC())) { + foreach ($message->getBCC() as $bcc) { + $body['bcc'] = "{$body['bcc']},{$bcc['name']}<{$bcc['email']}>"; + } } $response = new Response($this->getType()); @@ -68,7 +72,7 @@ protected function process(EmailMessage $message): string url: "https://$domain/v3/{$this->domain}/messages", headers: [ 'Authorization: Basic '.base64_encode('api:'.$this->apiKey), - 'h:Reply-To: '.$message->getReplyTo(), + 'h:Reply-To: '."{$message->getReplyToName()}<{$message->getReplyToEmail()}>", ], body: \http_build_query($body), ); diff --git a/src/Utopia/Messaging/Adapter/Email/Mock.php b/src/Utopia/Messaging/Adapter/Email/Mock.php index 2f01cc1d..ebf759ed 100644 --- a/src/Utopia/Messaging/Adapter/Email/Mock.php +++ b/src/Utopia/Messaging/Adapter/Email/Mock.php @@ -40,8 +40,8 @@ protected function process(EmailMessage $message): string $mail->Subject = $message->getSubject(); $mail->Body = $message->getContent(); $mail->AltBody = \strip_tags($message->getContent()); - $mail->setFrom($message->getSenderEmailAddress(), 'Utopia'); - $mail->addReplyTo($message->getFrom(), 'Utopia'); + $mail->setFrom($message->getFromEmail(), $message->getFromName()); + $mail->addReplyTo($message->getReplyToEmail(), $message->getReplyToName()); $mail->isHTML($message->isHtml()); foreach ($message->getTo() as $to) { diff --git a/src/Utopia/Messaging/Adapter/Email/Sendgrid.php b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php index c8a099ad..db6ef4bc 100644 --- a/src/Utopia/Messaging/Adapter/Email/Sendgrid.php +++ b/src/Utopia/Messaging/Adapter/Email/Sendgrid.php @@ -47,18 +47,22 @@ protected function process(EmailMessage $message): string ], ]; - if (! \is_null($message->getCcName()) && ! \is_null($message->getCcEmail())) { - $personalizations[0]['cc'] = [ - 'name' => $message->getCcName(), - 'email' => $message->getCcEmail(), - ]; + if (! \is_null($message->getCC())) { + foreach ($message->getCC() as $cc) { + $personalizations[0]['cc'][] = [ + 'name' => $cc['name'], + 'email' => $cc['email'], + ]; + } } - if (! \is_null($message->getBccName()) && ! \is_null($message->getBccEmail())) { - $personalizations[0]['bcc'] = [ - 'name' => $message->getBccName(), - 'email' => $message->getBccEmail(), - ]; + if (! \is_null($message->getBCC())) { + foreach ($message->getBCC() as $bcc) { + $personalizations[0]['bcc'][] = [ + 'name' => $bcc['name'], + 'email' => $bcc['email'], + ]; + } } $response = new Response($this->getType()); @@ -72,11 +76,12 @@ protected function process(EmailMessage $message): string body: \json_encode([ 'personalizations' => $personalizations, 'reply_to' => [ - 'email' => $message->getReplyTo(), + 'name' => $message->getReplyToName(), + 'email' => $message->getReplyToEmail(), ], 'from' => [ - 'name' => $message->getFrom(), - 'email' => $message->getSenderEmailAddress(), + 'name' => $message->getFromName(), + 'email' => $message->getFromEmail(), ], 'content' => [ [ diff --git a/src/Utopia/Messaging/Messages/Email.php b/src/Utopia/Messaging/Messages/Email.php index aaee9dd8..b2819e3b 100644 --- a/src/Utopia/Messaging/Messages/Email.php +++ b/src/Utopia/Messaging/Messages/Email.php @@ -10,13 +10,12 @@ class Email implements Message * @param array $to The recipients of the email. * @param string $subject The subject of the email. * @param string $content The content of the email. - * @param string $from The name of sender. - * @param string $senderEmailAddress The email address of sender. - * @param string|null $ccName The CC Name of the email. - * @param string|null $ccEmail The CC Email of the email. - * @param string|null $bccName The BCC Name of the email. - * @param string|null $bccEmail The BCC Email of the email. - * @param string $replyTo The reply to of the email. + * @param string $fromName The name of the sender. + * @param string $fromEmail The email address of the sender. + * @param array>|null $cc . The CC recipients of the email. Each recipient should be an array containing a "name" and an "email" key. + * @param array>|null $bcc . The BCC recipients of the email. Each recipient should be an array containing a "name" and an "email" key. + * @param string|null $replyToName The name of the reply to. + * @param string|null $replyToEmail The email address of the reply to. * @param array|null $attachments The attachments of the email. * @param bool $html Whether the message is HTML or not. */ @@ -24,18 +23,37 @@ public function __construct( private array $to, private string $subject, private string $content, - private string $from, - private string $senderEmailAddress, - private ?string $replyTo = null, - private ?string $ccName = null, - private ?string $ccEmail = null, - private ?string $bccName = null, - private ?string $bccEmail = null, + private string $fromName, + private string $fromEmail, + private ?string $replyToName = null, + private ?string $replyToEmail = null, + private ?array $cc = null, + private ?array $bcc = null, private ?array $attachments = null, private bool $html = false ) { - if (\is_null($this->replyTo)) { - $this->replyTo = $this->senderEmailAddress; + if (\is_null($this->replyToName)) { + $this->replyToName = $this->fromName; + } + + if (\is_null($this->replyToEmail)) { + $this->replyToEmail = $this->fromEmail; + } + + if (! \is_null($this->cc)) { + foreach ($this->cc as $recipient) { + if (! isset($recipient['name']) || ! isset($recipient['email'])) { + throw new \InvalidArgumentException('Each recipient in cc must have a name and email'); + } + } + } + + if (! \is_null($this->bcc)) { + foreach ($this->bcc as $recipient) { + if (! isset($recipient['name']) || ! isset($recipient['email'])) { + throw new \InvalidArgumentException('Each recipient in bcc must have a name and email'); + } + } } } @@ -57,39 +75,40 @@ public function getContent(): string return $this->content; } - public function getFrom(): string + public function getFromName(): string { - return $this->from; + return $this->fromName; } - public function getSenderEmailAddress(): string + public function getFromEmail(): string { - return $this->senderEmailAddress; + return $this->fromEmail; } - public function getReplyTo(): string + public function getReplyToName(): string { - return $this->replyTo; + return $this->replyToName; } - public function getCcName(): ?string + public function getReplyToEmail(): string { - return $this->ccName; + return $this->replyToEmail; } - public function getCcEmail(): ?string - { - return $this->ccEmail; - } - - public function getBccName(): ?string + /** + * @return array>|null + */ + public function getCC(): ?array { - return $this->bccName; + return $this->cc; } - public function getBccEmail(): ?string + /** + * @return array>|null + */ + public function getBCC(): ?array { - return $this->bccEmail; + return $this->bcc; } /** diff --git a/tests/Messaging/Adapter/Email/EmailTest.php b/tests/Messaging/Adapter/Email/EmailTest.php index c4013e40..1b168c2d 100644 --- a/tests/Messaging/Adapter/Email/EmailTest.php +++ b/tests/Messaging/Adapter/Email/EmailTest.php @@ -15,15 +15,15 @@ public function testSendEmail(): void $to = 'tester@localhost.test'; $subject = 'Test Subject'; $content = 'Test Content'; - $from = 'Test Sender'; - $senderEmailAddress = 'sender@localhost.test'; + $fromName = 'Test Sender'; + $fromEmail = 'sender@localhost.test'; $message = new Email( to: [$to], subject: $subject, content: $content, - from: $from, - senderEmailAddress: $senderEmailAddress, + fromName: $fromName, + fromEmail: $fromEmail, ); $response = \json_decode($sender->send($message), true); @@ -32,7 +32,7 @@ public function testSendEmail(): void $this->assertResponse($response); $this->assertEquals($to, $lastEmail['to'][0]['address']); - $this->assertEquals($senderEmailAddress, $lastEmail['from'][0]['address']); + $this->assertEquals($fromEmail, $lastEmail['from'][0]['address']); $this->assertEquals($subject, $lastEmail['subject']); $this->assertEquals($content, \trim($lastEmail['text'])); } diff --git a/tests/Messaging/Adapter/Email/MailgunTest.php b/tests/Messaging/Adapter/Email/MailgunTest.php index f0d92004..128c490a 100644 --- a/tests/Messaging/Adapter/Email/MailgunTest.php +++ b/tests/Messaging/Adapter/Email/MailgunTest.php @@ -22,14 +22,14 @@ public function testSendEmail(): void $to = \getenv('TEST_EMAIL'); $subject = 'Test Subject'; $content = 'Test Content'; - $senderEmailAddress = 'sender@'.$domain; + $fromEmail = 'sender@'.$domain; $message = new Email( to: [$to], subject: $subject, content: $content, - from: 'Test Sender', - senderEmailAddress: $senderEmailAddress, + fromName: 'Test Sender', + fromEmail: $fromEmail, ); $response = \json_decode($sender->send($message), true); diff --git a/tests/Messaging/Adapter/Email/SendgridTest.php b/tests/Messaging/Adapter/Email/SendgridTest.php index e6261a78..9cef0cce 100644 --- a/tests/Messaging/Adapter/Email/SendgridTest.php +++ b/tests/Messaging/Adapter/Email/SendgridTest.php @@ -16,14 +16,14 @@ public function testSendEmail(): void $to = \getenv('TEST_EMAIL'); $subject = 'Test Subject'; $content = 'Test Content'; - $senderEmailAddress = \getenv('TEST_FROM_EMAIL'); + $fromEmail = \getenv('TEST_FROM_EMAIL'); $message = new Email( to: [$to], subject: $subject, content: $content, - from: 'prateek', - senderEmailAddress: $senderEmailAddress, + fromName: 'prateek', + fromEmail: $fromEmail, ); $response = \json_decode($sender->send($message), true); From 35ea33082df1a9bc19f295a2948d1179db192c7e Mon Sep 17 00:00:00 2001 From: prateek banga Date: Thu, 30 Nov 2023 15:24:51 +0530 Subject: [PATCH 3/6] lint fixl --- src/Utopia/Messaging/Messages/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utopia/Messaging/Messages/Email.php b/src/Utopia/Messaging/Messages/Email.php index b2819e3b..edd17503 100644 --- a/src/Utopia/Messaging/Messages/Email.php +++ b/src/Utopia/Messaging/Messages/Email.php @@ -40,7 +40,7 @@ public function __construct( $this->replyToEmail = $this->fromEmail; } - if (! \is_null($this->cc)) { + if (!\is_null($this->cc)) { foreach ($this->cc as $recipient) { if (! isset($recipient['name']) || ! isset($recipient['email'])) { throw new \InvalidArgumentException('Each recipient in cc must have a name and email'); @@ -48,7 +48,7 @@ public function __construct( } } - if (! \is_null($this->bcc)) { + if (!\is_null($this->bcc)) { foreach ($this->bcc as $recipient) { if (! isset($recipient['name']) || ! isset($recipient['email'])) { throw new \InvalidArgumentException('Each recipient in bcc must have a name and email'); From 9b910645393a21dec4f01b7aeb02f77d549d5243 Mon Sep 17 00:00:00 2001 From: prateek banga Date: Thu, 30 Nov 2023 15:25:48 +0530 Subject: [PATCH 4/6] updated docs for email constructor --- src/Utopia/Messaging/Messages/Email.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Utopia/Messaging/Messages/Email.php b/src/Utopia/Messaging/Messages/Email.php index edd17503..3de05483 100644 --- a/src/Utopia/Messaging/Messages/Email.php +++ b/src/Utopia/Messaging/Messages/Email.php @@ -18,6 +18,7 @@ class Email implements Message * @param string|null $replyToEmail The email address of the reply to. * @param array|null $attachments The attachments of the email. * @param bool $html Whether the message is HTML or not. + * @throws \InvalidArgumentException */ public function __construct( private array $to, From d3b544c8429127bdc53ddce7de1f12d92a0dfcb5 Mon Sep 17 00:00:00 2001 From: prateek banga Date: Thu, 30 Nov 2023 15:26:56 +0530 Subject: [PATCH 5/6] lint fix --- src/Utopia/Messaging/Messages/Email.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Utopia/Messaging/Messages/Email.php b/src/Utopia/Messaging/Messages/Email.php index 3de05483..268a4dde 100644 --- a/src/Utopia/Messaging/Messages/Email.php +++ b/src/Utopia/Messaging/Messages/Email.php @@ -18,6 +18,7 @@ class Email implements Message * @param string|null $replyToEmail The email address of the reply to. * @param array|null $attachments The attachments of the email. * @param bool $html Whether the message is HTML or not. + * * @throws \InvalidArgumentException */ public function __construct( @@ -41,7 +42,7 @@ public function __construct( $this->replyToEmail = $this->fromEmail; } - if (!\is_null($this->cc)) { + if (! \is_null($this->cc)) { foreach ($this->cc as $recipient) { if (! isset($recipient['name']) || ! isset($recipient['email'])) { throw new \InvalidArgumentException('Each recipient in cc must have a name and email'); @@ -49,7 +50,7 @@ public function __construct( } } - if (!\is_null($this->bcc)) { + if (! \is_null($this->bcc)) { foreach ($this->bcc as $recipient) { if (! isset($recipient['name']) || ! isset($recipient['email'])) { throw new \InvalidArgumentException('Each recipient in bcc must have a name and email'); From 6abbb72b74924d16d68f6f4d6d0f5cf2b05e7172 Mon Sep 17 00:00:00 2001 From: Prateek Banga Date: Mon, 4 Dec 2023 16:28:27 +0100 Subject: [PATCH 6/6] adds fromArray method in response --- src/Utopia/Messaging/Response.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Utopia/Messaging/Response.php b/src/Utopia/Messaging/Response.php index 6372ab58..3b929151 100644 --- a/src/Utopia/Messaging/Response.php +++ b/src/Utopia/Messaging/Response.php @@ -78,4 +78,16 @@ public function toArray(): array 'results' => $this->results, ]; } + + /** + * @param array> $results + */ + public function fromArray(array $results): self + { + $response = new self($this->type); + $response->deliveredTo = $this->deliveredTo; + $response->results = $this->results; + + return $response; + } }