Skip to content

Commit cc2bec7

Browse files
More detailed error message for SMTP errors
1 parent 7131be9 commit cc2bec7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

overrides/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport
3838
/** Source Ip */
3939
protected $sourceIp;
4040

41+
protected $last_command;
42+
4143
/** Return an array of params for the Buffer */
4244
abstract protected function getBufferParams();
4345

@@ -140,6 +142,7 @@ public function start()
140142
return;
141143
}
142144
}
145+
$this->last_command = 'STREAM_CLIENT_CONNECT';
143146

144147
try {
145148
$this->buffer->initialize($this->getBufferParams());
@@ -326,6 +329,8 @@ public function getBuffer()
326329
*/
327330
public function executeCommand($command, $codes = [], &$failures = null, $pipeline = false, $address = null)
328331
{
332+
$this->last_command = $command;
333+
329334
$failures = (array) $failures;
330335
$seq = $this->buffer->write($command);
331336
if ($evt = $this->eventDispatcher->createCommandEvent($this, $command, $codes)) {
@@ -395,6 +400,7 @@ protected function doDataCommand(&$failedRecipients)
395400
/** Stream the contents of the message over the buffer */
396401
protected function streamMessage(Swift_Mime_SimpleMessage $message)
397402
{
403+
$this->last_command = 'STREAMMESSAGE';
398404
$this->buffer->setWriteTranslations(["\r\n." => "\r\n.."]);
399405
try {
400406
$message->toByteStream($this->buffer);
@@ -431,6 +437,21 @@ protected function getReversePath(Swift_Mime_SimpleMessage $message)
431437
/** Throw a TransportException, first sending it to any listeners */
432438
protected function throwException(Swift_TransportException $e)
433439
{
440+
$dbt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
441+
$caller_function = isset($dbt[1]['function']) ? $dbt[1]['function'] : null;
442+
443+
if ($caller_function) {
444+
$exception_type = get_class($e);
445+
$last_command = $this->last_command;
446+
// Remove sensitive data from command.
447+
if (strstr($last_command, ':')) {
448+
list($last_command) = explode(':', $last_command);
449+
} else {
450+
list($last_command) = explode(' ', $last_command);
451+
}
452+
$e = new $exception_type('Swift_Transport_AbstractSmtpTransport::'.$caller_function.'(); '.($last_command ? 'Last Command: '.$last_command.'; ' : '').$e->getMessage());
453+
}
454+
434455
if ($evt = $this->eventDispatcher->createTransportExceptionEvent($this, $e)) {
435456
$this->eventDispatcher->dispatchEvent($evt, 'exceptionThrown');
436457
if (!$evt->bubbleCancelled()) {

0 commit comments

Comments
 (0)