Skip to content

Commit

Permalink
Merge pull request #121 from kevinsmith/feature/dedicated_body_getters
Browse files Browse the repository at this point in the history
Add getPlainTextMessage and getHtmlMessage methods
  • Loading branch information
tedivm committed Jun 7, 2015
2 parents 6a6d909 + fd9784d commit 02af109
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Fetch/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,24 @@ public function getMessageBody($html = false)
return false;
}

/**
* This function returns the plain text body of the email or false if not present.
* @return string|bool Returns false if not present
*/
public function getPlainTextBody()
{
return isset($this->plaintextMessage) ? $this->plaintextMessage : false;
}

/**
* This function returns the HTML body of the email or false if not present.
* @return string|bool Returns false if not present
*/
public function getHtmlBody()
{
return isset($this->htmlMessage) ? $this->htmlMessage : false;
}

/**
* This function returns either an array of email addresses and names or, optionally, a string that can be used in
* mail headers.
Expand Down
37 changes: 37 additions & 0 deletions tests/Fetch/Test/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,43 @@ public function testGetMessageBody()

}

public function testGetPlainTextBody()
{
// easiest way to deal with php encoding issues is simply not to.
$plaintextTest1 = 'f9377a89c9c935463a2b35c92dd61042';
$plaintextTest2 = '0b8fc9b534a1789f1071f996f238a07a';
$plaintextTest3 = 'd41d8cd98f00b204e9800998ecf8427e';

$message = static::getMessage(3);
$messagePlainText = $message->getPlainTextBody();
$this->assertEquals($plaintextTest1, md5($messagePlainText), 'Message returns as plaintext.');

$message = static::getMessage(4);
$messagePlainText = $message->getPlainTextBody();
$this->assertEquals($plaintextTest2, md5($messagePlainText), 'Message returns as plaintext.');

$message = static::getMessage(6);
$messagePlainText = $message->getPlainTextBody();
$this->assertEquals($plaintextTest3, md5($messagePlainText), 'Message does not return as plaintext.');

}

public function testGetHtmlBody()
{
// easiest way to deal with php encoding issues is simply not to.
$HtmlTest1 = 'd41d8cd98f00b204e9800998ecf8427e';
$HtmlTest2 = '6a366ddecf080199284146d991d52169';

$message = static::getMessage(3);
$messageHtml = $message->getHtmlBody();
$this->assertEquals($HtmlTest1, md5($messageHtml), 'Message does not return as HTML.');

$message = static::getMessage(4);
$messageHtml = $message->getHtmlBody();
$this->assertEquals($HtmlTest2, md5($messageHtml), 'Message returns as HTML.');

}

public function testGetAddresses()
{
$message = static::getMessage(3);
Expand Down

0 comments on commit 02af109

Please sign in to comment.