Skip to content

Commit

Permalink
fixed issues #16 and #19, amended some incorrect text, the documentat…
Browse files Browse the repository at this point in the history
…ion and the readme file
  • Loading branch information
nickcv-ln committed Oct 22, 2015
1 parent 7acea8c commit ad6f9de
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
20 changes: 9 additions & 11 deletions Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace nickcv\mandrill;

use yii\mail\BaseMessage;
use yii\helpers\Html;
use yii\helpers\HtmlPurifier;
use yii\helpers\ArrayHelper;
use yii\helpers\FileHelper;
Expand Down Expand Up @@ -194,14 +193,14 @@ class Message extends BaseMessage
private $_templateContent;

/**
* Value use to decide whether the message should calculate default values
* Value used to decide whether the message should calculate default values
* for the sender based on the application settings or return nulls to use
* mandrill template defaults.
*
* @var boolean
* @since 1.4.0
*/
private $_ = false;
private $_calculateDefaultValues = false;

/**
* Global merge vars used when sending the message to mandrill.
Expand Down Expand Up @@ -565,13 +564,13 @@ public function getSubject()
* @see \nickcv\mandrill\Message::getSubject() getter
*
* @param string $subject
* The subject will be trimmed and html-encoded.
* The subject will be trimmed.
* @return \nickcv\mandrill\Message
*/
public function setSubject($subject)
{
if (is_string($subject)) {
$this->_subject = trim(Html::encode($subject));
$this->_subject = trim($subject);
}

return $this;
Expand Down Expand Up @@ -625,13 +624,12 @@ public function getHtmlBody()
* @see \nickcv\mandrill\Message::getHtmlBody() getter
*
* @param string $html
* The html will be purified.
* @return \nickcv\mandrill\Message
*/
public function setHtmlBody($html)
{
if (is_string($html)) {
$this->_html = HtmlPurifier::process($html);
$this->_html = $html;
}

return $this;
Expand Down Expand Up @@ -825,7 +823,7 @@ public function getTemplateContent()
*/
public function enableTemplateDefaults()
{
$this->_ = true;
$this->_calculateDefaultValues = true;

return $this;
}
Expand All @@ -838,7 +836,7 @@ public function enableTemplateDefaults()
*/
public function disableTemplateDefaults()
{
$this->_ = false;
$this->_calculateDefaultValues = false;

return $this;
}
Expand Down Expand Up @@ -1052,7 +1050,7 @@ private function getReplyToString()
*/
private function getFromName()
{
if ($this->_) {
if ($this->_calculateDefaultValues) {
return $this->_fromName ? $this->_fromName : null;
}

Expand All @@ -1066,7 +1064,7 @@ private function getFromName()
*/
private function getFromAddress()
{
if ($this->_) {
if ($this->_calculateDefaultValues) {
return $this->_fromAddress ? $this->_fromAddress : null;
}

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ Mandrill API Extension
Mandrill Api Integration for Yii2
[![Latest Stable Version](https://poser.pugx.org/nickcv/yii2-mandrill/v/stable)](https://packagist.org/packages/nickcv/yii2-mandrill) [![Build Status](https://travis-ci.org/nickcv-ln/yii2-mandrill.svg)](https://travis-ci.org/nickcv-ln/yii2-mandrill) [![Total Downloads](https://poser.pugx.org/nickcv/yii2-mandrill/downloads)](https://packagist.org/packages/nickcv/yii2-mandrill) [![License](https://poser.pugx.org/nickcv/yii2-mandrill/license)](https://packagist.org/packages/nickcv/yii2-mandrill)

Change Log
----------

Since **version 1.6.1** the methods ```nickcv\mandrill\Message::setHtmlBody``` and ```nickcv\mandrill\Message::setSubject``` do not purify/encode the data automatically.

This has been done to offer a greater degree of flexibility to developers, see issues [#16](https://github.com/nickcv-ln/yii2-mandrill/issues/16) and [#19](https://github.com/nickcv-ln/yii2-mandrill/issues/19).

Installation
------------

Expand Down
Binary file modified docs/cache/apidoc.data
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h1>Class Reference</h1>
</div>

<footer class="footer">
<p class="pull-right"><small>Page generated on Fri, 21 Aug 2015 10:51:36 +0000</small></p>
<p class="pull-right"><small>Page generated on Thu, 22 Oct 2015 11:42:04 +0000</small></p>
Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a></footer>

<script type="text/javascript">jQuery(document).ready(function () {
Expand Down
2 changes: 1 addition & 1 deletion docs/jssearch.index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/nickcv-mandrill-mailer.html
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ <h2>Method Details</h2>
</div>

<footer class="footer">
<p class="pull-right"><small>Page generated on Fri, 21 Aug 2015 10:51:36 +0000</small></p>
<p class="pull-right"><small>Page generated on Thu, 22 Oct 2015 11:42:04 +0000</small></p>
Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a></footer>

<script type="text/javascript">jQuery(document).ready(function () {
Expand Down
7 changes: 3 additions & 4 deletions docs/nickcv-mandrill-message.html
Original file line number Diff line number Diff line change
Expand Up @@ -1142,8 +1142,7 @@ <h2>Method Details</h2>
<tr>
<td class="param-name-col"><span style="color: #0000BB">$html</span></td>
<td class="param-type-col"><a href="http://www.php.net/language.types.string">string</a></td>
<td class="param-desc-col"><p>The html will be purified.</p>
</td>
<td class="param-desc-col"></td>
</tr>
</table>

Expand Down Expand Up @@ -1201,7 +1200,7 @@ <h2>Method Details</h2>
<tr>
<td class="param-name-col"><span style="color: #0000BB">$subject</span></td>
<td class="param-type-col"><a href="http://www.php.net/language.types.string">string</a></td>
<td class="param-desc-col"><p>The subject will be trimmed and html-encoded.</p>
<td class="param-desc-col"><p>The subject will be trimmed.</p>
</td>
</tr>
</table>
Expand Down Expand Up @@ -1401,7 +1400,7 @@ <h2>Method Details</h2>
</div>

<footer class="footer">
<p class="pull-right"><small>Page generated on Fri, 21 Aug 2015 10:51:36 +0000</small></p>
<p class="pull-right"><small>Page generated on Thu, 22 Oct 2015 11:42:04 +0000</small></p>
Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a></footer>

<script type="text/javascript">jQuery(document).ready(function () {
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/MandrillMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testMessageSetBCC()
public function testMessageSetSubject()
{
$this->assertInstanceOf('\nickcv\mandrill\Message', $this->_message->setSubject(' <a>Testo '));
$this->assertEquals('&lt;a&gt;Testo', $this->_message->getSubject());
$this->assertEquals('<a>Testo', $this->_message->getSubject());
}

public function testMessageSetTextBody()
Expand All @@ -188,8 +188,8 @@ public function testMessageSetTextBody()

public function testMessageSetHtmlBody()
{
$this->assertInstanceOf('\nickcv\mandrill\Message', $this->_message->setHtmlBody('<a>testo</a><script>alert("ciao");</script>'));
$this->assertEquals('<a>testo</a>', $this->_message->getHtmlBody());
$this->assertInstanceOf('\nickcv\mandrill\Message', $this->_message->setHtmlBody('<a>testo & co</a><script>alert("ciao");</script>'));
$this->assertEquals('<a>testo & co</a><script>alert("ciao");</script>', $this->_message->getHtmlBody());
}

public function testMessageAttach()
Expand Down Expand Up @@ -312,7 +312,7 @@ public function testMessageComplete()
->setGlobalMergeVars(['var1' => 'value1'])
->setSubject(' <a>Testo ')
->setTextBody('testo<script>alert("ciao");</script>')
->setHtmlBody('<a>testo</a><script>alert("ciao");</script>')
->setHtmlBody('<a>testo</a>')
->attachContent($this->getTestPdfBinary(),['fileName'=>'12.txt','contentType'=>'image/png'])
->embed($this->getTestImagePath());
$this->assertInstanceOf('\nickcv\mandrill\Message', $result);
Expand Down Expand Up @@ -343,7 +343,7 @@ public function testMessageComplete()

$this->assertEquals([['name' => 'var1', 'content' => 'value1']], $this->_message->getGlobalMergeVars());

$this->assertEquals('&lt;a&gt;Testo', $this->_message->getSubject());
$this->assertEquals('<a>Testo', $this->_message->getSubject());
$this->assertEquals('testo', $this->_message->getTextBody());
$this->assertEquals('<a>testo</a>', $this->_message->getHtmlBody());

Expand Down Expand Up @@ -374,7 +374,7 @@ public function testMessageArray()
->setSubject(' <a>Testo ')
->setGlobalMergeVars(['var1' => 'value1'])
->setTextBody('testo<script>alert("ciao");</script>')
->setHtmlBody('<a>testo</a><script>alert("ciao");</script>')
->setHtmlBody('<a>testo</a>')
->attachContent($this->getTestPdfBinary(),['fileName'=>'12.txt','contentType'=>'image/png'])
->embed($this->getTestImagePath());
$this->assertInstanceOf('\nickcv\mandrill\Message', $result);
Expand All @@ -383,7 +383,7 @@ public function testMessageArray()
$this->assertEquals('reply@email.it;user <reply2@email.it>', $array['headers']['Reply-To']);
$this->assertEquals('<a>testo</a>', $array['html']);
$this->assertEquals('testo', $array['text']);
$this->assertEquals('&lt;a&gt;Testo', $array['subject']);
$this->assertEquals('<a>Testo', $array['subject']);
$this->assertEquals('from@email.it', $array['from_email']);
$this->assertEquals('My Application', $array['from_name']);

Expand Down

0 comments on commit ad6f9de

Please sign in to comment.