updating EmailComponent, making lineLength public, deprecating protected _lineLength, default value of 70, updating docblocks,

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7105 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-06-03 17:26:30 +00:00
parent 2d2096d9f7
commit 6affb7f70a

View file

@ -9,15 +9,15 @@
* *
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/> * CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2008, Cake Software Foundation, Inc. * Copyright 2005-2008, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204 * 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104 * Las Vegas, Nevada 89104
* *
* Licensed under The MIT License * Licensed under The MIT License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake * @package cake
* @subpackage cake.cake.libs.controller.components * @subpackage cake.cake.libs.controller.components
* @since CakePHP(tm) v 1.2.0.3467 * @since CakePHP(tm) v 1.2.0.3467
@ -27,9 +27,10 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
/** /**
* Short description for file. * EmailComponent
* *
* Long description for file * This component is used for handling Internet Message Format based
* based on the standard outlined in http://www.rfc-editor.org/rfc/rfc2822.txt
* *
* @package cake * @package cake
* @subpackage cake.cake.libs.controller.components * @subpackage cake.cake.libs.controller.components
@ -103,7 +104,7 @@ class EmailComponent extends Object{
var $subject = null; var $subject = null;
/** /**
* Associative array of a user defined headers * Associative array of a user defined headers
* Keys will be prefixed 'X-' as per RFC822 Section 4.7.5 * Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
* *
* @var array * @var array
* @access public * @access public
@ -132,6 +133,17 @@ class EmailComponent extends Object{
* @access public * @access public
*/ */
var $template = null; var $template = null;
/**
* as per RFC2822 Section 2.1.1
*
* @var integer
* @access public
*/
var $lineLength = 70;
/**
* @deprecated see lineLength
*/
var $_lineLength = null;
/** /**
* What format should the email be sent in * What format should the email be sent in
* *
@ -199,9 +211,9 @@ class EmailComponent extends Object{
* @var array * @var array
* @access public * @access public
*/ */
var $smtpOptions = array('port'=> 25, var $smtpOptions = array(
'host' => 'localhost', 'port'=> 25, 'host' => 'localhost', 'timeout' => 30
'timeout' => 30); );
/** /**
* Placeholder for any errors that might happen with the * Placeholder for any errors that might happen with the
* smtp mail methods * smtp mail methods
@ -231,13 +243,6 @@ class EmailComponent extends Object{
* @access protected * @access protected
*/ */
var $_newLine = "\r\n"; var $_newLine = "\r\n";
/**
* Enter description here...
*
* @var integer
* @access protected
*/
var $_lineLength = 70;
/** /**
* Enter description here... * Enter description here...
* *
@ -548,7 +553,7 @@ class EmailComponent extends Object{
return null; return null;
} }
/** /**
* Wrap the message using EmailComponet::$_lineLength * Wrap the message using EmailComponent::$lineLength
* *
* @param string $message Message to wrap * @param string $message Message to wrap
* @return string Wrapped message * @return string Wrapped message
@ -560,11 +565,16 @@ class EmailComponent extends Object{
$lines = explode("\n", $message); $lines = explode("\n", $message);
$formatted = null; $formatted = null;
if ($this->_lineLength !== null) {
trigger_error('_lineLength cannot be accessed please use lineLength', E_USER_WARNING);
$this->lineLength = $this->_lineLength;
}
foreach ($lines as $line) { foreach ($lines as $line) {
if(substr($line, 0, 1) == '.') { if(substr($line, 0, 1) == '.') {
$line = '.' . $line; $line = '.' . $line;
} }
$formatted .= wordwrap($line, $this->_lineLength, $this->_newLine, true); $formatted .= wordwrap($line, $this->lineLength, $this->_newLine, true);
$formatted .= $this->_newLine; $formatted .= $this->_newLine;
} }
return $formatted; return $formatted;
@ -659,16 +669,16 @@ class EmailComponent extends Object{
*/ */
function __smtp() { function __smtp() {
App::import('Core', array('Socket')); App::import('Core', array('Socket'));
$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;
} }
if (!$this->__smtpSend('HELO cake', '250')) { if (!$this->__smtpSend('HELO cake', '250')) {
return false; return false;
} }
@ -712,7 +722,7 @@ class EmailComponent extends Object{
return false; return false;
} }
$this->__smtpSend('QUIT', false); $this->__smtpSend('QUIT', false);
$this->__smtpConnection->disconnect(); $this->__smtpConnection->disconnect();
return true; return true;
} }
@ -738,7 +748,7 @@ class EmailComponent extends Object{
break; break;
} }
} }
if (stristr($response, $checkCode) === false) { if (stristr($response, $checkCode) === false) {
$this->smtpError = $response; $this->smtpError = $response;
return false; return false;