mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-12 06:56:24 +00:00
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
This commit is contained in:
parent
dbe70a3dd2
commit
aabbf0ed85
2 changed files with 31 additions and 14 deletions
|
@ -310,7 +310,9 @@ class EmailComponent extends Object{
|
||||||
if ($this->_debug) {
|
if ($this->_debug) {
|
||||||
$this->delivery = 'debug';
|
$this->delivery = 'debug';
|
||||||
}
|
}
|
||||||
|
|
||||||
$__method = '__'.$this->delivery;
|
$__method = '__'.$this->delivery;
|
||||||
|
|
||||||
return $this->$__method();
|
return $this->$__method();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -589,14 +591,17 @@ class EmailComponent extends Object{
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __smtp() {
|
function __smtp() {
|
||||||
$response = $this->__smtpConnect($this->smtpOptions);
|
$response = $this->__smtpConnect();
|
||||||
|
debug($response);
|
||||||
|
|
||||||
if ($response['status'] == false) {
|
if ($response['errno'] != 0 && $response['status'] === false) {
|
||||||
$this->smtpError = "{$response['errno']}: {$response['errstr']}";
|
$this->smtpError = "{$response['errno']}: {$response['errstr']}";
|
||||||
return false;
|
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")) {
|
if (!$this->__sendData("MAIL FROM: {$this->from}\r\n")) {
|
||||||
return false;
|
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("DATA\r\n{$this->__header}\r\n{$this->__message}\r\n\r\n\r\n.\r\n", false);
|
||||||
$this->__sendData("QUIT\r\n", false);
|
$this->__sendData("QUIT\r\n", false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private method for connecting to an SMTP server
|
* Private method for connecting to an SMTP server
|
||||||
*
|
*
|
||||||
|
@ -617,14 +624,20 @@ class EmailComponent extends Object{
|
||||||
* @param array $options SMTP connection options
|
* @param array $options SMTP connection options
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function __smtpConnect($options) {
|
function __smtpConnect() {
|
||||||
$status = true;
|
$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) {
|
if ($this->__smtpConnection == false) {
|
||||||
$status = false;
|
$status = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$response = $this->__getSmtpResponse();
|
||||||
|
|
||||||
return array('status' => $status,
|
return array('status' => $status,
|
||||||
'errno' => $errno,
|
'errno' => $errno,
|
||||||
'errstr' => $errstr);
|
'errstr' => $errstr);
|
||||||
|
@ -646,10 +659,13 @@ class EmailComponent extends Object{
|
||||||
@fwrite($this->__smtpConnection, $data);
|
@fwrite($this->__smtpConnection, $data);
|
||||||
$response = $this->__getSmtpResponse();
|
$response = $this->__getSmtpResponse();
|
||||||
|
|
||||||
if ($check == true && !stristr($response, '250')) {
|
if ($check != false) {
|
||||||
|
if (stristr($response, '250') === false) {
|
||||||
$this->smtpError = $response;
|
$this->smtpError = $response;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -51,6 +51,7 @@ class EmailTest extends CakeTestCase {
|
||||||
function testBadSmtpSend() {
|
function testBadSmtpSend() {
|
||||||
if (@fsockopen('localhost', 25)) {
|
if (@fsockopen('localhost', 25)) {
|
||||||
$this->Controller->Email->smtpOptions['host'] = 'blah';
|
$this->Controller->Email->smtpOptions['host'] = 'blah';
|
||||||
|
$this->Controller->Email->delivery = 'smtp';
|
||||||
$this->assertFalse($this->Controller->Email->send('Should not work'));
|
$this->assertFalse($this->Controller->Email->send('Should not work'));
|
||||||
} else {
|
} else {
|
||||||
$this->skipUnless(@fsockopen('localhost', 25), 'Must be able to connect to localhost port 25');
|
$this->skipUnless(@fsockopen('localhost', 25), 'Must be able to connect to localhost port 25');
|
||||||
|
|
Loading…
Add table
Reference in a new issue