Skip to content

Commit

Permalink
Add email config for transferEncoding #11485
Browse files Browse the repository at this point in the history
  • Loading branch information
maratth committed Dec 1, 2017
1 parent d7cf3e7 commit 2023b4e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Mailer/Email.php
Expand Up @@ -241,6 +241,14 @@ class Email implements JsonSerializable, Serializable
*/
public $headerCharset;

/**
* The email transfer encoding used.
* If null, the $charset property is used for determined the transfer encoding.
*
* @var string|null
*/
public $transferEncoding;

/**
* The application wide charset, used to encode headers and body
*
Expand Down Expand Up @@ -827,6 +835,27 @@ public function headerCharset($charset = null)
return $this->headerCharset;
}

/**
* TransportCharset setter.
*
* @param string|null $encoding Character set.
* @return $this
*/
public function setTransferEncoding($encoding) {
$this->transferEncoding = $encoding;

return $this;
}

/**
* TransportCharset getter.
*
* @return string|null Encoding
*/
public function getTransferEncoding() {
return $this->transferEncoding;
}

/**
* EmailPattern setter/getter
*
Expand Down Expand Up @@ -2224,6 +2253,7 @@ public function reset()
$this->_priority = null;
$this->charset = 'utf-8';
$this->headerCharset = null;
$this->transferEncoding = null;
$this->_attachments = [];
$this->_profile = [];
$this->_emailPattern = self::EMAIL_PATTERN;
Expand Down Expand Up @@ -2661,6 +2691,10 @@ protected function _renderTemplates($content)
*/
protected function _getContentTransferEncoding()
{
if ($this->transferEncoding) {
return $this->transferEncoding;
}

$charset = strtoupper($this->charset);
if (in_array($charset, $this->_charset8bit)) {
return '8bit';
Expand Down
25 changes: 25 additions & 0 deletions tests/TestCase/Mailer/EmailTest.php
Expand Up @@ -90,6 +90,16 @@ public function render($content)
{
return $this->_render($content);
}

/**
* GetContentTransferEncoding to protected method
*
* @return string
*/
public function getContentTransferEncoding() {
return $this->_getContentTransferEncoding();
}

}

/**
Expand Down Expand Up @@ -2487,6 +2497,21 @@ public function testHeaderCharset()
$this->assertSame($charset, 'Shift_JIS');
}

/**
* Test transferEncoding
*/
public function testTransferEncoding(){
// Test new transport encoding
$this->Email->setTransferEncoding('quoted-printable');
$this->assertSame($this->Email->getTransferEncoding(), 'quoted-printable');
$this->assertSame($this->Email->getContentTransferEncoding(), 'quoted-printable');

// Test default charset/encoding : utf8/8bit
$this->Email->reset();
$this->assertNull($this->Email->getTransferEncoding());
$this->assertSame($this->Email->getContentTransferEncoding(), '8bit');
}

/**
* Tests for compatible check.
* charset property and charset() method.
Expand Down

0 comments on commit 2023b4e

Please sign in to comment.