partFactory->newToken($token); } /** * Calls $tokens->next() and returns. * * The default implementation checks if the current token is an end token, * and will not advance past it. Because a comment part of a header can be * nested, its implementation must advance past its own 'end' token. * * @return static */ protected function advanceToNextToken(Iterator $tokens, bool $isStartToken) { $tokens->next(); return $this; } /** * Post processing involves creating a single Part\CommentPart out of * generated parts from tokens. The Part\CommentPart is returned in an * array. * * @param \ZBateson\MailMimeParser\Header\IHeaderPart[] $parts * * @return \ZBateson\MailMimeParser\Header\IHeaderPart[]|array */ protected function processParts(array $parts): array { $comment = ''; foreach ($parts as $part) { // order is important here - CommentPart extends LiteralPart if ($part instanceof CommentPart) { $comment .= '('.$part->getComment().')'; } elseif ($part instanceof LiteralPart) { $comment .= '"'.\str_replace('(["\\])', '\$1', $part->getValue()).'"'; } else { $comment .= $part->getValue(); } } return [$this->partFactory->newCommentPart($comment)]; } }