[ 'from', 'to', 'cc', 'bcc', 'sender', 'replyto', 'resentfrom', 'resentto', 'resentcc', 'resentbcc', 'resentreplyto', 'returnpath', 'deliveredto', ], \ZBateson\MailMimeParser\Header\DateHeader::class => [ 'date', 'resentdate', 'deliverydate', 'expires', 'expirydate', 'replyby', ], \ZBateson\MailMimeParser\Header\ParameterHeader::class => [ 'contenttype', 'contentdisposition', 'receivedspf', 'authenticationresults', 'dkimsignature', 'autocrypt', ], \ZBateson\MailMimeParser\Header\SubjectHeader::class => [ 'subject', ], \ZBateson\MailMimeParser\Header\IdHeader::class => [ 'messageid', 'contentid', 'inreplyto', 'references', ], \ZBateson\MailMimeParser\Header\ReceivedHeader::class => [ 'received', ], ]; /** * @var string Defines the generic IHeader type to use for headers that * aren't mapped in $types */ protected $genericType = \ZBateson\MailMimeParser\Header\GenericHeader::class; /** * Instantiates member variables with the passed objects. * */ public function __construct(ConsumerService $consumerService, MimeLiteralPartFactory $mimeLiteralPartFactory) { $this->consumerService = $consumerService; $this->mimeLiteralPartFactory = $mimeLiteralPartFactory; } /** * Returns the string in lower-case, and with non-alphanumeric characters * stripped out. * * @param string $header The header name * * @return string The normalized header name */ public function getNormalizedHeaderName(string $header): string { return \preg_replace('/[^a-z0-9]/', '', \strtolower($header)); } /** * Returns the name of an IHeader class for the passed header name. * * @param string $name The header name. * * @return string The Fully Qualified class name. */ private function getClassFor(string $name): string { $test = $this->getNormalizedHeaderName($name); foreach ($this->types as $class => $matchers) { foreach ($matchers as $matcher) { if ($test === $matcher) { return $class; } } } return $this->genericType; } /** * Creates an IHeader instance for the passed header name and value, and * returns it. * * @param string $name The header name. * @param string $value The header value. * * @return IHeader The created header object. */ public function newInstance(string $name, string $value) { $class = $this->getClassFor($name); return $this->newInstanceOf($name, $value, $class); } /** * Creates an IHeader instance for the passed header name and value, and * returns it. * * @param string $name The header name. * @param string $value The header value. * * @return IHeader The created header object. */ public function newInstanceOf(string $name, string $value, string $iHeaderClass): IHeader { if (\is_a($iHeaderClass, 'ZBateson\MailMimeParser\Header\MimeEncodedHeader', true)) { return new $iHeaderClass( $this->mimeLiteralPartFactory, $this->consumerService, $name, $value ); } return new $iHeaderClass($this->consumerService, $name, $value); } }