0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-20 01:52:15 +02:00

Merge pull request #2814 from czirkoszoltan/avoid-error-message-when-could-not-connect

Avoid POP3 client error message when TCP connection failed
This commit is contained in:
Marcus Bointon 2022-10-27 22:24:18 +02:00 committed by GitHub
commit a5bc7ddba9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -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.

View File

@ -42,7 +42,7 @@ final class PopBeforeSmtpTest extends TestCase
* Set up default include path.
* Default to the dir above the test dir, i.e. the project home dir.
*/
define('PHPMAILER_INCLUDE_DIR', dirname(__DIR__));
define('PHPMAILER_INCLUDE_DIR', dirname(dirname(__DIR__)));
}
}
@ -54,6 +54,10 @@ final class PopBeforeSmtpTest extends TestCase
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('This test needs a non-Windows OS to run');
}
// Chdir to test directory as runfakepopserver.sh runs fakepopserver.sh
// from its working directory.
chdir(PHPMAILER_INCLUDE_DIR . "/test");
}
/**
@ -120,4 +124,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'
);
}
}

View File

@ -123,4 +123,4 @@ while [ ${BREAK} -eq 0 ] ; do
fi
done
echo "+OK Bye!\r\n"
echo -en "+OK Bye!\r\n"