Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added content transfer encoding detection based on charset.

  • Loading branch information...
commit 86a081463cabc813c24c17346b1a9664dcc7ecc7 1 parent e389858
@predominant predominant authored
Showing with 25 additions and 6 deletions.
  1. +25 −6 lib/Cake/Network/Email/CakeEmail.php
View
31 lib/Cake/Network/Email/CakeEmail.php
@@ -283,6 +283,13 @@ class CakeEmail {
protected $_config = array();
/**
+ * 8Bit character sets
+ *
+ * @var array
+ */
+ protected $_charset8bit = array('UTF-8', 'SHIFT_JIS');
+
+/**
* Constructor
* @param mixed $config Array of configs, or string to load configs from email.php
*
@@ -663,7 +670,7 @@ public function getHeaders($include = array()) {
} elseif ($this->_emailFormat === 'both') {
$headers['Content-Type'] = 'multipart/alternative; boundary="alt-' . $this->_boundary . '"';
}
- $headers['Content-Transfer-Encoding'] = '8bit';
+ $headers['Content-Transfer-Encoding'] = $this->getContentTransferEncoding();
return $headers;
}
@@ -1272,7 +1279,7 @@ protected function _formatMessage($message) {
} elseif ($this->_emailFormat === 'both') {
$prefix[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->_boundary . '"';
}
- $prefix[] = 'Content-Transfer-Encoding: 7bit';
+ $prefix[] = 'Content-Transfer-Encoding: ' . $this->getContentTransferEncoding();
$prefix[] = '';
$message = array_merge($prefix, $message);
}
@@ -1318,7 +1325,7 @@ protected function _render($content) {
}
$msg[] = '--alt-' . $this->_boundary;
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
- $msg[] = 'Content-Transfer-Encoding: 7bit';
+ $msg[] = 'Content-Transfer-Encoding: ' . $this->getContentTransferEncoding();
$msg[] = '';
$View->viewPath = $View->layoutPath = 'Emails' . DS . 'text';
@@ -1330,7 +1337,7 @@ protected function _render($content) {
$msg[] = '';
$msg[] = '--alt-' . $this->_boundary;
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
- $msg[] = 'Content-Transfer-Encoding: 7bit';
+ $msg[] = 'Content-Transfer-Encoding: ' . $this->getContentTransferEncoding();
$msg[] = '';
$View->viewPath = $View->layoutPath = 'Emails' . DS . 'html';
@@ -1352,12 +1359,12 @@ protected function _render($content) {
$msg[] = '';
$msg[] = '--' . $this->_boundary;
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
- $msg[] = 'Content-Transfer-Encoding: 7bit';
+ $msg[] = 'Content-Transfer-Encoding: ' . $this->getContentTransferEncoding();
$msg[] = '';
} else {
$msg[] = '--' . $this->_boundary;
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
- $msg[] = 'Content-Transfer-Encoding: 7bit';
+ $msg[] = 'Content-Transfer-Encoding: ' . $this->getContentTransferEncoding();
$msg[] = '';
}
}
@@ -1376,4 +1383,16 @@ protected function _render($content) {
return array_merge($msg, $content);
}
+/**
+ * Return the Content-Transfer Encoding value based on the set charset
+ *
+ * @return void
+ */
+ private function getContentTransferEncoding() {
+ $charset = strtoupper($this->charset);
+ if (in_array($charset, $this->_charset8bit)) {
+ return '8bit';
+ }
+ return '7bit';
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.