From 0cb822a1d0971ac53253be6ee37123932841bd49 Mon Sep 17 00:00:00 2001 From: ey-mailosaur Date: Thu, 19 Dec 2024 12:24:22 +0000 Subject: [PATCH] Added CC property to message option models Including Create, Forward and Reply --- src/Models/MessageCreateOptions.php | 6 +++ src/Models/MessageForwardOptions.php | 6 +++ src/Models/MessageReplyOptions.php | 6 +++ tests/EmailsTests.php | 62 ++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) diff --git a/src/Models/MessageCreateOptions.php b/src/Models/MessageCreateOptions.php index aeebfb6..7b3b46c 100644 --- a/src/Models/MessageCreateOptions.php +++ b/src/Models/MessageCreateOptions.php @@ -10,6 +10,11 @@ class MessageCreateOptions */ public $to = null; + /** + * @var string The email address to which the email will be CC'd. + */ + public $cc = null; + /** * @var string Partially overrides of the message's 'from' address. This **must** be an address ending * with `YOUR_SERVER.mailosaur.net`, such as `my-emails @a1bcdef2.mailosaur.net`. @@ -45,6 +50,7 @@ public function __toArray() { return array( 'to' => $this->to, + 'cc' => $this->cc, 'from' => $this->from, 'send' => $this->send, 'subject' => $this->subject, diff --git a/src/Models/MessageForwardOptions.php b/src/Models/MessageForwardOptions.php index 6b7bb9b..0a8d9cf 100644 --- a/src/Models/MessageForwardOptions.php +++ b/src/Models/MessageForwardOptions.php @@ -10,6 +10,11 @@ class MessageForwardOptions */ public $to = null; + /** + * @var string The email address to which the email will be CC'd. + */ + public $cc = null; + /** * @var string Any additional plain text content to forward the email with. Note that only text or html can be supplied, not both. */ @@ -24,6 +29,7 @@ public function __toArray() { return array( 'to' => $this->to, + 'cc' => $this->cc, 'text' => $this->text, 'html' => $this->html, ); diff --git a/src/Models/MessageReplyOptions.php b/src/Models/MessageReplyOptions.php index 6c20661..f4d5188 100644 --- a/src/Models/MessageReplyOptions.php +++ b/src/Models/MessageReplyOptions.php @@ -5,6 +5,11 @@ class MessageReplyOptions { + /** + * @var string The email address to which the email will be CC'd. + */ + public $cc = null; + /** * @var string Any additional plain text content to include in the reply. Note that only text or html can be supplied, not both. */ @@ -23,6 +28,7 @@ class MessageReplyOptions public function __toArray() { return array( + 'cc' => $this->cc, 'text' => $this->text, 'html' => $this->html, 'attachments' => $this->attachments, diff --git a/tests/EmailsTests.php b/tests/EmailsTests.php index 8b0fa37..4aacb32 100644 --- a/tests/EmailsTests.php +++ b/tests/EmailsTests.php @@ -303,6 +303,27 @@ public function testCreateSendHtml() $this->assertEquals($subject, $message->subject); } + public function testCreateWithCc() + { + if (empty(self::$verifiedDomain)) { $this->markTestSkipped(); } + + $subject = "CC message"; + $ccRecipient = 'someoneelse@' . self::$verifiedDomain; + + $options = new MessageCreateOptions(); + $options->to = 'anything@' . self::$verifiedDomain; + $options->cc = $ccRecipient; + $options->send = TRUE; + $options->subject = $subject; + $options->html = '

This is a new email.

'; + + $message = self::$client->messages->create(self::$server, $options); + $this->assertNotNull($message->id); + $this->assertEquals($subject, $message->subject); + $this->assertCount(1, $message->cc); + $this->assertEquals($ccRecipient, $message->cc[0]->email); + } + public function testCreateSendWithAttachment() { if (empty(self::$verifiedDomain)) { $this->markTestSkipped(); } @@ -370,6 +391,27 @@ public function testForwardHtml() $this->assertNotFalse(strpos($message->html->body, $body)); } + public function testForwardWithCc() + { + if (empty(self::$verifiedDomain)) { $this->markTestSkipped(); } + + $body = "

Forwarded HTML message.

"; + $targetEmailId = self::$emails[0]->id; + $ccRecipient = 'someoneelse@' . self::$verifiedDomain; + + $options = new MessageForwardOptions(); + $options->to = 'forwardcc@' . self::$verifiedDomain; + $options->cc = $ccRecipient; + $options->html = $body; + + $message = self::$client->messages->forward($targetEmailId, $options); + + $this->assertNotNull($message->id); + $this->assertNotFalse(strpos($message->html->body, $body)); + $this->assertCount(1, $message->cc); + $this->assertEquals($ccRecipient, $message->cc[0]->email); + } + public function testReplyText() { if (empty(self::$verifiedDomain)) { $this->markTestSkipped(); } @@ -402,6 +444,26 @@ public function testReplyHtml() $this->assertNotFalse(strpos($message->html->body, $body)); } + public function testReplyWithCc() + { + if (empty(self::$verifiedDomain)) { $this->markTestSkipped(); } + + $body = "

Reply HTML message.

"; + $ccRecipient = 'someoneelse@' . self::$verifiedDomain; + $targetEmailId = self::$emails[0]->id; + + $options = new MessageReplyOptions(); + $options->cc = $ccRecipient; + $options->html = $body; + + $message = self::$client->messages->reply($targetEmailId, $options); + + $this->assertNotNull($message->id); + $this->assertNotFalse(strpos($message->html->body, $body)); + $this->assertCount(1, $message->cc); + $this->assertEquals($ccRecipient, $message->cc[0]->email); + } + public function testReplyWithAttachment() { if (empty(self::$verifiedDomain)) { $this->markTestSkipped(); }