From 5e43e307b221cb253c59698fb64956d14a185db3 Mon Sep 17 00:00:00 2001 From: schlimpf Date: Fri, 13 Dec 2013 10:01:15 +0100 Subject: [PATCH] Fix Bug when trying to send a mail after the SMTPMailSender threw an exception Added a abort() function to cancel the current process. In case the SMTPMailSender throws an exception which is catched by another script, no further mails could be sent because the last command was not aborted. It may be a good idea to use a different exception type than "SystemException" --- .../lib/system/mail/SMTPMailSender.class.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/mail/SMTPMailSender.class.php b/wcfsetup/install/files/lib/system/mail/SMTPMailSender.class.php index 1a1cd515d4..d2b9edf161 100644 --- a/wcfsetup/install/files/lib/system/mail/SMTPMailSender.class.php +++ b/wcfsetup/install/files/lib/system/mail/SMTPMailSender.class.php @@ -137,6 +137,7 @@ class SMTPMailSender extends MailSender { $this->write('MAIL FROM:<'.$mail->getFrom().'>'); $this->getSMTPStatus(); if ($this->statusCode != 250) { + $this->abort(); throw new SystemException($this->formatError("wrong from format '".$mail->getFrom()."'")); } @@ -147,6 +148,7 @@ class SMTPMailSender extends MailSender { $this->getSMTPStatus(); if ($this->statusCode != 250 && $this->statusCode != 251) { if ($this->statusCode < 550) { + $this->abort(); throw new SystemException($this->formatError("wrong recipient format '".$recipient."'")); } continue; @@ -154,7 +156,7 @@ class SMTPMailSender extends MailSender { $recipientCounter++; } if (!$recipientCounter) { - $this->write("RSET"); + $this->abort(); return; } @@ -162,6 +164,7 @@ class SMTPMailSender extends MailSender { $this->write("DATA"); $this->getSMTPStatus(); if ($this->statusCode != 354 && $this->statusCode != 250) { + $this->abort(); throw new SystemException($this->formatError("smtp error")); } @@ -179,6 +182,7 @@ class SMTPMailSender extends MailSender { $this->getSMTPStatus(); if ($this->statusCode != 250) { + $this->abort(); throw new SystemException($this->formatError("message sending failed")); } } @@ -211,6 +215,15 @@ class SMTPMailSender extends MailSender { return $result; } + /** + * Aborts the current process. This is needed in case a new mail should be + * sent after a exception has occured + */ + protected function abort() { + $this->write("RSET"); + $this->read(); // read response, but do not care about status here + } + /** * Gets error code and message from a server message. * -- 2.20.1