Skip to content

Commit cfc1e24

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.7
2 parents a5caa4d + 9973d05 commit cfc1e24

File tree

12 files changed

+161
-11
lines changed

12 files changed

+161
-11
lines changed

app/Config/Filters.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ class Filters extends BaseFilters
6565
* List of filter aliases that are always
6666
* applied before and after every request.
6767
*
68-
* @var array<string, array<string, array<string, string>>>|array<string, list<string>>
68+
* @var array{
69+
* before: array<string, array{except: list<string>|string}>|list<string>,
70+
* after: array<string, array{except: list<string>|string}>|list<string>
71+
* }
6972
*/
7073
public array $globals = [
7174
'before' => [

preload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class preload
5757
'/system/Config/Routes.php',
5858
'/system/Language/',
5959
'/system/bootstrap.php',
60+
'/system/util_bootstrap.php',
6061
'/system/rewrite.php',
6162
'/Views/',
6263
// Errors occur.

system/Config/Filters.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ class Filters extends BaseConfig
7878
* List of filter aliases that are always
7979
* applied before and after every request.
8080
*
81-
* @var array<string, array<string, array<string, string>>>|array<string, list<string>>
81+
* @var array{
82+
* before: array<string, array{except: list<string>|string}>|list<string>,
83+
* after: array<string, array{except: list<string>|string}>|list<string>
84+
* }
8285
*/
8386
public array $globals = [
8487
'before' => [

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: 17 additions & 5 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

@@ -1313,7 +1313,7 @@ protected function appendAttachments(&$body, $boundary, $multipart = null)
13131313
. 'Content-Type: ' . $attachment['type'] . '; name="' . $name . '"' . $this->newline
13141314
. 'Content-Disposition: ' . $attachment['disposition'] . ';' . $this->newline
13151315
. 'Content-Transfer-Encoding: base64' . $this->newline
1316-
. ($attachment['cid'] === '' ? '' : 'Content-ID: <' . $attachment['cid'] . '>' . $this->newline)
1316+
. (isset($attachment['cid']) && $attachment['cid'] !== '' ? 'Content-ID: <' . $attachment['cid'] . '>' . $this->newline : '')
13171317
. $this->newline
13181318
. $attachment['content'] . $this->newline;
13191319
}
@@ -1891,7 +1891,7 @@ protected function SMTPEnd()
18911891
*/
18921892
protected function SMTPConnect()
18931893
{
1894-
if (is_resource($this->SMTPConnect)) {
1894+
if ($this->isSMTPConnected()) {
18951895
return true;
18961896
}
18971897

@@ -1915,7 +1915,7 @@ protected function SMTPConnect()
19151915
$this->SMTPTimeout,
19161916
);
19171917

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

19211921
return false;
@@ -2259,7 +2259,7 @@ protected function mimeTypes($ext = '')
22592259

22602260
public function __destruct()
22612261
{
2262-
if ($this->SMTPConnect !== null) {
2262+
if ($this->isSMTPConnected()) {
22632263
try {
22642264
$this->sendCommand('quit');
22652265
} catch (ErrorException $e) {
@@ -2316,4 +2316,16 @@ protected function setArchiveValues(): array
23162316

23172317
return $this->archive;
23182318
}
2319+
2320+
/**
2321+
* Checks if there is an active SMTP connection.
2322+
*
2323+
* @return bool True if SMTP connection is established and open, false otherwise
2324+
*/
2325+
protected function isSMTPConnected(): bool
2326+
{
2327+
return $this->SMTPConnect !== null
2328+
&& $this->SMTPConnect !== false
2329+
&& get_debug_type($this->SMTPConnect) !== 'resource (closed)';
2330+
}
23192331
}

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 = [];

tests/system/Email/EmailTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PHPUnit\Framework\Attributes\DataProvider;
2222
use PHPUnit\Framework\Attributes\Group;
2323
use ReflectionException;
24+
use ReflectionMethod;
2425

2526
/**
2627
* @internal
@@ -220,6 +221,41 @@ public function testSetAttachmentCIDBufferString(): void
220221
);
221222
}
222223

224+
/**
225+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/9644
226+
*
227+
* @throws ReflectionException
228+
*/
229+
public function testAppendAttachmentsWithoutCID(): void
230+
{
231+
$email = $this->createMockEmail();
232+
233+
// Manually inject an attachment without 'cid'
234+
$this->setPrivateProperty($email, 'attachments', [
235+
[
236+
'multipart' => 'mixed',
237+
'content' => 'VGhpcyBpcyBhIHRlc3QgZmlsZSBjb250ZW50Lg==', // base64 for "This is a test file content."
238+
'filename' => '',
239+
'type' => 'application/pdf',
240+
'name' => ['testfile.pdf'],
241+
'disposition' => 'attachment',
242+
],
243+
]);
244+
245+
$body = '';
246+
$boundary = 'test-boundary';
247+
248+
// Use ReflectionMethod to call protected method with pass-by-reference
249+
$refMethod = new ReflectionMethod($email, 'appendAttachments');
250+
$refMethod->invokeArgs($email, [&$body, $boundary, 'mixed']);
251+
252+
// Assertion: Should not include a Content-ID header
253+
$this->assertStringContainsString('Content-Type: application/pdf; name="testfile.pdf"', $body);
254+
$this->assertStringContainsString('Content-Disposition: attachment;', $body);
255+
$this->assertStringNotContainsString('Content-ID:', $body);
256+
$this->assertStringContainsString('--' . $boundary . '--', $body);
257+
}
258+
223259
/**
224260
* @throws ReflectionException
225261
*/

user_guide_src/source/changelogs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See all the changes.
1313
:titlesonly:
1414

1515
v4.7.0
16+
v4.6.3
1617
v4.6.2
1718
v4.6.1
1819
v4.6.0
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#############
2+
Version 4.6.3
3+
#############
4+
5+
Release Date: Unreleased
6+
7+
**4.6.3 release of CodeIgniter4**
8+
9+
.. contents::
10+
:local:
11+
:depth: 3
12+
13+
********
14+
BREAKING
15+
********
16+
17+
***************
18+
Message Changes
19+
***************
20+
21+
*******
22+
Changes
23+
*******
24+
25+
************
26+
Deprecations
27+
************
28+
29+
**********
30+
Bugs Fixed
31+
**********
32+
33+
- **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.
35+
36+
See the repo's
37+
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
38+
for a complete list of bugs fixed.

0 commit comments

Comments
 (0)