From aabbf0ed850b1e9f8cbd3087db9b1883379932e6 Mon Sep 17 00:00:00 2001 From: phpnut Date: Sat, 11 Aug 2007 13:31:12 +0000 Subject: [PATCH] Adding patch from #2908, fixed to read the response from the server git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5505 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/email.php | 42 +++++++++++++------ .../libs/controller/components/email.test.php | 3 +- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index bd923201d..95ef808de 100644 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -310,7 +310,9 @@ class EmailComponent extends Object{ if ($this->_debug) { $this->delivery = 'debug'; } + $__method = '__'.$this->delivery; + return $this->$__method(); } /** @@ -589,14 +591,17 @@ class EmailComponent extends Object{ * @access private */ function __smtp() { - $response = $this->__smtpConnect($this->smtpOptions); - - if ($response['status'] == false) { + $response = $this->__smtpConnect(); + debug($response); + + if ($response['errno'] != 0 && $response['status'] === false) { $this->smtpError = "{$response['errno']}: {$response['errstr']}"; return false; } - $this->__sendData("HELO cake\r\n", false); + if (!$this->__sendData("HELO cake\r\n")) { + return false; + } if (!$this->__sendData("MAIL FROM: {$this->from}\r\n")) { return false; @@ -608,8 +613,10 @@ class EmailComponent extends Object{ $this->__sendData("DATA\r\n{$this->__header}\r\n{$this->__message}\r\n\r\n\r\n.\r\n", false); $this->__sendData("QUIT\r\n", false); - return true; + + return true; } + /** * Private method for connecting to an SMTP server * @@ -617,14 +624,20 @@ class EmailComponent extends Object{ * @param array $options SMTP connection options * @return array */ - function __smtpConnect($options) { + function __smtpConnect() { $status = true; - $this->__smtpConnection = @fsockopen($options['host'], $options['port'], $errno, $errstr, $options['timeout']); + $this->__smtpConnection = @fsockopen($this->smtpOptions['host'], + $this->smtpOptions['port'], + $errno, + $errstr, + $this->smtpOptions['timeout']); if ($this->__smtpConnection == false) { $status = false; } - + + $response = $this->__getSmtpResponse(); + return array('status' => $status, 'errno' => $errno, 'errstr' => $errstr); @@ -645,11 +658,14 @@ class EmailComponent extends Object{ function __sendData($data, $check = true) { @fwrite($this->__smtpConnection, $data); $response = $this->__getSmtpResponse(); - - if ($check == true && !stristr($response, '250')) { - $this->smtpError = $response; - return false; + + if ($check != false) { + if (stristr($response, '250') === false) { + $this->smtpError = $response; + return false; + } } + return true; } /** @@ -679,4 +695,4 @@ class EmailComponent extends Object{ return true; } } -?> \ No newline at end of file +?> diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 9b51843a3..b792d2191 100644 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -51,6 +51,7 @@ class EmailTest extends CakeTestCase { function testBadSmtpSend() { if (@fsockopen('localhost', 25)) { $this->Controller->Email->smtpOptions['host'] = 'blah'; + $this->Controller->Email->delivery = 'smtp'; $this->assertFalse($this->Controller->Email->send('Should not work')); } else { $this->skipUnless(@fsockopen('localhost', 25), 'Must be able to connect to localhost port 25'); @@ -71,4 +72,4 @@ class EmailTest extends CakeTestCase { } } } -?> \ No newline at end of file +?>