From: schlimpf Date: Fri, 13 Dec 2013 09:01:15 +0000 (+0100) Subject: Fix Bug when trying to send a mail after the SMTPMailSender threw an exception X-Git-Tag: 2.0.4~11^2~1^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5e43e307b221cb253c59698fb64956d14a185db3;p=GitHub%2FWoltLab%2FWCF.git 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" --- 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. *