Skip to content

Commit a9420fc

Browse files
authored
Merge pull request #119 from DirectoryTree/bug-118
In-Reply-To is handled as an address, but should be handled the same as Message-ID
2 parents 22899b4 + 75ec8db commit a9420fc

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

src/HasParsedMessage.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,19 @@ public function replyTo(): ?Address
8080
}
8181

8282
/**
83-
* Get the IN-REPLY-TO address.
83+
* Get the IN-REPLY-TO message identifier(s).
84+
*
85+
* @return string[]
8486
*/
85-
public function inReplyTo(): ?Address
87+
public function inReplyTo(): array
8688
{
87-
return head($this->addresses(HeaderConsts::IN_REPLY_TO)) ?: null;
89+
$parts = $this->header(HeaderConsts::IN_REPLY_TO)?->getParts() ?? [];
90+
91+
$values = array_map(function (IHeaderPart $part) {
92+
return $part->getValue();
93+
}, $parts);
94+
95+
return array_values(array_filter($values));
8896
}
8997

9098
/**

src/MessageInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ public function messageId(): ?string;
5151
public function replyTo(): ?Address;
5252

5353
/**
54-
* Get the 'In-Reply-To' address.
54+
* Get the 'In-Reply-To' message identifier(s).
55+
*
56+
* @return string[]
5557
*/
56-
public function inReplyTo(): ?Address;
58+
public function inReplyTo(): array;
5759

5860
/**
5961
* Get the 'To' addresses.

tests/Unit/FileMessageTest.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@
144144
expect($message->attachments())->toBe([]);
145145
});
146146

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

158158
$message = new FileMessage($contents);
159159

160-
$address = $message->inReplyTo();
161-
expect($address)->not->toBeNull();
162-
expect($address->email())->toBe('[email protected]');
160+
expect($message->inReplyTo())->toBe(['[email protected]']);
161+
});
162+
163+
test('it can parse In-Reply-To header with multiple values', function () {
164+
$contents = <<<'EOT'
165+
From: "John Doe" <[email protected]>
166+
167+
Subject: In-Reply-To Check
168+
Date: Wed, 19 Feb 2025 12:34:56 -0500
169+
Content-Type: text/plain; charset="UTF-8"
170+
171+
Check the in-reply-to header
172+
EOT;
173+
174+
$message = new FileMessage($contents);
175+
176+
expect($message->inReplyTo())->toBe([
177+
178+
179+
180+
]);
181+
});
182+
183+
test('it returns empty array when In-Reply-To header is missing', function () {
184+
$contents = <<<'EOT'
185+
From: "John Doe" <[email protected]>
186+
Subject: No In-Reply-To
187+
Date: Wed, 19 Feb 2025 12:34:56 -0500
188+
Content-Type: text/plain; charset="UTF-8"
189+
190+
No in-reply-to header
191+
EOT;
192+
193+
$message = new FileMessage($contents);
194+
195+
expect($message->inReplyTo())->toBe([]);
163196
});
164197

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

0 commit comments

Comments
 (0)