MailMimeParser 1.3

ReceivedConsumer extends AbstractConsumer

Parses a Received header into ReceivedParts, ReceivedDomainParts, a DatePart, and CommentParts.

Parts that don't correspond to any of the above are discarded.

Tags
author

Zaahid Bateson

Table of Contents

$consumerService  : ConsumerService
$partFactory  : HeaderPartFactory
__construct()  : mixed
Initializes the instance.
__invoke()  : array<string|int, HeaderPart>
Invokes parsing of a header's value into header parts.
getInstance()  : mixed
Returns the singleton instance for the class.
advanceToNextToken()  : mixed
Overridden to /not/ advance when the end token matches a start token for a sub-consumer.
getAllConsumers()  : array<string|int, AbstractConsumer>
Returns this consumer and all unique sub consumers.
getAllTokenSeparators()  : array<string|int, string>
Returns a list of regular expression markers for this consumer and all sub-consumers by calling 'getTokenSeparators'.
getConsumerTokenParts()  : array<string|int, HeaderPart>|array<string|int, mixed>
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 getPartForToken and returns it in an array.
getPartForToken()  : HeaderPart|null
Constructs and returns a \ZBateson\MailMimeParser\Header\Part\HeaderPart for the passed string token. If the token should be ignored, the function must return null.
getSubConsumers()  : array<string|int, AbstractConsumer>
Returns two {@see Received/DomainConsumer} instances, with FROM and BY as part names, and 4 {@see Received/GenericReceivedConsumer} instances for VIA, WITH, ID, and FOR part names, and 1 {@see Received/ReceivedDateConsumer} for the date/time stamp, and one {@see CommentConsumer} to consume any comments.
getTokenParts()  : array<string|int, HeaderPart>|array<string|int, mixed>
Returns an array of \ZBateson\MailMimeParser\Header\Part\HeaderPart for the current token on the iterator.
getTokenSeparators()  : array<string|int, string>
ReceivedConsumer doesn't have any token separators of its own.
getTokenSplitPattern()  : string
Overridden to exclude the MimeLiteralPart pattern that comes by default in AbstractConsumer.
isEndToken()  : bool
ReceivedConsumer doesn't have an end token, and so this just returns false.
isStartToken()  : bool
ReceivedConsumer doesn't start consuming at a specific token, it's the base handler for the Received header, and so this always returns false.
parseTokensIntoParts()  : array<string|int, HeaderPart>
Iterates over the passed token Iterator and returns an array of parsed \ZBateson\MailMimeParser\Header\Part\HeaderPart objects.
processParts()  : array<string|int, HeaderPart>|array<string|int, ReceivedDomainPart>|array<string|int, ReceivedPart>|array<string|int, DatePart>|array<string|int, CommentPart>
Overridden to combine all part values into a single string and return it as an array with a single element.
splitRawValue()  : array<string|int, mixed>
Returns an array of split tokens from the input string.
parseRawValue()  : array<string|int, HeaderPart>
Called by __invoke to parse the raw header value into header parts.

Properties

Methods

__invoke()

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

public __invoke(string $value) : array<string|int, HeaderPart>
Parameters
$value : string

the raw header value

Return values
array<string|int, HeaderPart>

the array of parsed parts

advanceToNextToken()

Overridden to /not/ advance when the end token matches a start token for a sub-consumer.

protected advanceToNextToken(Iterator $tokens, bool $isStartToken) : mixed
Parameters
$tokens : Iterator
$isStartToken : bool
Return values
mixed

getAllConsumers()

Returns this consumer and all unique sub consumers.

protected getAllConsumers() : array<string|int, AbstractConsumer>

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

Return values
array<string|int, AbstractConsumer>

getAllTokenSeparators()

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

protected getAllTokenSeparators() : array<string|int, string>

.

Return values
array<string|int, string>

an array of regular expression markers

getConsumerTokenParts()

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 getPartForToken and returns it in an array.

