Skip to content

Commit 2ec5eff

Browse files
authored
Merge pull request #9648 from michalsn/fix/email-destruct
fix: SMTP connection resource validation in `Email` class destructor
2 parents 2f6ca33 + 2e8091e commit 2ec5eff

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

system/Debug/Toolbar/Collectors/Routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Routes extends BaseCollector
5151
* Returns the data of this collector to be formatted in the toolbar
5252
*
5353
* @return array{
54-
* matchedRoute: array<array{
54+
* matchedRoute: list<array{
5555
* directory: string,
5656
* controller: string,
5757
* method: string,

system/Email/Email.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class Email
263263
/**
264264
* SMTP Connection socket placeholder
265265
*
266-
* @var resource|null
266+
* @var false|resource|null
267267
*/
268268
protected $SMTPConnect;
269269

@@ -1886,7 +1886,7 @@ protected function SMTPEnd()
18861886
*/
18871887
protected function SMTPConnect()
18881888
{
1889-
if (is_resource($this->SMTPConnect)) {
1889+
if ($this->isSMTPConnected()) {
18901890
return true;
18911891
}
18921892

@@ -1910,7 +1910,7 @@ protected function SMTPConnect()
19101910
$this->SMTPTimeout,
19111911
);
19121912

1913-
if (! is_resource($this->SMTPConnect)) {
1913+
if (! $this->isSMTPConnected()) {
19141914
$this->setErrorMessage(lang('Email.SMTPError', [$errno . ' ' . $errstr]));
19151915

19161916
return false;
@@ -2227,7 +2227,7 @@ protected function mimeTypes($ext = '')
22272227

22282228
public function __destruct()
22292229
{
2230-
if ($this->SMTPConnect !== null) {
2230+
if ($this->isSMTPConnected()) {
22312231
try {
22322232
$this->sendCommand('quit');
22332233
} catch (ErrorException $e) {
@@ -2284,4 +2284,16 @@ protected function setArchiveValues(): array
22842284

22852285
return $this->archive;
22862286
}
2287+
2288+
/**
2289+
* Checks if there is an active SMTP connection.
2290+
*
2291+
* @return bool True if SMTP connection is established and open, false otherwise
2292+
*/
2293+
protected function isSMTPConnected(): bool
2294+
{
2295+
return $this->SMTPConnect !== null
2296+
&& $this->SMTPConnect !== false
2297+
&& get_debug_type($this->SMTPConnect) !== 'resource (closed)';
2298+
}
22872299
}

system/Router/RouteCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,7 @@ public function resetRoutes()
17241724
* @return array<
17251725
* string,
17261726
* array{
1727-
* filter?: string|list<string>, namespace?: string, hostname?: string,
1727+
* filter?: list<string>|string, namespace?: string, hostname?: string,
17281728
* subdomain?: string, offset?: int, priority?: int, as?: string,
17291729
* redirect?: int
17301730
* }

system/Test/Mock/MockConnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class MockConnection extends BaseConnection
2727
{
2828
/**
2929
* @var array{
30-
* connect?: object|resource|false|list<object|resource|false>,
31-
* execute?: object|resource|false,
30+
* connect?: false|list<false|object|resource>|object|resource,
31+
* execute?: false|object|resource,
3232
* }
3333
*/
3434
protected $returnValues = [];

user_guide_src/source/changelogs/v4.6.3.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Bugs Fixed
3131
**********
3232

3333
- **Email:** Fixed a bug with CID check when building email attachments.
34+
- **Email:** Fixed a bug with SMTP connection resource validation in the class destructor.
3435

3536
See the repo's
3637
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)