mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Greatly modified the way newLine characters are handled.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7437 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
ed6ea45581
commit
48f55a0f56
2 changed files with 145 additions and 136 deletions
|
@ -230,40 +230,26 @@ class EmailComponent extends Object{
|
||||||
*/
|
*/
|
||||||
var $_debug = false;
|
var $_debug = false;
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Temporary store of message header lines
|
||||||
*
|
*
|
||||||
* @var string
|
* @var array
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
var $_error = false;
|
|
||||||
/**
|
|
||||||
* New lines char
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
var $_newLine = "\n";
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $__header = null;
|
var $__header = array();
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* If set, boundary to use for multipart mime messages
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $__boundary = null;
|
var $__boundary = null;
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Temporary store of message lines
|
||||||
*
|
*
|
||||||
* @var string
|
* @var array
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
var $__message = null;
|
var $__message = array();
|
||||||
/**
|
/**
|
||||||
* Variable that holds SMTP connection
|
* Variable that holds SMTP connection
|
||||||
*
|
*
|
||||||
|
@ -304,39 +290,36 @@ class EmailComponent extends Object{
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($content)) {
|
if (is_array($content)) {
|
||||||
$message = null;
|
$content = implode("\n", $content) . "\n";
|
||||||
foreach ($content as $key => $value) {
|
|
||||||
$message .= $value . $this->_newLine;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$message = $content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($template === null && $this->template === null) {
|
$message = $this->__wrap($content);
|
||||||
$this->__formatMessage($message);
|
if ($this->template === null) {
|
||||||
|
$message = $this->__formatMessage($message);
|
||||||
} else {
|
} else {
|
||||||
$message = $this->__wrap($message);
|
|
||||||
$message = $this->__renderTemplate($message);
|
$message = $this->__renderTemplate($message);
|
||||||
// $message = $this->__wrap($message);
|
|
||||||
$this->__message = $message;
|
|
||||||
}
|
}
|
||||||
|
$message[] = '';
|
||||||
|
$this->__message = $message;
|
||||||
|
|
||||||
if (!empty($this->attachments)) {
|
if (!empty($this->attachments)) {
|
||||||
$this->__attachFiles();
|
$this->__attachFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_null($this->__boundary)) {
|
if (!is_null($this->__boundary)) {
|
||||||
$this->__message .= $this->_newLine .'--' . $this->__boundary . '--' . $this->_newLine . $this->_newLine;
|
$this->__message[] = '';
|
||||||
|
$this->__message[] = '--' . $this->__boundary . '--';
|
||||||
|
$this->__message[] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->_debug) {
|
if ($this->_debug) {
|
||||||
return $this->__debug();
|
return $this->__debug();
|
||||||
}
|
}
|
||||||
$__method = '__'.$this->delivery;
|
$__method = '__' . $this->delivery;
|
||||||
$sent = $this->$__method();
|
$sent = $this->$__method();
|
||||||
|
|
||||||
$this->__header = '';
|
$this->__header = array();
|
||||||
$this->__message = '';
|
$this->__message = array();
|
||||||
|
|
||||||
return $sent;
|
return $sent;
|
||||||
}
|
}
|
||||||
|
@ -355,15 +338,15 @@ class EmailComponent extends Object{
|
||||||
$this->bcc = array();
|
$this->bcc = array();
|
||||||
$this->subject = null;
|
$this->subject = null;
|
||||||
$this->additionalParams = null;
|
$this->additionalParams = null;
|
||||||
$this->__header = null;
|
$this->__header = array();
|
||||||
$this->__boundary = null;
|
$this->__boundary = null;
|
||||||
$this->__message = null;
|
$this->__message = array();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Render the contents using the current layout and template.
|
* Render the contents using the current layout and template.
|
||||||
*
|
*
|
||||||
* @param string $content Content to render
|
* @param string $content Content to render
|
||||||
* @return string Email ready to be sent
|
* @return array Email ready to be sent
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __renderTemplate($content) {
|
function __renderTemplate($content) {
|
||||||
|
@ -378,49 +361,64 @@ class EmailComponent extends Object{
|
||||||
}
|
}
|
||||||
$View = new $viewClass($this->Controller, false);
|
$View = new $viewClass($this->Controller, false);
|
||||||
$View->layout = $this->layout;
|
$View->layout = $this->layout;
|
||||||
$msg = null;
|
$msg = array();
|
||||||
|
|
||||||
|
$content = implode("\n", $content);
|
||||||
|
|
||||||
if ($this->sendAs === 'both') {
|
if ($this->sendAs === 'both') {
|
||||||
$htmlContent = $content;
|
$htmlContent = $content;
|
||||||
if (!empty($this->attachments)) {
|
if (!empty($this->attachments)) {
|
||||||
$msg .= '--' . $this->__boundary . $this->_newLine;
|
$msg[] = '--' . $this->__boundary;
|
||||||
$msg .= 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"' . $this->_newLine . $this->_newLine;
|
$msg[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
|
||||||
|
$msg[] = '';
|
||||||
}
|
}
|
||||||
$msg .= '--alt-' . $this->__boundary . $this->_newLine;
|
$msg[] = '--alt-' . $this->__boundary;
|
||||||
$msg .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
|
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
|
||||||
$msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
|
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
||||||
|
$msg[] = '';
|
||||||
|
|
||||||
$content = $View->element('email' . DS . 'text' . DS . $this->template, array('content' => $content), true);
|
$content = $View->element('email' . DS . 'text' . DS . $this->template, array('content' => $content), true);
|
||||||
$View->layoutPath = 'email' . DS . 'text';
|
$View->layoutPath = 'email' . DS . 'text';
|
||||||
$msg .= $View->renderLayout($content) . $this->_newLine;
|
$content = explode("\n", str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($content)));
|
||||||
|
$msg = array_merge($msg, $content);
|
||||||
|
|
||||||
$msg .= $this->_newLine. '--alt-' . $this->__boundary . $this->_newLine;
|
$msg[] = '';
|
||||||
$msg .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
|
$msg[] = '--alt-' . $this->__boundary;
|
||||||
$msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
|
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
|
||||||
|
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
||||||
|
$msg[] = '';
|
||||||
|
|
||||||
$content = $View->element('email' . DS . 'html' . DS . $this->template, array('content' => $htmlContent), true);
|
$htmlContent = $View->element('email' . DS . 'html' . DS . $this->template, array('content' => $htmlContent), true);
|
||||||
$View->layoutPath = 'email' . DS . 'html';
|
$View->layoutPath = 'email' . DS . 'html';
|
||||||
$msg .= $View->renderLayout($content) . $this->_newLine . $this->_newLine;
|
$htmlContent = explode("\n", str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($htmlContent)));
|
||||||
$msg .= '--alt-' . $this->__boundary . '--' . $this->_newLine . $this->_newLine;
|
$msg = array_merge($msg, $htmlContent);
|
||||||
return $msg;
|
$msg[] = '';
|
||||||
|
$msg[] = '--alt-' . $this->__boundary . '--';
|
||||||
|
$msg[] = '';
|
||||||
|
|
||||||
|
return $msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->attachments)) {
|
if (!empty($this->attachments)) {
|
||||||
if ($this->sendAs === 'html') {
|
if ($this->sendAs === 'html') {
|
||||||
$msg .= $this->_newLine. '--' . $this->__boundary . $this->_newLine;
|
$msg[] = '';
|
||||||
$msg .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
|
$msg[] = '--' . $this->__boundary;
|
||||||
$msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
|
$msg[] = 'Content-Type: text/html; charset=' . $this->charset;
|
||||||
|
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
||||||
|
$msg[] = '';
|
||||||
} else {
|
} else {
|
||||||
$msg .= '--' . $this->__boundary . $this->_newLine;
|
$msg[] = '--' . $this->__boundary;
|
||||||
$msg .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
|
$msg[] = 'Content-Type: text/plain; charset=' . $this->charset;
|
||||||
$msg .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
|
$msg[] = 'Content-Transfer-Encoding: 7bit';
|
||||||
|
$msg[] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $View->element('email' . DS . $this->sendAs . DS . $this->template, array('content' => $content), true);
|
$content = $View->element('email' . DS . $this->sendAs . DS . $this->template, array('content' => $content), true);
|
||||||
$View->layoutPath = 'email' . DS . $this->sendAs;
|
$View->layoutPath = 'email' . DS . $this->sendAs;
|
||||||
$msg .= $View->renderLayout($content) . $this->_newLine;
|
$content = explode("\n", str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($content)));
|
||||||
|
$msg = array_merge($msg, $content);
|
||||||
|
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -439,63 +437,55 @@ class EmailComponent extends Object{
|
||||||
*/
|
*/
|
||||||
function __createHeader() {
|
function __createHeader() {
|
||||||
if ($this->delivery == 'smtp') {
|
if ($this->delivery == 'smtp') {
|
||||||
$this->_newLine = "\r\n";
|
$this->__header[] = 'To: ' . $this->__formatAddress($this->to);
|
||||||
$this->__header = 'To: ' . $this->__formatAddress($this->to) . $this->_newLine;
|
|
||||||
}
|
}
|
||||||
$this->__header .= 'From: ' . $this->__formatAddress($this->from) . $this->_newLine;
|
$this->__header[] = 'From: ' . $this->__formatAddress($this->from);
|
||||||
|
|
||||||
if (!empty($this->replyTo)) {
|
if (!empty($this->replyTo)) {
|
||||||
$this->__header .= 'Reply-To: ' . $this->__formatAddress($this->replyTo) . $this->_newLine;
|
$this->__header[] = 'Reply-To: ' . $this->__formatAddress($this->replyTo);
|
||||||
}
|
}
|
||||||
if (!empty($this->return)) {
|
if (!empty($this->return)) {
|
||||||
$this->__header .= 'Return-Path: ' . $this->__formatAddress($this->return) . $this->_newLine;
|
$this->__header[] = 'Return-Path: ' . $this->__formatAddress($this->return);
|
||||||
}
|
}
|
||||||
if (!empty($this->readReceipt)) {
|
if (!empty($this->readReceipt)) {
|
||||||
$this->__header .= 'Disposition-Notification-To: ' . $this->__formatAddress($this->readReceipt) . $this->_newLine;
|
$this->__header[] = 'Disposition-Notification-To: ' . $this->__formatAddress($this->readReceipt);
|
||||||
}
|
}
|
||||||
$addresses = null;
|
|
||||||
|
|
||||||
if (!empty($this->cc)) {
|
if (!empty($this->cc)) {
|
||||||
foreach ($this->cc as $cc) {
|
$this->__header[] = 'cc: ' .implode(', ', array_map(array($this, '__formatAddress'), $this->cc));
|
||||||
$addresses .= ', ' . $this->__formatAddress($cc);
|
|
||||||
}
|
|
||||||
$this->__header .= 'cc: ' . substr($addresses, 2) . $this->_newLine;
|
|
||||||
}
|
}
|
||||||
$addresses = null;
|
|
||||||
|
|
||||||
if (!empty($this->bcc)) {
|
if (!empty($this->bcc)) {
|
||||||
foreach ($this->bcc as $bcc) {
|
$this->__header[] = 'Bcc: ' .implode(', ', array_map(array($this, '__formatAddress'), $this->bcc));
|
||||||
$addresses .= ', ' . $this->__formatAddress($bcc);
|
|
||||||
}
|
|
||||||
$this->__header .= 'Bcc: ' . substr($addresses, 2) . $this->_newLine;
|
|
||||||
}
|
}
|
||||||
if ($this->delivery == 'smtp') {
|
if ($this->delivery == 'smtp') {
|
||||||
$this->__header .= 'Subject: ' . $this->__encode($this->subject) . $this->_newLine;
|
$this->__header[] = 'Subject: ' . $this->__encode($this->subject);
|
||||||
}
|
}
|
||||||
$this->__header .= 'X-Mailer: ' . $this->xMailer . $this->_newLine;
|
$this->__header[] = 'X-Mailer: ' . $this->xMailer;
|
||||||
|
|
||||||
if (!empty($this->headers)) {
|
if (!empty($this->headers)) {
|
||||||
foreach ($this->headers as $key => $val) {
|
foreach ($this->headers as $key => $val) {
|
||||||
$this->__header .= 'X-'.$key.': '.$val . $this->_newLine;
|
$this->__header[] = 'X-' . $key . ': ' . $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->attachments)) {
|
if (!empty($this->attachments)) {
|
||||||
$this->__createBoundary();
|
$this->__createBoundary();
|
||||||
$this->__header .= 'MIME-Version: 1.0' . $this->_newLine;
|
$this->__header[] = 'MIME-Version: 1.0';
|
||||||
$this->__header .= 'Content-Type: multipart/mixed; boundary="' . $this->__boundary . '"' . $this->_newLine;
|
$this->__header[] = 'Content-Type: multipart/mixed; boundary="' . $this->__boundary . '"';
|
||||||
$this->__header .= 'This part of the E-mail should never be seen. If' . $this->_newLine;
|
$this->__header[] = 'This part of the E-mail should never be seen. If';
|
||||||
$this->__header .= 'you are reading this, consider upgrading your e-mail' . $this->_newLine;
|
$this->__header[] = 'you are reading this, consider upgrading your e-mail';
|
||||||
$this->__header .= 'client to a MIME-compatible client.' . $this->_newLine;
|
$this->__header[] = 'client to a MIME-compatible client.';
|
||||||
} elseif ($this->sendAs === 'text') {
|
} elseif ($this->sendAs === 'text') {
|
||||||
$this->__header .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
|
$this->__header[] = 'Content-Type: text/plain; charset=' . $this->charset;
|
||||||
} elseif ($this->sendAs === 'html') {
|
} elseif ($this->sendAs === 'html') {
|
||||||
$this->__header .= 'Content-Type: text/html; charset=' . $this->charset . $this->_newLine;
|
$this->__header[] = 'Content-Type: text/html; charset=' . $this->charset;
|
||||||
} elseif ($this->sendAs === 'both') {
|
} elseif ($this->sendAs === 'both') {
|
||||||
$this->__header .= 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"' . $this->_newLine . $this->_newLine;
|
$this->__header[] = 'Content-Type: multipart/alternative; boundary="alt-' . $this->__boundary . '"';
|
||||||
|
$this->__header[] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->__header .= 'Content-Transfer-Encoding: 7bit';
|
$this->__header[] = 'Content-Transfer-Encoding: 7bit';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Format the message by seeing if it has attachments.
|
* Format the message by seeing if it has attachments.
|
||||||
|
@ -505,17 +495,21 @@ class EmailComponent extends Object{
|
||||||
*/
|
*/
|
||||||
function __formatMessage($message) {
|
function __formatMessage($message) {
|
||||||
if (!empty($this->attachments)) {
|
if (!empty($this->attachments)) {
|
||||||
$this->__message .= '--' . $this->__boundary . $this->_newLine;
|
$prefix = array(
|
||||||
$this->__message .= 'Content-Type: text/plain; charset=' . $this->charset . $this->_newLine;
|
'--' . $this->__boundary,
|
||||||
$this->__message .= 'Content-Transfer-Encoding: 7bit' . $this->_newLine . $this->_newLine;
|
'Content-Type: text/plain; charset=' . $this->charset,
|
||||||
|
'Content-Transfer-Encoding: 7bit',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
$message = array_merge($prefix, $message);
|
||||||
}
|
}
|
||||||
$message = $this->__wrap($message);
|
return $message;
|
||||||
$this->__message .= $message . $this->_newLine;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Attach files by adding file contents inside boundaries.
|
* Attach files by adding file contents inside boundaries.
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
|
* @TODO: modify to use the core File class?
|
||||||
*/
|
*/
|
||||||
function __attachFiles() {
|
function __attachFiles() {
|
||||||
$files = array();
|
$files = array();
|
||||||
|
@ -532,11 +526,13 @@ class EmailComponent extends Object{
|
||||||
$data = chunk_split(base64_encode($data)) ;
|
$data = chunk_split(base64_encode($data)) ;
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
|
|
||||||
$this->__message .= '--' . $this->__boundary . $this->_newLine;
|
$this->__message[] = '--' . $this->__boundary;
|
||||||
$this->__message .= 'Content-Type: application/octet-stream' . $this->_newLine;
|
$this->__message[] = 'Content-Type: application/octet-stream';
|
||||||
$this->__message .= 'Content-Transfer-Encoding: base64' . $this->_newLine;
|
$this->__message[] = 'Content-Transfer-Encoding: base64';
|
||||||
$this->__message .= 'Content-Disposition: attachment; filename="' . basename($file) . '"' . $this->_newLine . $this->_newLine;
|
$this->__message[] = 'Content-Disposition: attachment; filename="' . basename($file) . '"';
|
||||||
$this->__message .= $data . $this->_newLine . $this->_newLine;
|
$this->__message[] = '';
|
||||||
|
$this->__message[] = $data;
|
||||||
|
$this->__message[] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -562,14 +558,14 @@ class EmailComponent extends Object{
|
||||||
* Wrap the message using EmailComponent::$lineLength
|
* Wrap the message using EmailComponent::$lineLength
|
||||||
*
|
*
|
||||||
* @param string $message Message to wrap
|
* @param string $message Message to wrap
|
||||||
* @return string Wrapped message
|
* @return array Wrapped message
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __wrap($message) {
|
function __wrap($message) {
|
||||||
$message = $this->__strip($message, true);
|
$message = $this->__strip($message, true);
|
||||||
$message = str_replace(array("\r\n","\r"), "\n", $message);
|
$message = str_replace(array("\r\n","\r"), "\n", $message);
|
||||||
$lines = explode("\n", $message);
|
$lines = explode("\n", $message);
|
||||||
$formatted = null;
|
$formatted = array();
|
||||||
|
|
||||||
if ($this->_lineLength !== null) {
|
if ($this->_lineLength !== null) {
|
||||||
trigger_error('_lineLength cannot be accessed please use lineLength', E_USER_WARNING);
|
trigger_error('_lineLength cannot be accessed please use lineLength', E_USER_WARNING);
|
||||||
|
@ -580,9 +576,9 @@ class EmailComponent extends Object{
|
||||||
if(substr($line, 0, 1) == '.') {
|
if(substr($line, 0, 1) == '.') {
|
||||||
$line = '.' . $line;
|
$line = '.' . $line;
|
||||||
}
|
}
|
||||||
$formatted .= wordwrap($line, $this->lineLength, $this->_newLine, true);
|
$formatted = array_merge($formatted, explode("\n", wordwrap($line, $this->lineLength, "\n", true)));
|
||||||
$formatted .= $this->_newLine;
|
|
||||||
}
|
}
|
||||||
|
$formatted[] = '';
|
||||||
return $formatted;
|
return $formatted;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -595,10 +591,15 @@ class EmailComponent extends Object{
|
||||||
function __encode($subject) {
|
function __encode($subject) {
|
||||||
$subject = $this->__strip($subject);
|
$subject = $this->__strip($subject);
|
||||||
|
|
||||||
|
$nl = "\n";
|
||||||
|
if ($this->delivery == 'smtp') {
|
||||||
|
$nl = "\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
if (strtolower($this->charset) !== 'iso-8859-15') {
|
if (strtolower($this->charset) !== 'iso-8859-15') {
|
||||||
$start = "=?" . $this->charset . "?B?";
|
$start = "=?" . $this->charset . "?B?";
|
||||||
$end = "?=";
|
$end = "?=";
|
||||||
$spacer = $end . $this->_newLine . " " . $start;
|
$spacer = $end . $nl . ' ' . $start;
|
||||||
|
|
||||||
$length = 75 - strlen($start) - strlen($end);
|
$length = 75 - strlen($start) - strlen($end);
|
||||||
$length = $length - ($length % 4);
|
$length = $length - ($length % 4);
|
||||||
|
@ -606,7 +607,7 @@ class EmailComponent extends Object{
|
||||||
$subject = base64_encode($subject);
|
$subject = base64_encode($subject);
|
||||||
$subject = chunk_split($subject, $length, $spacer);
|
$subject = chunk_split($subject, $length, $spacer);
|
||||||
$spacer = preg_quote($spacer);
|
$spacer = preg_quote($spacer);
|
||||||
$subject = preg_replace("/" . $spacer . "$/", "", $subject);
|
$subject = preg_replace('/' . $spacer . '$/', '', $subject);
|
||||||
$subject = $start . $subject . $end;
|
$subject = $start . $subject . $end;
|
||||||
}
|
}
|
||||||
return $subject;
|
return $subject;
|
||||||
|
@ -662,10 +663,12 @@ class EmailComponent extends Object{
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __mail() {
|
function __mail() {
|
||||||
|
$header = implode("\n", $this->__header);
|
||||||
|
$message = implode("\n", $this->__message);
|
||||||
if (ini_get('safe_mode')) {
|
if (ini_get('safe_mode')) {
|
||||||
return @mail($this->to, $this->__encode($this->subject), $this->__message, $this->__header);
|
return @mail($this->to, $this->__encode($this->subject), $message, $header);
|
||||||
}
|
}
|
||||||
return @mail($this->to, $this->__encode($this->subject), $this->__message, $this->__header, $this->additionalParams);
|
return @mail($this->to, $this->__encode($this->subject), $message, $header, $this->additionalParams);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Sends out email via SMTP
|
* Sends out email via SMTP
|
||||||
|
@ -724,7 +727,9 @@ class EmailComponent extends Object{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->__smtpSend($this->__header . "\r\n\r\n" . $this->__message . "\r\n\r\n\r\n.")) {
|
$header = implode("\r\n", $this->__header);
|
||||||
|
$message = implode("\r\n", $this->__message);
|
||||||
|
if (!$this->__smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->__smtpSend('QUIT', false);
|
$this->__smtpSend('QUIT', false);
|
||||||
|
@ -769,7 +774,9 @@ class EmailComponent extends Object{
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __debug() {
|
function __debug() {
|
||||||
$nl = $this->_newLine;
|
$nl = "\n";
|
||||||
|
$header = implode($nl, $this->__header);
|
||||||
|
$message = implode($nl, $this->__message);
|
||||||
$fm = '<pre>';
|
$fm = '<pre>';
|
||||||
|
|
||||||
if ($this->delivery == 'smtp') {
|
if ($this->delivery == 'smtp') {
|
||||||
|
@ -780,13 +787,14 @@ class EmailComponent extends Object{
|
||||||
$fm .= sprintf('%s %s%s', 'To:', $this->to, $nl);
|
$fm .= sprintf('%s %s%s', 'To:', $this->to, $nl);
|
||||||
$fm .= sprintf('%s %s%s', 'From:', $this->from, $nl);
|
$fm .= sprintf('%s %s%s', 'From:', $this->from, $nl);
|
||||||
$fm .= sprintf('%s %s%s', 'Subject:', $this->subject, $nl);
|
$fm .= sprintf('%s %s%s', 'Subject:', $this->subject, $nl);
|
||||||
$fm .= sprintf('%s%3$s%3$s%s', 'Header:', $this->__header, $nl);
|
$fm .= sprintf('%s%3$s%3$s%s', 'Header:', $header, $nl);
|
||||||
$fm .= sprintf('%s%3$s%3$s%s', 'Parameters:', $this->additionalParams, $nl);
|
$fm .= sprintf('%s%3$s%3$s%s', 'Parameters:', $this->additionalParams, $nl);
|
||||||
$fm .= sprintf('%s%3$s%3$s%s', 'Message:', $this->__message, $nl);
|
$fm .= sprintf('%s%3$s%3$s%s', 'Message:', $message, $nl);
|
||||||
$fm .= '</pre>';
|
$fm .= '</pre>';
|
||||||
|
|
||||||
$this->Controller->Session->setFlash($fm, 'default', null, 'email');
|
$this->Controller->Session->setFlash($fm, 'default', null, 'email');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -88,7 +88,7 @@ class EmailTest extends CakeTestCase {
|
||||||
$this->Controller->Email->startup($this->Controller);
|
$this->Controller->Email->startup($this->Controller);
|
||||||
ClassRegistry::addObject('view', new View($this->Controller));
|
ClassRegistry::addObject('view', new View($this->Controller));
|
||||||
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
|
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* testBadSmtpSend method
|
* testBadSmtpSend method
|
||||||
|
@ -250,7 +250,7 @@ MSGBLOC;
|
||||||
$this->Controller->Email->from = 'noreply@example.com';
|
$this->Controller->Email->from = 'noreply@example.com';
|
||||||
$this->Controller->Email->subject = 'Cake SMTP test';
|
$this->Controller->Email->subject = 'Cake SMTP test';
|
||||||
$this->Controller->Email->replyTo = 'noreply@example.com';
|
$this->Controller->Email->replyTo = 'noreply@example.com';
|
||||||
|
|
||||||
$this->Controller->Email->delivery = 'debug';
|
$this->Controller->Email->delivery = 'debug';
|
||||||
|
|
||||||
$header = <<<HEADBLOC
|
$header = <<<HEADBLOC
|
||||||
|
@ -272,7 +272,7 @@ HEADBLOC;
|
||||||
|
|
||||||
$this->Controller->Email->layout = 'default';
|
$this->Controller->Email->layout = 'default';
|
||||||
$this->Controller->Email->template = 'default';
|
$this->Controller->Email->template = 'default';
|
||||||
|
|
||||||
$text = <<<TEXTBLOC
|
$text = <<<TEXTBLOC
|
||||||
|
|
||||||
This is the body of the message
|
This is the body of the message
|
||||||
|
@ -292,8 +292,7 @@ TEXTBLOC;
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<p> This is the body of the message</p><p> </p>
|
<p> This is the body of the message</p><p> </p>
|
||||||
<p>This email was sent using the <a href="http://cakephp.org">CakePHP
|
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
|
||||||
Framework</a></p>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
@ -303,12 +302,12 @@ HTMLBLOC;
|
||||||
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>';
|
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>';
|
||||||
$this->assertTrue($this->Controller->Email->send('This is the body of the message'));
|
$this->assertTrue($this->Controller->Email->send('This is the body of the message'));
|
||||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||||
|
|
||||||
$this->Controller->Email->sendAs = 'html';
|
$this->Controller->Email->sendAs = 'html';
|
||||||
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>';
|
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>';
|
||||||
$this->assertTrue($this->Controller->Email->send('This is the body of the message'));
|
$this->assertTrue($this->Controller->Email->send('This is the body of the message'));
|
||||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||||
|
|
||||||
$this->Controller->Email->sendAs = 'both';
|
$this->Controller->Email->sendAs = 'both';
|
||||||
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $header);
|
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"' . "\n", $header);
|
||||||
$expect .= '--alt-' . "\n" . 'Content-Type: text/plain; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $text . "\n\n";
|
$expect .= '--alt-' . "\n" . 'Content-Type: text/plain; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $text . "\n\n";
|
||||||
|
@ -317,22 +316,6 @@ HTMLBLOC;
|
||||||
$this->assertTrue($this->Controller->Email->send('This is the body of the message'));
|
$this->assertTrue($this->Controller->Email->send('This is the body of the message'));
|
||||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||||
|
|
||||||
$text = <<<TEXTBLOC
|
|
||||||
|
|
||||||
This element has some text that is just too wide to comply with email
|
|
||||||
standards.
|
|
||||||
This is the body of the message
|
|
||||||
|
|
||||||
This email was sent using the CakePHP Framework, http://cakephp.org.
|
|
||||||
|
|
||||||
|
|
||||||
TEXTBLOC;
|
|
||||||
|
|
||||||
$this->Controller->Email->sendAs = 'text';
|
|
||||||
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>';
|
|
||||||
$this->assertTrue($this->Controller->Email->send('This is the body of the message', 'wide'));
|
|
||||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
|
||||||
|
|
||||||
$html = <<<HTMLBLOC
|
$html = <<<HTMLBLOC
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
||||||
|
|
||||||
|
@ -353,7 +336,25 @@ HTMLBLOC;
|
||||||
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>';
|
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>';
|
||||||
$this->assertTrue($this->Controller->Email->send('This is the body of the message', 'default', 'thin'));
|
$this->assertTrue($this->Controller->Email->send('This is the body of the message', 'default', 'thin'));
|
||||||
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
$text = <<<TEXTBLOC
|
||||||
|
|
||||||
|
This element has some text that is just too wide to comply with email
|
||||||
|
standards.
|
||||||
|
This is the body of the message
|
||||||
|
|
||||||
|
This email was sent using the CakePHP Framework, http://cakephp.org.
|
||||||
|
|
||||||
|
|
||||||
|
TEXTBLOC;
|
||||||
|
|
||||||
|
$this->Controller->Email->sendAs = 'text';
|
||||||
|
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>';
|
||||||
|
$this->assertTrue($this->Controller->Email->send('This is the body of the message', 'wide', 'default'));
|
||||||
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -391,9 +392,9 @@ HTMLBLOC;
|
||||||
$expected = "Previous content\n--alt-\n text/html; utf-8\n 7bit\n\n<p>My own html content</p>";
|
$expected = "Previous content\n--alt-\n text/html; utf-8\n 7bit\n\n<p>My own html content</p>";
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
function __osFix($string) {
|
function __osFix($string) {
|
||||||
return str_replace(array("\r\n", "\n"), $this->Controller->Email->_newLine, $string);
|
return str_replace(array("\r\n", "\r"), "\n", $string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue