Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add Cakelog to send(), transport classes now all return in same forma…

…t, fixing some typos
  • Loading branch information...
commit 9e0ff5ad88c9cb88146d7d0ae260619e47a0254c 1 parent c93274a
@ceeram ceeram authored
View
2  lib/Cake/Network/Email/AbstractTransport.php
@@ -35,7 +35,7 @@
* Send mail
*
* @params object $email CakeEmail
- * @return boolean
+ * @return array
*/
abstract public function send(CakeEmail $email);
View
37 lib/Cake/Network/Email/CakeEmail.php
@@ -582,17 +582,10 @@ public function addHeaders($headers) {
* @return array
*/
public function getHeaders($include = array()) {
- $defaults = array(
- 'from' => false,
- 'sender' => false,
- 'replyTo' => false,
- 'readReceipt' => false,
- 'returnPath' => false,
- 'to' => false,
- 'cc' => false,
- 'bcc' => false,
- 'subject' => false
- );
+ if ($include == array_values($include)) {
+ $include = array_fill_keys($include, true);
+ }
+ $defaults = array_fill_keys(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), false);
$include += $defaults;
$headers = array();
@@ -904,7 +897,7 @@ public function config($config = null) {
/**
* Send an email using the specified content, template and layout
*
- * @return boolean Success
+ * @return array
* @throws SocketException
*/
public function send($content = null) {
@@ -948,8 +941,11 @@ public function send($content = null) {
$this->_message[] = '--' . $this->_boundary . '--';
$this->_message[] = '';
}
-
- return $this->transportClass()->send($this);
+ $contents = $this->transportClass()->send($this);
+ if (isset($this->_config['log']) && $this->_config['log']) {
+ CakeLog::write(LOG_DEBUG, '\nHeaders:\n' . $contents['headers'] . 'Message:\n' . $contents['message']);
+ }
+ return $contents;
}
/**
@@ -961,6 +957,7 @@ public function send($content = null) {
* @param mixed $transportConfig String to use config from EmailConfig or array with configs
* @param boolean $send Send the email or just return the instance pre-configured
* @return object Instance of CakeEmail
+ * @throws SocketException
*/
public static function deliver($to = null, $subject = null, $message = null, $transportConfig = 'fast', $send = true) {
$class = __CLASS__;
@@ -1259,12 +1256,12 @@ protected function _render($content) {
$View->helpers = $this->_helpers;
$msg = array();
- list($templatePlugin, $template) = pluginSplit($this->_template, true);
- list($layoutPlugin, $layout) = pluginSplit($this->_layout, true);
- if (!empty($templatePlugin)) {
- $View->plugin = rtrim($templatePlugin, '.');
- } elseif (!empty($layoutPlugin)) {
- $View->plugin = rtrim($layoutPlugin, '.');
+ list($templatePlugin, $template) = pluginSplit($this->_template);
+ list($layoutPlugin, $layout) = pluginSplit($this->_layout);
+ if ($templatePlugin) {
+ $View->plugin = $templatePlugin;
+ } elseif ($layoutPlugin) {
+ $View->plugin = $layoutPlugin;
}
$content = implode("\n", $content);
View
17 lib/Cake/Network/Email/DebugTransport.php
@@ -29,22 +29,13 @@ class DebugTransport extends AbstractTransport {
* Send mail
*
* @params object $email CakeEmail
- * @return boolean
+ * @return array
*/
public function send(CakeEmail $email) {
- $headers = $email->getHeaders(array(
- 'from' => true,
- 'sender' => true,
- 'replyTo' => true,
- 'readReceipt' => true,
- 'returnPath' => true,
- 'to' => true,
- 'cc' => true,
- 'bcc' => true,
- 'subject' => true
- ));
+ $headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'));
$headers = $this->_headersToString($headers);
- return $headers . "\n\n" . implode((array)$email->message(), "\n");
+ $message = implode((array)$email->message(), "\n");
+ return array('headers' => $headers, 'message' => $message);
}
}
View
15 lib/Cake/Network/Email/MailTransport.php
@@ -28,22 +28,27 @@ class MailTransport extends AbstractTransport {
* Send mail
*
* @params object $email CakeEmail
- * @return boolean
+ * @return array
*/
public function send(CakeEmail $email) {
$eol = PHP_EOL;
if (isset($this->_config['eol'])) {
$eol = $this->_config['eol'];
}
- $headers = $email->getHeaders(array_fill_keys(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'), true));
+ $headers = $email->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc'));
$to = $headers['To'];
unset($headers['To']);
- $header = $this->_headersToString($headers, $eol);
+ $headers = $this->_headersToString($headers, $eol);
$message = implode($eol, $email->message());
if (ini_get('safe_mode') || !isset($this->_config['additionalParameters'])) {
- return @mail($to, $email->subject(), $message, $header);
+ if (!@mail($to, $email->subject(), $message, $headers)) {
+ throw new SocketException(__d('cake', 'Could not send email.'));
+ }
}
- return @mail($to, $email->subject(), $message, $header, $this->_config['additionalParameters']);
+ if(!@mail($to, $email->subject(), $message, $headers, $this->_config['additionalParameters'])) {
+ throw new SocketException(__d('cake', 'Could not send email.'));
+ }
+ return array('headers' => $headers, 'message' => $message);
}
}
View
14 lib/Cake/Network/Email/SmtpTransport.php
@@ -40,10 +40,17 @@ class SmtpTransport extends AbstractTransport {
protected $_cakeEmail;
/**
+ * Content of email to return
+ *
+ * @var string
+ */
+ protected $_content;
+
+/**
* Send mail
*
* @params object $email CakeEmail
- * @return boolean
+ * @return array
* @throws SocketException
*/
public function send(CakeEmail $email) {
@@ -55,7 +62,7 @@ public function send(CakeEmail $email) {
$this->_sendData();
$this->_disconnect();
- return true;
+ return $this->_content;
}
/**
@@ -158,10 +165,11 @@ protected function _sendRcpt() {
protected function _sendData() {
$this->_smtpSend('DATA', '354');
- $headers = $this->_cakeEmail->getHeaders(array_fill_keys(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), true));
+ $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'));
$headers = $this->_headersToString($headers);
$message = implode("\r\n", $this->_cakeEmail->message());
$this->_smtpSend($headers . "\r\n\r\n" . $message . "\r\n\r\n\r\n.");
+ $this->_content = array('headers' => $headers, 'message' => $message);
}
/**
View
24 lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -559,16 +559,16 @@ public function testConfigString() {
$this->CakeEmail->config('test');
$result = $this->CakeEmail->to();
- $this->assertEqual($result, $configs->test['to']);
+ $this->assertEquals($configs->test['to'], $result);
$result = $this->CakeEmail->from();
- $this->assertEqual($result, $configs->test['from']);
+ $this->assertEquals($configs->test['from'], $result);
$result = $this->CakeEmail->subject();
- $this->assertEqual($result, $configs->test['subject']);
+ $this->assertEquals($configs->test['subject'], $result);
$result = $this->CakeEmail->transport();
- $this->assertEqual($result, $configs->test['transport']);
+ $this->assertEquals($configs->test['transport'], $result);
$result = $this->CakeEmail->transportClass();
$this->assertTrue($result instanceof DebugTransport);
@@ -933,16 +933,16 @@ public function testConstructWithConfigArray() {
$this->CakeEmail = new CakeEmail($configs);
$result = $this->CakeEmail->to();
- $this->assertEqual($result, array($configs['to'] => $configs['to']));
+ $this->assertEquals(array($configs['to'] => $configs['to']), $result);
$result = $this->CakeEmail->from();
- $this->assertEqual($result, $configs['from']);
+ $this->assertEquals($configs['from'], $result);
$result = $this->CakeEmail->subject();
- $this->assertEqual($result, $configs['subject']);
+ $this->assertEquals($configs['subject'], $result);
$result = $this->CakeEmail->transport();
- $this->assertEqual($result, $configs['transport']);
+ $this->assertEquals($configs['transport'], $result);
$result = $this->CakeEmail->transportClass();
$this->assertTrue($result instanceof DebugTransport);
@@ -968,16 +968,16 @@ public function testConstructWithConfigString() {
$this->CakeEmail = new CakeEmail('test');
$result = $this->CakeEmail->to();
- $this->assertEqual($result, $configs->test['to']);
+ $this->assertEquals($configs->test['to'], $result);
$result = $this->CakeEmail->from();
- $this->assertEqual($result, $configs->test['from']);
+ $this->assertEquals($configs->test['from'], $result);
$result = $this->CakeEmail->subject();
- $this->assertEqual($result, $configs->test['subject']);
+ $this->assertEquals($configs->test['subject'], $result);
$result = $this->CakeEmail->transport();
- $this->assertEqual($result, $configs->test['transport']);
+ $this->assertEquals($configs->test['transport'], $result);
$result = $this->CakeEmail->transportClass();
$this->assertTrue($result instanceof DebugTransport);
View
44 lib/Cake/Test/Case/Network/Email/DebugTransportTest.php
@@ -17,8 +17,6 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('CakeEmail', 'Network/Email');
-App::uses('AbstractTransport', 'Network/Email');
-App::uses('DebugTransport', 'Network/Email');
/**
* Test case
@@ -26,14 +24,6 @@
*/
class DebugTransportTest extends CakeTestCase {
-/**
- * Setup
- *
- * @return void
- */
- public function setUp() {
- $this->DebugTransport = new DebugTransport();
- }
/**
* testSend method
@@ -42,7 +32,7 @@ public function setUp() {
*/
public function testSend() {
$this->getMock('CakeEmail', array('message'), array(), 'DebugCakeEmail');
- $email = new DebugCakeEmail();
+ $email = new DebugCakeEmail(array('transport' => 'Debug'));
$email->from('noreply@cakephp.org', 'CakePHP Test');
$email->to('cake@cakephp.org', 'CakePHP');
$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
@@ -51,23 +41,25 @@ public function testSend() {
$email->subject('Testing Message');
$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '')));
- $data = "From: CakePHP Test <noreply@cakephp.org>\r\n";
- $data .= "To: CakePHP <cake@cakephp.org>\r\n";
- $data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>\r\n";
- $data .= "Bcc: phpnut@cakephp.org\r\n";
- $data .= "X-Mailer: CakePHP Email\r\n";
- $data .= "Date: " . date(DATE_RFC2822) . "\r\n";
- $data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>\r\n";
- $data .= "Subject: Testing Message\r\n";
- $data .= "MIME-Version: 1.0\r\n";
- $data .= "Content-Type: text/plain; charset=UTF-8\r\n";
- $data .= "Content-Transfer-Encoding: 7bit";
- $data .= "\n\n";
- $data .= "First Line\n";
+ $headers = "From: CakePHP Test <noreply@cakephp.org>\r\n";
+ $headers .= "To: CakePHP <cake@cakephp.org>\r\n";
+ $headers .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>\r\n";
+ $headers .= "Bcc: phpnut@cakephp.org\r\n";
+ $headers .= "X-Mailer: CakePHP Email\r\n";
+ $headers .= "Date: " . date(DATE_RFC2822) . "\r\n";
+ $headers .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>\r\n";
+ $headers .= "Subject: Testing Message\r\n";
+ $headers .= "MIME-Version: 1.0\r\n";
+ $headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
+ $headers .= "Content-Transfer-Encoding: 7bit";
+
+ $data = "First Line\n";
$data .= "Second Line\n";
- $result = $this->DebugTransport->send($email);
- $this->assertEquals($data, $result);
+ $result = $email->transportClass()->send($email);
+
+ $this->assertEquals($headers, $result['headers']);
+ $this->assertEquals($data, $result['message']);
}
}
View
6 lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php
@@ -61,7 +61,7 @@ protected function _generateSocket() {
* @param string $method
* @param string $args
* @return mixed
- */
+ */
public function __call($method, $args) {
$method = '_' . $method;
return $this->$method();
@@ -73,7 +73,7 @@ public function __call($method, $args) {
* Test case
*
*/
-class StmpProtocolTest extends CakeTestCase {
+class SmtpTransportTest extends CakeTestCase {
/**
* Setup
@@ -130,7 +130,7 @@ public function testConnectHelo() {
* @expectedException Exception
* @return void
*/
- public function testConnetFail() {
+ public function testConnectFail() {
$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
Please sign in to comment.
Something went wrong with that request. Please try again.