Skip to content
Permalink
Browse files

Exit early if SMTP connection fails.

If the SMTP connection is disconnected (read() returns false) we should
exit early and not wait for the read timeout. This has the added benefit
of making the mocks much simpler.

Refs #10221
  • Loading branch information...
markstory committed Feb 14, 2017
1 parent aa8d708 commit 34158407b2ef8131b9a4223439137f5834879c99
Showing with 75 additions and 107 deletions.
  1. +5 −1 lib/Cake/Network/Email/SmtpTransport.php
  2. +70 −106 lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php
@@ -352,7 +352,11 @@ protected function _smtpSend($data, $checkCode = '250') {
$response = '';
$startTime = time();
while (substr($response, -2) !== "\r\n" && ((time() - $startTime) < $this->_config['timeout'])) {
$response .= $this->_socket->read();
$bytes = $this->_socket->read();
if ($bytes === false || $bytes === null) {
break;
}
$response .= $bytes;
}
if (substr($response, -2) !== "\r\n") {
throw new SocketException(__d('cake_dev', 'SMTP timeout.'));
Oops, something went wrong.

0 comments on commit 3415840

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.