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
14 changes: 11 additions & 3 deletions src/HasParsedMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ public function replyTo(): ?Address
}

/**
* Get the IN-REPLY-TO address.
* Get the IN-REPLY-TO message identifier(s).
*
* @return string[]
*/
public function inReplyTo(): ?Address
public function inReplyTo(): array
{
return head($this->addresses(HeaderConsts::IN_REPLY_TO)) ?: null;
$parts = $this->header(HeaderConsts::IN_REPLY_TO)?->getParts() ?? [];

$values = array_map(function (IHeaderPart $part) {
return $part->getValue();
}, $parts);

return array_values(array_filter($values));
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ public function messageId(): ?string;
public function replyTo(): ?Address;

/**
* Get the 'In-Reply-To' address.
* Get the 'In-Reply-To' message identifier(s).
*
* @return string[]
*/
public function inReplyTo(): ?Address;
public function inReplyTo(): array;

/**
* Get the 'To' addresses.
Expand Down
43 changes: 38 additions & 5 deletions tests/Unit/FileMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@
expect($message->attachments())->toBe([]);
});

test('it can parse other header fields like IN-REPLY-TO', function () {
test('it can parse In-Reply-To header', function () {
$contents = <<<'EOT'
From: "John Doe" <[email protected]>
In-Reply-To: <[email protected]>, <[email protected]>
In-Reply-To: <[email protected]>
Subject: In-Reply-To Check
Date: Wed, 19 Feb 2025 12:34:56 -0500
Content-Type: text/plain; charset="UTF-8"
Expand All @@ -157,9 +157,42 @@

$message = new FileMessage($contents);

$address = $message->inReplyTo();
expect($address)->not->toBeNull();
expect($address->email())->toBe('[email protected]');
expect($message->inReplyTo())->toBe(['[email protected]']);
});

test('it can parse In-Reply-To header with multiple values', function () {
$contents = <<<'EOT'
From: "John Doe" <[email protected]>
In-Reply-To: <[email protected]> <[email protected]> <[email protected]>
Subject: In-Reply-To Check
Date: Wed, 19 Feb 2025 12:34:56 -0500
Content-Type: text/plain; charset="UTF-8"

Check the in-reply-to header
EOT;

$message = new FileMessage($contents);

expect($message->inReplyTo())->toBe([
'[email protected]',
'[email protected]',
'[email protected]',
]);
});

test('it returns empty array when In-Reply-To header is missing', function () {
$contents = <<<'EOT'
From: "John Doe" <[email protected]>
Subject: No In-Reply-To
Date: Wed, 19 Feb 2025 12:34:56 -0500
Content-Type: text/plain; charset="UTF-8"

No in-reply-to header
EOT;

$message = new FileMessage($contents);

expect($message->inReplyTo())->toBe([]);
});

test('it can be cast to a string via __toString()', function () {
Expand Down