Copied!

Extends GenericConsumer to remove its sub consumers.

Prior to this, subject headers were parsed using the GenericConsumer which meant if the subject contained text within parentheses, it would not be included as part of the returned value in a getHeaderValue. Mime-encoded parts within quotes would be ignored, and backslash characters denoted an escaped character.

From testing in ThunderBird and Outlook web mail it seems quoting parts doesn't have an effect (e.g. quoting a "mime-literal" encoded part still comes out decoded), and parts in parentheses (comments) are displayed normally.

CloneableInstantiable
Methods
public ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::__construct(ZBateson\MailMimeParser\Header\Consumer\ConsumerService $consumerService, ZBateson\MailMimeParser\Header\Part\HeaderPartFactory $partFactory)
public ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::__invoke(string $value) : array
 

Invokes parsing of a header's value into header parts.

  • param string $value the raw header value
  • return \ZBateson\MailMimeParser\Header\IHeaderPart[] the array of parsed parts
public static ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::getInstance(ZBateson\MailMimeParser\Header\Consumer\ConsumerService $consumerService, ZBateson\MailMimeParser\Header\Part\HeaderPartFactory $partFactory)
 

Returns the singleton instance for the class.

Properties
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::$consumerService = NULL
 
  • var \ConsumerService used to get consumer instances for sub-consumers.
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::$partFactory = NULL
 
  • var \HeaderPartFactory used to construct IHeaderPart objects
Methods
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::advanceToNextToken(Iterator $tokens, bool $isStartToken)
 

Determines if the iterator should be advanced to the next token after reading tokens or finding a start token.

The default implementation will advance for a start token, but not advance on the end token of the current consumer, allowing the end token to be passed up to a higher-level consumer.

  • param \Iterator $tokens The token iterator.
  • param bool $isStartToken true for the start token.
  • return static
protected ZBateson\MailMimeParser\Header\Consumer\GenericConsumer::filterIgnoredSpaces(array $parts)
 

Filters out ignorable spaces between parts in the passed array.

Spaces with parts on either side of it that specify they can be ignored are filtered out. filterIgnoredSpaces is called from within processParts, and if needed by an implementing class that overrides processParts, must be specifically called.

  • param \HeaderPart[] $parts
  • return \HeaderPart[]
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::getAllConsumers() : array
 

Returns this consumer and all unique sub consumers.

Loops into the sub-consumers (and their sub-consumers, etc...) finding all unique consumers, and returns them in an array.

  • return \AbstractConsumer[] Array of unique consumers.
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::getAllTokenSeparators() : array
 

Returns a list of regular expression markers for this consumer and all sub-consumers by calling getTokenSeparators().

  • return string[] Array of regular expression markers.
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::getConsumerTokenParts(Iterator $tokens) : array
 

Iterates through this consumer's sub-consumers checking if the current token triggers a sub-consumer's start token and passes control onto that sub-consumer's parseTokenIntoParts().

If no sub-consumer is responsible for the current token, calls {@see \AbstractConsumer::getPartForToken()} and returns it in an array.

  • return \ZBateson\MailMimeParser\Header\IHeaderPart[]
protected getPartForToken(string $token, bool $isLiteral)
 

Overridden to preserve whitespace.

Whitespace between two words is preserved unless the whitespace begins with a newline (\n or \r\n), in which case the entire string of whitespace is discarded, and a single space ' ' character is used in its place.

  • param string $token the token
  • param bool $isLiteral set to true if the token represents a literal - e.g. an escaped token
  • return \ZBateson\MailMimeParser\Header\Part\HeaderPart|null the constructed header part or null if the token should be ignored
protected getSubConsumers() : array
 

Returns an empty array

  • return \AbstractConsumer[] the sub-consumers
protected getTokenParts(Iterator $tokens) : array
 

Returns an array of \ZBateson\MailMimeParser\Header\Part\HeaderPart for the current token on the iterator.

Overridden from AbstractConsumer to remove special filtering for backslash escaping, which also seems to not apply to Subject headers at least in ThunderBird's implementation.

  • return \ZBateson\MailMimeParser\Header\Part\HeaderPart[]|array
protected ZBateson\MailMimeParser\Header\Consumer\GenericConsumer::getTokenSeparators() : array
 

Returns the regex '\s+' (whitespace) pattern matcher as a token marker so the header value is split along whitespace characters.

  • return string[] an array of regex pattern matchers
protected getTokenSplitPattern() : string
 

Overridden to not split out backslash characters and its next character as a special case defined in AbastractConsumer

  • return string the regex pattern
protected ZBateson\MailMimeParser\Header\Consumer\GenericConsumer::isEndToken(string $token) : bool
 

GenericConsumer doesn't have start/end tokens, and so always returns false.

protected ZBateson\MailMimeParser\Header\Consumer\GenericConsumer::isStartToken(string $token) : bool
 

GenericConsumer doesn't have start/end tokens, and so always returns false.

  • codeCoverageIgnore
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::parseTokensIntoParts(Iterator $tokens) : array
 

Iterates over the passed token Iterator and returns an array of parsed IHeaderPart objects.

The method checks each token to see if the token matches a sub-consumer's start token, or if it matches the current consumer's end token to stop processing.

If a sub-consumer's start token is matched, the sub-consumer is invoked and its returned parts are merged to the current consumer's header parts.

After all tokens are read and an array of Header\Parts are constructed, the array is passed to AbstractConsumer::processParts for any final processing.

  • param \Iterator $tokens An iterator over a string of tokens
  • return \ZBateson\MailMimeParser\Header\IHeaderPart[] An array of parsed parts
protected ZBateson\MailMimeParser\Header\Consumer\GenericConsumer::processParts(array $parts) : array
 

Overridden to combine all part values into a single string and return it as an array with a single element.

The returned IHeaderParts are all LiteralParts.

  • param \ZBateson\MailMimeParser\Header\IHeaderPart[] $parts
  • return \ZBateson\MailMimeParser\Header\IHeaderPart[]
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::splitRawValue( $rawValue) : array
 

Returns an array of split tokens from the input string.

The method calls preg_split using {@see \AbstractConsumer::getTokenSplitPattern()}. The split array will not contain any empty parts and will contain the markers.

  • param string $rawValue the raw string
  • return array the array of tokens
Methods
public static ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::getInstance(ZBateson\MailMimeParser\Header\Consumer\ConsumerService $consumerService, ZBateson\MailMimeParser\Header\Part\HeaderPartFactory $partFactory)
 

Returns the singleton instance for the class.

© 2024 Bruce Wells
Search Namespaces \ Classes
Configuration