Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ protected function appendAttachments(&$body, $boundary, $multipart = null)
. 'Content-Type: ' . $attachment['type'] . '; name="' . $name . '"' . $this->newline
. 'Content-Disposition: ' . $attachment['disposition'] . ';' . $this->newline
. 'Content-Transfer-Encoding: base64' . $this->newline
. ($attachment['cid'] === '' ? '' : 'Content-ID: <' . $attachment['cid'] . '>' . $this->newline)
. (isset($attachment['cid']) && $attachment['cid'] !== '' ? 'Content-ID: <' . $attachment['cid'] . '>' . $this->newline : '')
. $this->newline
. $attachment['content'] . $this->newline;
}
Expand Down
36 changes: 36 additions & 0 deletions tests/system/Email/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use ReflectionException;
use ReflectionMethod;

/**
* @internal
Expand Down Expand Up @@ -220,6 +221,41 @@ public function testSetAttachmentCIDBufferString(): void
);
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/9644
*
* @throws ReflectionException
*/
public function testAppendAttachmentsWithoutCID(): void
{
$email = $this->createMockEmail();

// Manually inject an attachment without 'cid'
$this->setPrivateProperty($email, 'attachments', [
[
'multipart' => 'mixed',
'content' => 'VGhpcyBpcyBhIHRlc3QgZmlsZSBjb250ZW50Lg==', // base64 for "This is a test file content."
'filename' => '',
'type' => 'application/pdf',
'name' => ['testfile.pdf'],
'disposition' => 'attachment',
],
]);

$body = '';
$boundary = 'test-boundary';

// Use ReflectionMethod to call protected method with pass-by-reference
$refMethod = new ReflectionMethod($email, 'appendAttachments');
$refMethod->invokeArgs($email, [&$body, $boundary, 'mixed']);

// Assertion: Should not include a Content-ID header
$this->assertStringContainsString('Content-Type: application/pdf; name="testfile.pdf"', $body);
$this->assertStringContainsString('Content-Disposition: attachment;', $body);
$this->assertStringNotContainsString('Content-ID:', $body);
$this->assertStringContainsString('--' . $boundary . '--', $body);
}

/**
* @throws ReflectionException
*/
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.6.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Deprecations
Bugs Fixed
**********

- **Email:** Fixed a bug with CID check when building email attachments.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
for a complete list of bugs fixed.
Loading