From 9099f8602be8141d2eac7ebe19505d2af3815cab Mon Sep 17 00:00:00 2001 From: michalsn Date: Tue, 29 Jul 2025 11:54:21 +0200 Subject: [PATCH 1/6] fix: use is_resource() instead of null check for SMTP connection validation --- system/Email/Email.php | 2 +- user_guide_src/source/changelogs/v4.6.3.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/system/Email/Email.php b/system/Email/Email.php index 6db52f3fa656..7db123a1d4de 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -2227,7 +2227,7 @@ protected function mimeTypes($ext = '') public function __destruct() { - if ($this->SMTPConnect !== null) { + if (is_resource($this->SMTPConnect)) { try { $this->sendCommand('quit'); } catch (ErrorException $e) { diff --git a/user_guide_src/source/changelogs/v4.6.3.rst b/user_guide_src/source/changelogs/v4.6.3.rst index fa7786891956..c4d79f349f70 100644 --- a/user_guide_src/source/changelogs/v4.6.3.rst +++ b/user_guide_src/source/changelogs/v4.6.3.rst @@ -31,6 +31,7 @@ Bugs Fixed ********** - **Email:** Fixed a bug with CID check when building email attachments. +- **Email:** Fixed SMTP connection resource validation in the class destructor. See the repo's `CHANGELOG.md `_ From cc7f32fe8b2b7ef30b082035c201fac2a5e2314f Mon Sep 17 00:00:00 2001 From: michalsn Date: Tue, 29 Jul 2025 12:02:57 +0200 Subject: [PATCH 2/6] update changelog --- user_guide_src/source/changelogs/v4.6.3.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.6.3.rst b/user_guide_src/source/changelogs/v4.6.3.rst index c4d79f349f70..ae525e52c3f8 100644 --- a/user_guide_src/source/changelogs/v4.6.3.rst +++ b/user_guide_src/source/changelogs/v4.6.3.rst @@ -31,7 +31,7 @@ Bugs Fixed ********** - **Email:** Fixed a bug with CID check when building email attachments. -- **Email:** Fixed SMTP connection resource validation in the class destructor. +- **Email:** Fixed a bug with SMTP connection resource validation in the class destructor. See the repo's `CHANGELOG.md `_ From a577705a4adf90fac55f680b16309e6503f8838c Mon Sep 17 00:00:00 2001 From: michalsn Date: Tue, 29 Jul 2025 20:02:46 +0200 Subject: [PATCH 3/6] add the isSMTPConnected() method for a type-safe check --- system/Email/Email.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/system/Email/Email.php b/system/Email/Email.php index 7db123a1d4de..a11dd2a950cf 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -1886,7 +1886,7 @@ protected function SMTPEnd() */ protected function SMTPConnect() { - if (is_resource($this->SMTPConnect)) { + if ($this->isSMTPConnected()) { return true; } @@ -1910,7 +1910,7 @@ protected function SMTPConnect() $this->SMTPTimeout, ); - if (! is_resource($this->SMTPConnect)) { + if (! $this->isSMTPConnected()) { $this->setErrorMessage(lang('Email.SMTPError', [$errno . ' ' . $errstr])); return false; @@ -2227,7 +2227,7 @@ protected function mimeTypes($ext = '') public function __destruct() { - if (is_resource($this->SMTPConnect)) { + if ($this->isSMTPConnected()) { try { $this->sendCommand('quit'); } catch (ErrorException $e) { @@ -2284,4 +2284,14 @@ protected function setArchiveValues(): array return $this->archive; } + + /** + * Checks if there is an active SMTP connection. + * + * @return bool True if SMTP connection is established and open, false otherwise + */ + protected function isSMTPConnected(): bool + { + return $this->SMTPConnect !== null && get_debug_type($this->SMTPConnect) !== 'resource (closed)'; + } } From 04f5b42af74d9f4840168c7e41f6f4370b1fa352 Mon Sep 17 00:00:00 2001 From: michalsn Date: Tue, 29 Jul 2025 20:16:55 +0200 Subject: [PATCH 4/6] update the isSMTPConnected() method to also check for a false value --- system/Email/Email.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/Email/Email.php b/system/Email/Email.php index a11dd2a950cf..e450e2b1b1ef 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -2292,6 +2292,8 @@ protected function setArchiveValues(): array */ protected function isSMTPConnected(): bool { - return $this->SMTPConnect !== null && get_debug_type($this->SMTPConnect) !== 'resource (closed)'; + return $this->SMTPConnect !== null + && $this->SMTPConnect !== false + && get_debug_type($this->SMTPConnect) !== 'resource (closed)'; } } From d32b8572689787bd8efb44573aa947e986bc6fa6 Mon Sep 17 00:00:00 2001 From: michalsn Date: Wed, 30 Jul 2025 08:50:09 +0200 Subject: [PATCH 5/6] update phpdoc for the SMTPConnect property --- system/Email/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Email/Email.php b/system/Email/Email.php index e450e2b1b1ef..9ed8465daa66 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -263,7 +263,7 @@ class Email /** * SMTP Connection socket placeholder * - * @var resource|null + * @var false|resource|null */ protected $SMTPConnect; From 2e8091ec67d3ac1cb344d7aa9b1d90e4f1960ca4 Mon Sep 17 00:00:00 2001 From: michalsn Date: Wed, 30 Jul 2025 08:52:06 +0200 Subject: [PATCH 6/6] cs fix --- system/Debug/Toolbar/Collectors/Routes.php | 2 +- system/Router/RouteCollection.php | 2 +- system/Test/Mock/MockConnection.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/system/Debug/Toolbar/Collectors/Routes.php b/system/Debug/Toolbar/Collectors/Routes.php index 47c808e7ac40..f8005065c57e 100644 --- a/system/Debug/Toolbar/Collectors/Routes.php +++ b/system/Debug/Toolbar/Collectors/Routes.php @@ -51,7 +51,7 @@ class Routes extends BaseCollector * Returns the data of this collector to be formatted in the toolbar * * @return array{ - * matchedRoute: array, namespace?: string, hostname?: string, + * filter?: list|string, namespace?: string, hostname?: string, * subdomain?: string, offset?: int, priority?: int, as?: string, * redirect?: int * } diff --git a/system/Test/Mock/MockConnection.php b/system/Test/Mock/MockConnection.php index 2801a0674ad5..d14160595333 100644 --- a/system/Test/Mock/MockConnection.php +++ b/system/Test/Mock/MockConnection.php @@ -27,8 +27,8 @@ class MockConnection extends BaseConnection { /** * @var array{ - * connect?: object|resource|false|list, - * execute?: object|resource|false, + * connect?: false|list|object|resource, + * execute?: false|object|resource, * } */ protected $returnValues = [];