From 3ee44f271b37d9c4554c4407059531cb54535656 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Wed, 4 Nov 2026 16:28:34 -0500 Subject: [PATCH] Fix nullable attachment content disposition --- src/Attachment.php | 2 +- tests/Unit/MessageTest.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Attachment.php b/src/Attachment.php index ea9952c..ee437aa 100644 --- a/src/Attachment.php +++ b/src/Attachment.php @@ -107,7 +107,7 @@ public function contentType(): string /** * Get the attachment's content disposition. */ - public function contentDisposition(): string + public function contentDisposition(): ?string { return $this->contentDisposition; } diff --git a/tests/Unit/MessageTest.php b/tests/Unit/MessageTest.php index 2850b14..88d5277 100644 --- a/tests/Unit/MessageTest.php +++ b/tests/Unit/MessageTest.php @@ -499,11 +499,34 @@ expect($attachments)->toHaveCount(1); expect($attachments[0]->filename())->toBe('document.pdf'); expect($attachments[0]->contentType())->toBe('application/pdf'); + expect($attachments[0]->contentDisposition())->toBe('attachment'); // Content is fetched lazily when contents() is called expect($attachments[0]->contents())->toBe('Hello World!'); }); +test('it fetches attachments without a content disposition from body structure', function () { + $mailbox = Mailbox::make([ + 'username' => 'foo', + 'password' => 'bar', + ]); + + $folder = new Folder($mailbox, 'INBOX', [], '/'); + + $bodyStructureData = parseBodyStructureResponse( + '* 1 FETCH (BODYSTRUCTURE (("text" "plain" ("charset" "utf-8") NIL NIL "7bit" 100 5 NIL NIL NIL) ("application" "pdf" ("name" "document.pdf") NIL NIL "base64" 5000 NIL NIL NIL NIL) "mixed" ("boundary" "abc") NIL NIL) UID 1)' + ); + + $message = new Message($folder, 1, [], 'From: test@example.com', '', null, $bodyStructureData); + + $attachments = $message->attachments(fetch: true); + + expect($attachments)->toHaveCount(1); + expect($attachments[0]->filename())->toBe('document.pdf'); + expect($attachments[0]->contentType())->toBe('application/pdf'); + expect($attachments[0]->contentDisposition())->toBeNull(); +}); + test('it fetches headers from server', function () { $mailbox = Mailbox::make([ 'username' => 'foo',