[a-f\d\.\:]+)\])?\s*(helo=)?(?P[a-z0-9\-]+[a-z0-9\-\.]+)?\s*(\[(IPv[64])?(?P[a-f\d\.\:]+)\])?$~i'; if (\preg_match($pattern, $value, $matches)) { if (!empty($matches['name'])) { $hostname = $matches['name']; } if (!empty($matches['addr1'])) { $address = $matches['addr1']; } if (!empty($matches['addr2'])) { $address = $matches['addr2']; } return true; } return false; } /** * Creates a single ReceivedDomainPart out of matched parts. If an * unmatched parenthesized expression was found, it's returned as a * CommentPart. * * @param \ZBateson\MailMimeParser\Header\Part\HeaderPart[] $parts * * @return \ZBateson\MailMimeParser\Header\Part\ReceivedDomainPart[]|\ZBateson\MailMimeParser\Header\Part\CommentPart[]|\ZBateson\MailMimeParser\Header\Part\HeaderPart[] */ protected function processParts(array $parts): array { $ehloName = null; $hostname = null; $address = null; $commentPart = null; $filtered = $this->filterIgnoredSpaces($parts); foreach ($filtered as $part) { if ($part instanceof CommentPart) { $commentPart = $part; continue; } $ehloName .= $part->getValue(); } $strValue = $ehloName; if ($commentPart !== null && $this->matchHostPart($commentPart->getComment(), $hostname, $address)) { $strValue .= ' ('.$commentPart->getComment().')'; $commentPart = null; } $domainPart = $this->partFactory->newReceivedDomainPart( $this->getPartName(), $strValue, $ehloName, $hostname, $address ); return \array_filter([$domainPart, $commentPart]); } }