From 3046fa334dccd4324824d0f867f9f664074093e2 Mon Sep 17 00:00:00 2001 From: christopher Date: Mon, 29 Sep 2025 11:22:52 +0200 Subject: [PATCH] Provide Content-Disposition in Attachment --- src/Attachment.php | 9 +++++++++ src/HasParsedMessage.php | 1 + tests/Unit/AttachmentTest.php | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Attachment.php b/src/Attachment.php index 40bc490..38190fa 100644 --- a/src/Attachment.php +++ b/src/Attachment.php @@ -16,6 +16,7 @@ public function __construct( protected ?string $filename, protected ?string $contentId, protected string $contentType, + protected ?string $contentDisposition, protected StreamInterface $contentStream, ) {} @@ -43,6 +44,14 @@ public function contentType(): string return $this->contentType; } + /** + * Get the attachment's content disposition. + */ + public function contentDisposition(): string + { + return $this->contentDisposition; + } + /** * Get the attachment's contents. */ diff --git a/src/HasParsedMessage.php b/src/HasParsedMessage.php index 4ff3727..453d25c 100644 --- a/src/HasParsedMessage.php +++ b/src/HasParsedMessage.php @@ -136,6 +136,7 @@ public function attachments(): array $part->getFilename(), $part->getContentId(), $part->getContentType(), + $part->getContentDisposition(), $part->getBinaryContentStream() ?? Utils::streamFor(''), ); } diff --git a/tests/Unit/AttachmentTest.php b/tests/Unit/AttachmentTest.php index 342b1d2..247babf 100644 --- a/tests/Unit/AttachmentTest.php +++ b/tests/Unit/AttachmentTest.php @@ -6,7 +6,7 @@ test('extension', function () { $stream = new LazyOpenStream('test.jpg', 'r'); - $ext = (new Attachment('test.jpg', null, 'image/jpeg', $stream))->extension(); + $ext = (new Attachment('test.jpg', null, 'image/jpeg', 'attachment', $stream))->extension(); expect($ext)->toBe('jpg'); }); @@ -14,7 +14,7 @@ test('extension with content type', function () { $stream = new LazyOpenStream('test', 'r'); - $ext = (new Attachment('test', null, 'image/jpeg', $stream))->extension(); + $ext = (new Attachment('test', null, 'image/jpeg', 'attachment', $stream))->extension(); expect($ext)->toBe('jpg'); });