feat: extract references

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-09-29 19:44:03 -04:00
parent 8abd2c2c8c
commit e5e76351a5
2 changed files with 31 additions and 1 deletions
@@ -46,7 +46,7 @@ final class FetchMessageParser
self::decodeMimeHeader(self::envelopeString($envelope, 1)),
self::envelopeString($envelope, 0),
self::trimAngles(self::envelopeString($envelope, 9)),
self::envelopeString($envelope, 8),
self::trimAngles(self::envelopeString($envelope, 8)),
self::parseAddressList($envelope[2] ?? null),
self::parseAddressList($envelope[3] ?? null),
self::parseAddressList($envelope[4] ?? null),
@@ -55,6 +55,7 @@ final class FetchMessageParser
self::parseAddressList($envelope[7] ?? null),
$bodyStructure,
$bodySections,
self::extractReferences($headers),
);
}
@@ -351,6 +352,24 @@ final class FetchMessageParser
return $parsed;
}
/**
* Extract the message ids listed in the References header, without angle brackets.
*
* @param array<string, list<string>> $headers
* @return list<string>
*/
private static function extractReferences(array $headers): array
{
$references = [];
foreach ($headers['references'] ?? [] as $value) {
if (preg_match_all('/<([^<>\s]+)>/', $value, $matches) > 0) {
array_push($references, ...$matches[1]);
}
}
return array_values(array_unique($references));
}
/**
* @param array<string, list<string>> $headers
*/