protected getConsumerTokenParts(Iterator $tokens) : array<string|int, HeaderPart>|array<string|int, mixed>
Parameters
$tokens : Iterator
Return values
array<string|int, HeaderPart>|array<string|int, mixed>

getPartForToken()

Constructs and returns a \ZBateson\MailMimeParser\Header\Part\HeaderPart for the passed string token. If the token should be ignored, the function must return null.

protected getPartForToken(string $token, bool $isLiteral) : HeaderPart|null

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

Parameters
$token : string

the token

$isLiteral : bool

set to true if the token represents a literal - e.g. an escaped token

Return values
HeaderPart|null

the constructed header part or null if the token should be ignored

getSubConsumers()

Returns two {@see Received/DomainConsumer} instances, with FROM and BY as part names, and 4 {@see Received/GenericReceivedConsumer} instances for VIA, WITH, ID, and FOR part names, and 1 {@see Received/ReceivedDateConsumer} for the date/time stamp, and one {@see CommentConsumer} to consume any comments.

protected getSubConsumers() : array<string|int, AbstractConsumer>
Return values
array<string|int, AbstractConsumer>

the sub-consumers

getTokenParts()

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

protected getTokenParts(Iterator $tokens) : array<string|int, HeaderPart>|array<string|int, mixed>

If the current token is a start token from a sub-consumer, the sub- consumer's parseTokensIntoParts method is called.

Parameters
$tokens : Iterator
Return values
array<string|int, HeaderPart>|array<string|int, mixed>

getTokenSeparators()

ReceivedConsumer doesn't have any token separators of its own.

protected getTokenSeparators() : array<string|int, string>

Sub-Consumers will return separators matching 'part' word separators, for example 'from' and 'by', and ';' for date, etc...

Return values
array<string|int, string>

an array of regex pattern matchers

getTokenSplitPattern()

Overridden to exclude the MimeLiteralPart pattern that comes by default in AbstractConsumer.

protected getTokenSplitPattern() : string
Return values
string

the regex pattern

isEndToken()

ReceivedConsumer doesn't have an end token, and so this just returns false.

protected isEndToken(string $token) : bool
Parameters
$token : string
Return values
bool

false

isStartToken()

ReceivedConsumer doesn't start consuming at a specific token, it's the base handler for the Received header, and so this always returns false.

protected isStartToken(string $token) : bool
Parameters
$token : string
Tags
codeCoverageIgnore
Return values
bool

false

parseTokensIntoParts()

Iterates over the passed token Iterator and returns an array of parsed \ZBateson\MailMimeParser\Header\Part\HeaderPart objects.

protected parseTokensIntoParts(Iterator $tokens) : array<string|int, HeaderPart>

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.

Parameters
$tokens : Iterator

an iterator over a string of tokens

Return values
array<string|int, HeaderPart>

an array of parsed parts

processParts()

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

protected processParts(array<string|int, HeaderPart$parts) : array<string|int, HeaderPart>|array<string|int, ReceivedDomainPart>|array<string|int, ReceivedPart>|array<string|int, DatePart>|array<string|int, CommentPart>
Parameters
$parts : array<string|int, HeaderPart>
Return values
array<string|int, HeaderPart>|array<string|int, ReceivedDomainPart>|array<string|int, ReceivedPart>|array<string|int, DatePart>|array<string|int, CommentPart>

splitRawValue()

Returns an array of split tokens from the input string.

protected splitRawValue(string $rawValue) : array<string|int, mixed>

The method calls preg_split using getTokenSplitPattern. The split array will not contain any empty parts and will contain the markers.

Parameters
$rawValue : string

the raw string

Return values
array<string|int, mixed>

the array of tokens

parseRawValue()

Called by __invoke to parse the raw header value into header parts.

private parseRawValue(string $value) : array<string|int, HeaderPart>

Calls splitTokens to split the value into token part strings, then calls parseParts to parse the returned array.

Parameters
$value : string
Return values
array<string|int, HeaderPart>

the array of parsed parts

Search results