* @author Brent R. Matzelle (original founder)
- * @copyright 2012 - 2019 Marcus Bointon
+ * @copyright 2012 - 2020 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
@@ -45,7 +46,7 @@ class POP3
*
* @var string
*/
- const VERSION = '6.1.6';
+ const VERSION = '6.2.0';
/**
* Default POP3 port number.
@@ -62,12 +63,16 @@ class POP3
const DEFAULT_TIMEOUT = 30;
/**
- * Debug display level.
- * Options: 0 = no, 1+ = yes.
+ * POP3 class debug output mode.
+ * Debug output level.
+ * Options:
+ * @see POP3::DEBUG_OFF: No output
+ * @see POP3::DEBUG_SERVER: Server messages, connection/server errors
+ * @see POP3::DEBUG_CLIENT: Client and Server messages, connection/server errors
*
* @var int
*/
- public $do_debug = 0;
+ public $do_debug = self::DEBUG_OFF;
/**
* POP3 mail server hostname.
@@ -130,6 +135,28 @@ class POP3
*/
const LE = "\r\n";
+ /**
+ * Debug level for no output.
+ *
+ * @var int
+ */
+ const DEBUG_OFF = 0;
+
+ /**
+ * Debug level to show server -> client messages
+ * also shows clients connection errors or errors from server
+ *
+ * @var int
+ */
+ const DEBUG_SERVER = 1;
+
+ /**
+ * Debug level to show client -> server and server -> client messages.
+ *
+ * @var int
+ */
+ const DEBUG_CLIENT = 2;
+
/**
* Simple static wrapper for all-in-one POP before SMTP.
*
@@ -329,7 +356,7 @@ class POP3
protected function getResponse($size = 128)
{
$response = fgets($this->pop_conn, $size);
- if ($this->do_debug >= 1) {
+ if ($this->do_debug >= self::DEBUG_SERVER) {
echo 'Server -> Client: ', $response;
}
@@ -346,7 +373,7 @@ class POP3
protected function sendString($string)
{
if ($this->pop_conn) {
- if ($this->do_debug >= 2) { //Show client messages when debug >= 2
+ if ($this->do_debug >= self::DEBUG_CLIENT) { //Show client messages when debug >= 2
echo 'Client -> Server: ', $string;
}
@@ -384,7 +411,7 @@ class POP3
protected function setError($error)
{
$this->errors[] = $error;
- if ($this->do_debug >= 1) {
+ if ($this->do_debug >= self::DEBUG_SERVER) {
echo '';
foreach ($this->errors as $e) {
print_r($e);
diff --git a/data/web/inc/lib/vendor/phpmailer/phpmailer/src/SMTP.php b/data/web/inc/lib/vendor/phpmailer/phpmailer/src/SMTP.php
index aa555514..ab7f46e4 100644
--- a/data/web/inc/lib/vendor/phpmailer/phpmailer/src/SMTP.php
+++ b/data/web/inc/lib/vendor/phpmailer/phpmailer/src/SMTP.php
@@ -1,4 +1,5 @@
* @author Andy Prevost (codeworxtech)
* @author Brent R. Matzelle (original founder)
- * @copyright 2012 - 2019 Marcus Bointon
+ * @copyright 2012 - 2020 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
@@ -34,7 +35,7 @@ class SMTP
*
* @var string
*/
- const VERSION = '6.1.6';
+ const VERSION = '6.2.0';
/**
* SMTP line break constant.
@@ -311,12 +312,6 @@ class SMTP
*/
public function connect($host, $port = null, $timeout = 30, $options = [])
{
- static $streamok;
- //This is enabled by default since 5.0.0 but some providers disable it
- //Check this once and cache the result
- if (null === $streamok) {
- $streamok = function_exists('stream_socket_client');
- }
// Clear errors to avoid confusion
$this->setError('');
// Make sure we are __not__ connected
@@ -335,12 +330,48 @@ class SMTP
(count($options) > 0 ? var_export($options, true) : 'array()'),
self::DEBUG_CONNECTION
);
+
+ $this->smtp_conn = $this->getSMTPConnection($host, $port, $timeout, $options);
+
+ if ($this->smtp_conn === false) {
+ //Error info already set inside `getSMTPConnection()`
+ return false;
+ }
+
+ $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
+
+ // Get any announcement
+ $this->last_reply = $this->get_lines();
+ $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
+
+ return true;
+ }
+
+ /**
+ * Create connection to the SMTP server.
+ *
+ * @param string $host SMTP server IP or host name
+ * @param int $port The port number to connect to
+ * @param int $timeout How long to wait for the connection to open
+ * @param array $options An array of options for stream_context_create()
+ *
+ * @return false|resource
+ */
+ protected function getSMTPConnection($host, $port = null, $timeout = 30, $options = [])
+ {
+ static $streamok;
+ //This is enabled by default since 5.0.0 but some providers disable it
+ //Check this once and cache the result
+ if (null === $streamok) {
+ $streamok = function_exists('stream_socket_client');
+ }
+
$errno = 0;
$errstr = '';
if ($streamok) {
$socket_context = stream_context_create($options);
set_error_handler([$this, 'errorHandler']);
- $this->smtp_conn = stream_socket_client(
+ $connection = stream_socket_client(
$host . ':' . $port,
$errno,
$errstr,
@@ -356,7 +387,7 @@ class SMTP
self::DEBUG_CONNECTION
);
set_error_handler([$this, 'errorHandler']);
- $this->smtp_conn = fsockopen(
+ $connection = fsockopen(
$host,
$port,
$errno,
@@ -365,8 +396,9 @@ class SMTP
);
restore_error_handler();
}
+
// Verify we connected properly
- if (!is_resource($this->smtp_conn)) {
+ if (!is_resource($connection)) {
$this->setError(
'Failed to connect to server',
'',
@@ -381,22 +413,19 @@ class SMTP
return false;
}
- $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
+
// SMTP server can take longer to respond, give longer timeout for first read
// Windows does not have support for this timeout function
if (strpos(PHP_OS, 'WIN') !== 0) {
- $max = (int) ini_get('max_execution_time');
- // Don't bother if unlimited
- if (0 !== $max && $timeout > $max) {
+ $max = (int)ini_get('max_execution_time');
+ // Don't bother if unlimited, or if set_time_limit is disabled
+ if (0 !== $max && $timeout > $max && strpos(ini_get('disable_functions'), 'set_time_limit') === false) {
@set_time_limit($timeout);
}
- stream_set_timeout($this->smtp_conn, $timeout, 0);
+ stream_set_timeout($connection, $timeout, 0);
}
- // Get any announcement
- $announce = $this->get_lines();
- $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
- return true;
+ return $connection;
}
/**
@@ -511,11 +540,12 @@ class SMTP
return false;
}
// Send encoded username and password
- if (!$this->sendCommand(
- 'User & Password',
- base64_encode("\0" . $username . "\0" . $password),
- 235
- )
+ if (
+ !$this->sendCommand(
+ 'User & Password',
+ base64_encode("\0" . $username . "\0" . $password),
+ 235
+ )
) {
return false;
}
@@ -1058,8 +1088,10 @@ class SMTP
{
//If SMTP transcripts are left enabled, or debug output is posted online
//it can leak credentials, so hide credentials in all but lowest level
- if (self::DEBUG_LOWLEVEL > $this->do_debug &&
- in_array($command, ['User & Password', 'Username', 'Password'], true)) {
+ if (
+ self::DEBUG_LOWLEVEL > $this->do_debug &&
+ in_array($command, ['User & Password', 'Username', 'Password'], true)
+ ) {
$this->edebug('CLIENT -> SERVER: [credentials hidden]', self::DEBUG_CLIENT);
} else {
$this->edebug('CLIENT -> SERVER: ' . $data, self::DEBUG_CLIENT);
@@ -1166,13 +1198,41 @@ class SMTP
$selW = null;
while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
//Must pass vars in here as params are by reference
- if (!stream_select($selR, $selW, $selW, $this->Timelimit)) {
+ //solution for signals inspired by https://github.com/symfony/symfony/pull/6540
+ set_error_handler([$this, 'errorHandler']);
+ $n = stream_select($selR, $selW, $selW, $this->Timelimit);
+ restore_error_handler();
+
+ if ($n === false) {
+ $message = $this->getError()['detail'];
+
+ $this->edebug(
+ 'SMTP -> get_lines(): select failed (' . $message . ')',
+ self::DEBUG_LOWLEVEL
+ );
+
+ //stream_select returns false when the `select` system call is interrupted
+ //by an incoming signal, try the select again
+ if (stripos($message, 'interrupted system call') !== false) {
+ $this->edebug(
+ 'SMTP -> get_lines(): retrying stream_select',
+ self::DEBUG_LOWLEVEL
+ );
+ $this->setError('');
+ continue;
+ }
+
+ break;
+ }
+
+ if (!$n) {
$this->edebug(
'SMTP -> get_lines(): select timed-out in (' . $this->Timelimit . ' sec)',
self::DEBUG_LOWLEVEL
);
break;
}
+
//Deliberate noise suppression - errors are handled afterwards
$str = @fgets($this->smtp_conn, self::MAX_REPLY_LENGTH);
$this->edebug('SMTP INBOUND: "' . trim($str) . '"', self::DEBUG_LOWLEVEL);