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 src/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading