Skip to content

Commit

Permalink
Added CC property to message option models
Browse files Browse the repository at this point in the history
Including Create, Forward and Reply
  • Loading branch information
ey-mailosaur committed Dec 19, 2024
1 parent f109783 commit 0cb822a
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Models/MessageCreateOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -45,6 +50,7 @@ public function __toArray()
{
return array(
'to' => $this->to,
'cc' => $this->cc,
'from' => $this->from,
'send' => $this->send,
'subject' => $this->subject,
Expand Down
6 changes: 6 additions & 0 deletions src/Models/MessageForwardOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -24,6 +29,7 @@ public function __toArray()
{
return array(
'to' => $this->to,
'cc' => $this->cc,
'text' => $this->text,
'html' => $this->html,
);
Expand Down
6 changes: 6 additions & 0 deletions src/Models/MessageReplyOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -23,6 +28,7 @@ class MessageReplyOptions
public function __toArray()
{
return array(
'cc' => $this->cc,
'text' => $this->text,
'html' => $this->html,
'attachments' => $this->attachments,
Expand Down
62 changes: 62 additions & 0 deletions tests/EmailsTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<p>This is a new email.</p>';

$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(); }
Expand Down Expand Up @@ -370,6 +391,27 @@ public function testForwardHtml()
$this->assertNotFalse(strpos($message->html->body, $body));
}

public function testForwardWithCc()
{
if (empty(self::$verifiedDomain)) { $this->markTestSkipped(); }

$body = "<p>Forwarded <strong>HTML</strong> message.</p>";
$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(); }
Expand Down Expand Up @@ -402,6 +444,26 @@ public function testReplyHtml()
$this->assertNotFalse(strpos($message->html->body, $body));
}

public function testReplyWithCc()
{
if (empty(self::$verifiedDomain)) { $this->markTestSkipped(); }

$body = "<p>Reply <strong>HTML</strong> message.</p>";
$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(); }
Expand Down

0 comments on commit 0cb822a

Please sign in to comment.