diff --git a/src/HasParsedMessage.php b/src/HasParsedMessage.php index 2618ac3..80672c9 100644 --- a/src/HasParsedMessage.php +++ b/src/HasParsedMessage.php @@ -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)); } /** diff --git a/src/MessageInterface.php b/src/MessageInterface.php index 54b7737..3b3c06d 100644 --- a/src/MessageInterface.php +++ b/src/MessageInterface.php @@ -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. diff --git a/tests/Unit/FileMessageTest.php b/tests/Unit/FileMessageTest.php index d37cab0..fa394dc 100644 --- a/tests/Unit/FileMessageTest.php +++ b/tests/Unit/FileMessageTest.php @@ -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" - In-Reply-To: , + In-Reply-To: Subject: In-Reply-To Check Date: Wed, 19 Feb 2025 12:34:56 -0500 Content-Type: text/plain; charset="UTF-8" @@ -157,9 +157,42 @@ $message = new FileMessage($contents); - $address = $message->inReplyTo(); - expect($address)->not->toBeNull(); - expect($address->email())->toBe('some-other-message@server.example.com'); + expect($message->inReplyTo())->toBe(['some-other-message@server.example.com']); +}); + +test('it can parse In-Reply-To header with multiple values', function () { + $contents = <<<'EOT' + From: "John Doe" + In-Reply-To: + 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([ + 'first-message@server.example.com', + 'second-message@server.example.com', + 'third-message@server.example.com', + ]); +}); + +test('it returns empty array when In-Reply-To header is missing', function () { + $contents = <<<'EOT' + From: "John Doe" + 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 () {