Copied!

Parses a single part of an address header.

Represents a single part of a list of addresses. A part could be one email
address, or one 'group' containing multiple addresses. The consumer ends on
finding either a comma token, representing a separation between addresses, or
a semi-colon token representing the end of a group.

A single email address may consist of just an email, or a name and an email
address. Both of these are valid examples of a From header:

Groups must be named, for example:

Addresses may contain quoted parts and comments, and names may be mime-header
encoded.

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( $value)
 

Invokes parsing of a header's value into header 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.

public getTokenSeparators()
 

Overridden to return patterns matching end tokens ("," and ";"), and
whitespace.

Properties
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::$consumerService
 
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::$partFactory
 
Methods
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::advanceToNextToken(Iterator $tokens, $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.

protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::getAllConsumers()
 

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.

protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::getAllTokenSeparators()
 

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

protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::getConsumerTokenParts(Iterator $tokens)
 

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.

protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::getPartForToken( $token, $isLiteral)
 

Constructs and returns an IHeaderPart for the passed string token.

If the token should be ignored, the function must return null.

The default created part uses the instance's partFactory->newInstance
method.

protected getSubConsumers()
 

Returns the following as sub-consumers:

  • {@see AddressGroupConsumer}
  • {@see CommentConsumer}
  • {@see QuotedStringConsumer}
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::getTokenParts(Iterator $tokens)
 

Returns an array of IHeaderPart for the current token on the iterator.

If the current token is a start token from a sub-consumer, the sub-
consumer's {@see \AbstractConsumer::parseTokensIntoParts()} method is
called.

protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::getTokenSplitPattern()
 

Returns a regex pattern used to split the input header string.

The default implementation calls
{@see \AbstractConsumer::getAllTokenSeparators()} and implodes the
returned array with the regex OR '|' character as its glue.

protected isEndToken( $token)
 

Returns true for commas and semi-colons.

Although the semi-colon is not strictly the end token of an
AddressConsumer, it could end a parent AddressGroupConsumer.

protected isStartToken( $token)
 

AddressConsumer is "greedy", so this always returns true.

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

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.

protected processParts(array $parts)
 

Performs final processing on parsed parts.

AddressConsumer's implementation looks for tokens representing the
beginning of an address part, to create a Part\AddressPart out of a
name/address pair, or assign the name part to a parsed
Part\AddressGroupPart returned from its AddressGroupConsumer
sub-consumer.

The returned array consists of a single element - either a
Part\AddressPart or a Part\AddressGroupPart.

protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumer::splitRawValue( $rawValue)
 

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.

Methods
private processSinglePart(ZBateson\MailMimeParser\Header\IHeaderPart $part, $strName, $strValue)
 

Checks if the passed part represents the beginning or end of an address
part (less than/greater than characters) and either appends the value of
the part to the passed $strValue, or sets up $strName

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.

© 2023 Bruce Wells
Search Namespaces \ Classes
Configuration