From 5a6992d3c1efdb7727eb65bfa2a62b30469b40a7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 11 Sep 2018 08:08:33 +0200 Subject: [PATCH 1/2] tweaked error message when response is empty --- lib/classes/Swift/Transport/AbstractSmtpTransport.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/classes/Swift/Transport/AbstractSmtpTransport.php b/lib/classes/Swift/Transport/AbstractSmtpTransport.php index 39b6e2135..fa1edd533 100644 --- a/lib/classes/Swift/Transport/AbstractSmtpTransport.php +++ b/lib/classes/Swift/Transport/AbstractSmtpTransport.php @@ -443,6 +443,10 @@ protected function throwException(Swift_TransportException $e) /** Throws an Exception if a response code is incorrect */ protected function assertResponseCode($response, $wanted) { + if (!$response) { + $this->throwException(new Swift_TransportException('Expected response code '.implode('/', $wanted).' but got an empty response')); + } + list($code) = sscanf($response, '%3d'); $valid = (empty($wanted) || in_array($code, $wanted)); @@ -452,12 +456,7 @@ protected function assertResponseCode($response, $wanted) } if (!$valid) { - $this->throwException( - new Swift_TransportException( - 'Expected response code '.implode('/', $wanted).' but got code '. - '"'.$code.'", with message "'.$response.'"', - $code) - ); + $this->throwException(new Swift_TransportException('Expected response code '.implode('/', $wanted).' but got code "'.$code.'", with message "'.$response.'"', $code)); } } From 2ea9f8c0d7bee76f6b85a051b3c33988aa9d41d7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 11 Sep 2018 08:11:14 +0200 Subject: [PATCH 2/2] added previous exception to exception --- lib/classes/Swift/Transport/AbstractSmtpTransport.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/classes/Swift/Transport/AbstractSmtpTransport.php b/lib/classes/Swift/Transport/AbstractSmtpTransport.php index fa1edd533..8266f882e 100644 --- a/lib/classes/Swift/Transport/AbstractSmtpTransport.php +++ b/lib/classes/Swift/Transport/AbstractSmtpTransport.php @@ -188,10 +188,7 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul } if (!$reversePath = $this->getReversePath($message)) { - $this->throwException(new Swift_TransportException( - 'Cannot send message without a sender address' - ) - ); + $this->throwException(new Swift_TransportException('Cannot send message without a sender address')); } $to = (array) $message->getTo(); @@ -472,10 +469,7 @@ protected function getFullResponse($seq) } catch (Swift_TransportException $e) { $this->throwException($e); } catch (Swift_IoException $e) { - $this->throwException( - new Swift_TransportException( - $e->getMessage()) - ); + $this->throwException(new Swift_TransportException($e->getMessage(), 0, $e)); } return $response;