Skip to content

Commit

Permalink
Exit early if SMTP connection fails.
Browse files Browse the repository at this point in the history
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 3415840
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 107 deletions.
6 changes: 5 additions & 1 deletion lib/Cake/Network/Email/SmtpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'));
Expand Down
Loading

0 comments on commit 3415840

Please sign in to comment.