generated from Nodarx/template
feat: extract references
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@ final class Message
|
||||
* @param list<MessageAddress> $cc
|
||||
* @param list<MessageAddress> $bcc
|
||||
* @param array<string, string> $bodySections
|
||||
* @param list<string> $references message ids from the References header, without angle brackets
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly int $sequence,
|
||||
@@ -35,6 +36,7 @@ final class Message
|
||||
private readonly array $bcc,
|
||||
private readonly ?MessagePart $bodyStructure,
|
||||
private readonly array $bodySections,
|
||||
private readonly array $references = [],
|
||||
) {}
|
||||
|
||||
public function sequence(): int
|
||||
@@ -90,6 +92,14 @@ final class Message
|
||||
return $this->inReplyTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function references(): array
|
||||
{
|
||||
return $this->references;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<MessageAddress>
|
||||
*/
|
||||
@@ -185,6 +195,7 @@ final class Message
|
||||
$this->bcc,
|
||||
$bodyStructure,
|
||||
$bodySections,
|
||||
$this->references,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user