partName = $partName; } /** * Returns the name of the part being parsed. * * This is always the lower-case name provided to the constructor, not the * actual string that started the consumer, which could be in any case. * */ protected function getPartName(): string { return $this->partName; } /** * Overridden to return a CommentConsumer. * * @return \ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer[] the sub-consumers */ protected function getSubConsumers(): array { return [$this->consumerService->getCommentConsumer()]; } /** * Returns true if the passed token matches (case-insensitively) * $this->getPartName() with optional whitespace surrounding it. */ protected function isStartToken(string $token): bool { $pattern = '/^'.\preg_quote($this->getPartName(), '/').'$/i'; return (\preg_match($pattern, $token) === 1); } /** * Returns true if the token matches (case-insensitively) any of the * following, with optional surrounding whitespace: * * o by * o via * o with * o id * o for * o ; */ protected function isEndToken(string $token): bool { return (\preg_match('/^(by|via|with|id|for|;)$/i', $token) === 1); } /** * Returns a whitespace separator (for filtering ignorable whitespace * between parts), and a separator matching the current part name as * returned by $this->getPartName(). * * @return string[] an array of regex pattern matchers */ protected function getTokenSeparators(): array { return [ '\s+', '(\A\s*|\s+)(?i)'.\preg_quote($this->getPartName(), '/').'(?-i)(?=\s+)', ]; } /** * Overridden to combine all part values into a single string and return it * as the first element, followed by any comment elements as subsequent * elements. * * @param \ZBateson\MailMimeParser\Header\Part\HeaderPart[] $parts * * @return \ZBateson\MailMimeParser\Header\Part\HeaderPart[]|\ZBateson\MailMimeParser\Header\Part\CommentPart[] */ protected function processParts(array $parts): array { $strValue = ''; $ret = []; $filtered = $this->filterIgnoredSpaces($parts); foreach ($filtered as $part) { if ($part instanceof CommentPart) { $ret[] = $part; continue; // getValue() is empty anyway, but for clarity... } $strValue .= $part->getValue(); } \array_unshift($ret, $this->partFactory->newReceivedPart($this->getPartName(), $strValue)); return $ret; } }