Skip to content

Commit

Permalink
Converting EmailComponent private methods to protected.
Browse files Browse the repository at this point in the history
  • Loading branch information
jperras committed Aug 9, 2009
1 parent 27437a8 commit 4dbdf1e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
102 changes: 51 additions & 51 deletions cake/libs/controller/components/email.php
Expand Up @@ -318,7 +318,7 @@ function startup(&$controller) {}
* @access public * @access public
*/ */
function send($content = null, $template = null, $layout = null) { function send($content = null, $template = null, $layout = null) {
$this->__createHeader(); $this->_createHeader();


if ($template) { if ($template) {
$this->template = $template; $this->template = $template;
Expand All @@ -332,17 +332,17 @@ function send($content = null, $template = null, $layout = null) {
$content = implode("\n", $content) . "\n"; $content = implode("\n", $content) . "\n";
} }


$message = $this->__wrap($content); $message = $this->_wrap($content);
if ($this->template === null) { if ($this->template === null) {
$message = $this->__formatMessage($message); $message = $this->_formatMessage($message);
} else { } else {
$message = $this->__renderTemplate($message); $message = $this->_renderTemplate($message);
} }
$message[] = ''; $message[] = '';
$this->__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)) {
Expand All @@ -352,10 +352,10 @@ function send($content = null, $template = null, $layout = null) {
} }


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 = array(); $this->__header = array();
$this->__message = array(); $this->__message = array();
Expand Down Expand Up @@ -392,7 +392,7 @@ function reset() {
* @return array Email ready to be sent * @return array Email ready to be sent
* @access private * @access private
*/ */
function __renderTemplate($content) { function _renderTemplate($content) {
$viewClass = $this->Controller->view; $viewClass = $this->Controller->view;


if ($viewClass != 'View') { if ($viewClass != 'View') {
Expand Down Expand Up @@ -470,7 +470,7 @@ function __renderTemplate($content) {
* *
* @access private * @access private
*/ */
function __createBoundary() { function _createboundary() {

This comment has been minimized.

Copy link
@mikebranderhorst

mikebranderhorst Apr 8, 2013

Shouldn't this be:

function _createBoundary() {

This comment has been minimized.

Copy link
@dereuromark

dereuromark Apr 8, 2013

Member

It has long been fixed in https://github.com/cakephp/cakephp/blob/1.3/cake/libs/controller/components/email.php#L358
No need to start a discussion in a 4 year old commit :)

$this->__boundary = md5(uniqid(time())); $this->__boundary = md5(uniqid(time()));
} }


Expand All @@ -480,31 +480,31 @@ function __createBoundary() {
* *
* @access private * @access private
*/ */
function __createHeader() { function _createHeader() {
if ($this->delivery == 'smtp') { if ($this->delivery == 'smtp') {
$this->__header[] = 'To: ' . $this->__formatAddress($this->to); $this->__header[] = 'To: ' . $this->_formatAddress($this->to);
} }
$this->__header[] = 'From: ' . $this->__formatAddress($this->from); $this->__header[] = 'From: ' . $this->_formatAddress($this->from);


if (!empty($this->replyTo)) { if (!empty($this->replyTo)) {
$this->__header[] = 'Reply-To: ' . $this->__formatAddress($this->replyTo); $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->__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->__header[] = 'Disposition-Notification-To: ' . $this->_formatAddress($this->readReceipt);
} }


if (!empty($this->cc)) { if (!empty($this->cc)) {
$this->__header[] = 'cc: ' .implode(', ', array_map(array($this, '__formatAddress'), $this->cc)); $this->__header[] = 'cc: ' .implode(', ', array_map(array($this, '_formatAddress'), $this->cc));
} }


if (!empty($this->bcc) && $this->delivery != 'smtp') { if (!empty($this->bcc) && $this->delivery != 'smtp') {
$this->__header[] = 'Bcc: ' .implode(', ', array_map(array($this, '__formatAddress'), $this->bcc)); $this->__header[] = 'Bcc: ' .implode(', ', array_map(array($this, '_formatAddress'), $this->bcc));
} }
if ($this->delivery == 'smtp') { if ($this->delivery == 'smtp') {
$this->__header[] = 'Subject: ' . $this->__encode($this->subject); $this->__header[] = 'Subject: ' . $this->_encode($this->subject);
} }
$this->__header[] = 'X-Mailer: ' . $this->xMailer; $this->__header[] = 'X-Mailer: ' . $this->xMailer;


Expand All @@ -515,7 +515,7 @@ function __createHeader() {
} }


if (!empty($this->attachments)) { if (!empty($this->attachments)) {
$this->__createBoundary(); $this->_createBoundary();
$this->__header[] = 'MIME-Version: 1.0'; $this->__header[] = 'MIME-Version: 1.0';
$this->__header[] = 'Content-Type: multipart/mixed; boundary="' . $this->__boundary . '"'; $this->__header[] = 'Content-Type: multipart/mixed; boundary="' . $this->__boundary . '"';
$this->__header[] = 'This part of the E-mail should never be seen. If'; $this->__header[] = 'This part of the E-mail should never be seen. If';
Expand All @@ -538,7 +538,7 @@ function __createHeader() {
* @param string $message Message to format * @param string $message Message to format
* @access private * @access private
*/ */
function __formatMessage($message) { function _formatMessage($message) {
if (!empty($this->attachments)) { if (!empty($this->attachments)) {
$prefix = array('--' . $this->__boundary); $prefix = array('--' . $this->__boundary);
if ($this->sendAs === 'text') { if ($this->sendAs === 'text') {
Expand All @@ -561,10 +561,10 @@ function __formatMessage($message) {
* @access private * @access private
* @TODO: modify to use the core File class? * @TODO: modify to use the core File class?
*/ */
function __attachFiles() { function _attachFiles() {
$files = array(); $files = array();
foreach ($this->attachments as $attachment) { foreach ($this->attachments as $attachment) {
$file = $this->__findFiles($attachment); $file = $this->_findFiles($attachment);
if (!empty($file)) { if (!empty($file)) {
$files[] = $file; $files[] = $file;
} }
Expand Down Expand Up @@ -593,7 +593,7 @@ function __attachFiles() {
* @return string Path to located file * @return string Path to located file
* @access private * @access private
*/ */
function __findFiles($attachment) { function _findFiles($attachment) {
if (file_exists($attachment)) { if (file_exists($attachment)) {
return $attachment; return $attachment;
} }
Expand All @@ -613,8 +613,8 @@ function __findFiles($attachment) {
* @return array 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 = array(); $formatted = array();
Expand All @@ -641,8 +641,8 @@ function __wrap($message) {
* @return string Encoded string * @return string Encoded string
* @access private * @access private
*/ */
function __encode($subject) { function _encode($subject) {
$subject = $this->__strip($subject); $subject = $this->_strip($subject);


$nl = "\r\n"; $nl = "\r\n";
if ($this->delivery == 'mail') { if ($this->delivery == 'mail') {
Expand All @@ -658,16 +658,16 @@ function __encode($subject) {
* @return string Email address suitable for email headers or smtp pipe * @return string Email address suitable for email headers or smtp pipe
* @access private * @access private
*/ */
function __formatAddress($string, $smtp = false) { function _formatAddress($string, $smtp = false) {
if (strpos($string, '<') !== false) { if (strpos($string, '<') !== false) {
$value = explode('<', $string); $value = explode('<', $string);
if ($smtp) { if ($smtp) {
$string = '<' . $value[1]; $string = '<' . $value[1];
} else { } else {
$string = $this->__encode($value[0]) . ' <' . $value[1]; $string = $this->_encode($value[0]) . ' <' . $value[1];
} }
} }
return $this->__strip($string); return $this->_strip($string);
} }


/** /**
Expand All @@ -678,7 +678,7 @@ function __formatAddress($string, $smtp = false) {
* @return string Stripped value * @return string Stripped value
* @access private * @access private
*/ */
function __strip($value, $message = false) { function _strip($value, $message = false) {
$search = '%0a|%0d|Content-(?:Type|Transfer-Encoding)\:'; $search = '%0a|%0d|Content-(?:Type|Transfer-Encoding)\:';
$search .= '|charset\=|mime-version\:|multipart/mixed|(?:[^a-z]to|b?cc)\:.*'; $search .= '|charset\=|mime-version\:|multipart/mixed|(?:[^a-z]to|b?cc)\:.*';


Expand All @@ -698,13 +698,13 @@ function __strip($value, $message = false) {
* @return bool Success * @return bool Success
* @access private * @access private
*/ */
function __mail() { function _mail() {
$header = implode("\n", $this->__header); $header = implode("\n", $this->__header);
$message = implode("\n", $this->__message); $message = implode("\n", $this->__message);
if (ini_get('safe_mode')) { if (ini_get('safe_mode')) {
return @mail($this->to, $this->__encode($this->subject), $message, $header); return @mail($this->to, $this->_encode($this->subject), $message, $header);
} }
return @mail($this->to, $this->__encode($this->subject), $message, $header, $this->additionalParams); return @mail($this->to, $this->_encode($this->subject), $message, $header, $this->additionalParams);
} }


/** /**
Expand All @@ -713,15 +713,15 @@ function __mail() {
* @return bool Success * @return bool Success
* @access private * @access private
*/ */
function __smtp() { function _smtp() {
App::import('Core', array('CakeSocket')); App::import('Core', array('CakeSocket'));


$this->__smtpConnection =& new CakeSocket(array_merge(array('protocol'=>'smtp'), $this->smtpOptions)); $this->__smtpConnection =& new CakeSocket(array_merge(array('protocol'=>'smtp'), $this->smtpOptions));


if (!$this->__smtpConnection->connect()) { if (!$this->__smtpConnection->connect()) {
$this->smtpError = $this->__smtpConnection->lastError(); $this->smtpError = $this->__smtpConnection->lastError();
return false; return false;
} elseif (!$this->__smtpSend(null, '220')) { } elseif (!$this->_smtpSend(null, '220')) {
return false; return false;
} }


Expand All @@ -731,53 +731,53 @@ function __smtp() {
$host = env('HTTP_HOST'); $host = env('HTTP_HOST');
} }


if (!$this->__smtpSend("HELO {$host}", '250')) { if (!$this->_smtpSend("HELO {$host}", '250')) {
return false; return false;
} }


if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password'])) { if (isset($this->smtpOptions['username']) && isset($this->smtpOptions['password'])) {
$authRequired = $this->__smtpSend('AUTH LOGIN', '334|503'); $authRequired = $this->_smtpSend('AUTH LOGIN', '334|503');
if ($authRequired == '334') { if ($authRequired == '334') {
if (!$this->__smtpSend(base64_encode($this->smtpOptions['username']), '334')) { if (!$this->_smtpSend(base64_encode($this->smtpOptions['username']), '334')) {
return false; return false;
} }
if (!$this->__smtpSend(base64_encode($this->smtpOptions['password']), '235')) { if (!$this->_smtpSend(base64_encode($this->smtpOptions['password']), '235')) {
return false; return false;
} }
} elseif ($authRequired != '503') { } elseif ($authRequired != '503') {
return false; return false;
} }
} }


if (!$this->__smtpSend('MAIL FROM: ' . $this->__formatAddress($this->from, true))) { if (!$this->_smtpSend('MAIL FROM: ' . $this->_formatAddress($this->from, true))) {
return false; return false;
} }


if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($this->to, true))) { if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($this->to, true))) {
return false; return false;
} }


foreach ($this->cc as $cc) { foreach ($this->cc as $cc) {
if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($cc, true))) { if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($cc, true))) {
return false; return false;
} }
} }
foreach ($this->bcc as $bcc) { foreach ($this->bcc as $bcc) {
if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($bcc, true))) { if (!$this->_smtpSend('RCPT TO: ' . $this->_formatAddress($bcc, true))) {
return false; return false;
} }
} }


if (!$this->__smtpSend('DATA', '354')) { if (!$this->_smtpSend('DATA', '354')) {
return false; return false;
} }


$header = implode("\r\n", $this->__header); $header = implode("\r\n", $this->__header);
$message = implode("\r\n", $this->__message); $message = implode("\r\n", $this->__message);
if (!$this->__smtpSend($header . "\r\n\r\n" . $message . "\r\n\r\n\r\n.")) { 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);


$this->__smtpConnection->disconnect(); $this->__smtpConnection->disconnect();
return true; return true;
Expand All @@ -791,7 +791,7 @@ function __smtp() {
* @return bool Success * @return bool Success
* @access private * @access private
*/ */
function __smtpSend($data, $checkCode = '250') { function _smtpSend($data, $checkCode = '250') {
if (!is_null($data)) { if (!is_null($data)) {
$this->__smtpConnection->write($data . "\r\n"); $this->__smtpConnection->write($data . "\r\n");
} }
Expand All @@ -813,7 +813,7 @@ function __smtpSend($data, $checkCode = '250') {
* @return boolean Success * @return boolean Success
* @access private * @access private
*/ */
function __debug() { function _debug() {
$nl = "\n"; $nl = "\n";
$header = implode($nl, $this->__header); $header = implode($nl, $this->__header);
$message = implode($nl, $this->__message); $message = implode($nl, $this->__message);
Expand All @@ -826,7 +826,7 @@ function __debug() {
} }
$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->__encode($this->subject), $nl); $fm .= sprintf('%s %s%s', 'Subject:', $this->_encode($this->subject), $nl);
$fm .= sprintf('%s%3$s%3$s%s', 'Header:', $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:', $message, $nl); $fm .= sprintf('%s%3$s%3$s%s', 'Message:', $message, $nl);
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/libs/controller/components/email.test.php
Expand Up @@ -42,7 +42,7 @@ class EmailTestComponent extends EmailComponent {
* @return mixed * @return mixed
*/ */
function smtpSend($data, $code = '250') { function smtpSend($data, $code = '250') {
return parent::__smtpSend($data, $code); return parent::_smtpSend($data, $code);
} }


/** /**
Expand Down Expand Up @@ -122,7 +122,7 @@ function getMessage() {
* @return string * @return string
*/ */
function strip($content, $message = false) { function strip($content, $message = false) {
return parent::__strip($content, $message); return parent::_strip($content, $message);
} }
} }


Expand Down

0 comments on commit 4dbdf1e

Please sign in to comment.