Avoid POP3 client error message when TCP connection failed
The disconnect() method throws a TypeError when the TCP connection cannot be created. Error and trace: fgets(): Argument #1 ($stream) must be of type resource, bool given phpmailer/phpmailer/src/POP3.php(372): fgets() phpmailer/phpmailer/src/POP3.php(345): PHPMailer\PHPMailer\POP3->getResponse() phpmailer/phpmailer/src/POP3.php(230): PHPMailer\PHPMailer\POP3->disconnect() PHPMailer\PHPMailer\POP3->authorise() Reproduce with: include __DIR__ . "/POP3.php"; \PHPMailer\PHPMailer\POP3::popBeforeSmtp('doesnotexist', 110);
This commit is contained in:
parent
00b7f5162a
commit
b4b493c8f3
|
|
@ -337,6 +337,11 @@ class POP3
|
|||
*/
|
||||
public function disconnect()
|
||||
{
|
||||
// If could not connect at all, no need to disconnect
|
||||
if ($this->pop_conn === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->sendString('QUIT' . static::LE);
|
||||
|
||||
// RFC 1939 shows POP3 server sending a +OK response to the QUIT command.
|
||||
|
|
|
|||
|
|
@ -120,4 +120,16 @@ final class PopBeforeSmtpTest extends TestCase
|
|||
@shell_exec('kill -TERM ' . escapeshellarg($pid));
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case when POP3 server is unreachable.
|
||||
*/
|
||||
public function testPopBeforeSmtpUnreachable()
|
||||
{
|
||||
// There is no POP3 server at all. Port is different again.
|
||||
self::assertFalse(
|
||||
POP3::popBeforeSmtp('localhost', 1102, 10, 'user', 'xxx'),
|
||||
'POP before SMTP should have failed'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue