MailMimeParser 2.3

ParameterConsumer extends GenericConsumer
in package

Reads headers separated into parameters consisting of an optional main value, and subsequent name/value pairs - for example text/html; charset=utf-8.

A ParameterConsumer's parts are separated by a semi-colon. Its name/value pairs are separated with an '=' character.

Parts may be mime-encoded entities. Additionally, a value can be quoted and comments may exist.

Tags
author

Zaahid Bateson

Table of Contents

$consumerService  : ConsumerService
$partFactory  : HeaderPartFactory
__construct()  : mixed
__invoke()  : array<string|int, IHeaderPart>
Invokes parsing of a header's value into header parts.
getInstance()  : mixed
Returns the singleton instance for the class.
advanceToNextToken()  : static
Determines if the iterator should be advanced to the next token after reading tokens or finding a start token.
filterIgnoredSpaces()  : array<string|int, HeaderPart>
Filters out ignorable spaces between parts in the passed array.
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, IHeaderPart>
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().
getPartForToken()  : IHeaderPart
Creates and returns a \ZBateson\MailMimeParser\Header\Part\Token out of the passed string token and returns it, unless the token is an escaped literal, in which case a LiteralPart is returned.
getSubConsumers()  : array<string|int, AbstractConsumer>
Returns an array of sub-consumers.
getTokenParts()  : array<string|int, IHeaderPart>
Returns an array of IHeaderPart for the current token on the iterator.
getTokenSeparators()  : array<string|int, string>
Returns semi-colon and equals char as token separators.
getTokenSplitPattern()  : string
Overridden to use a specialized regex for finding mime-encoded parts (RFC 2047).
isEndToken()  : bool
Returns true if the passed string token marks the end marker for the current consumer.
isStartToken()  : bool
Returns true if the passed string token marks the beginning marker for the current consumer.
parseTokensIntoParts()  : array<string|int, IHeaderPart>
Iterates over the passed token Iterator and returns an array of parsed IHeaderPart objects.
processParts()  : array<string|int, IHeaderPart>
Post processing involves creating Part\LiteralPart or Part\ParameterPart objects out of created Token and LiteralParts.
splitRawValue()  : array<string|int, mixed>
Returns an array of split tokens from the input string.
addSpaces()  : self
Checks if the passed space part should be added to the returned parts and adds it.
addSpaceToRetParts()  : self
Loops over the $parts array from the current position, checks if the space should be added, then adds it to $retParts and returns.
addToSplitPart()  : SplitParameterToken
Adds the passed parameter with the given name and value to a SplitParameterToken, at the passed index. If one with the given name doesn't exist, it is created.
finalizeParameterParts()  : array<string|int, IHeaderPart>|array<string|int, mixed>
Loops over parts in the passed array, creating ParameterParts out of any parsed SplitParameterTokens, replacing them in the array.
getPartFor()  : MimeLiteralPart|SplitParameterToken|ParameterPart
Instantiates and returns either a MimeLiteralPart if $strName is empty, a SplitParameterToken if the parameter is a split parameter and is the first in a series, null if it's a split parameter but is not the first part in its series, or a ParameterPart is returned otherwise.
isSpaceToken()  : bool
Returns true if the passed HeaderPart is a Token instance and a space.
parseRawValue()  : array<string|int, IHeaderPart>
Parses the raw header value into header parts.
processTokenPart()  : bool
Handles parameter separator tokens during final processing.
shouldAddSpace()  : bool
Returns true if a space should be added based on the passed last and next parts.

Properties

Methods

__invoke()

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

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

the raw header value

Return values
array<string|int, IHeaderPart>

the array of parsed parts

advanceToNextToken()

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

protected advanceToNextToken(Iterator $tokens, bool $isStartToken) : static

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.

Parameters
$tokens : Iterator

The token iterator.

$isStartToken : bool

true for the start token.

Return values
static

filterIgnoredSpaces()

Filters out ignorable spaces between parts in the passed array.

protected filterIgnoredSpaces(array<string|int, HeaderPart$parts) : array<string|int, HeaderPart>

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.

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

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>

Array of unique consumers.

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>

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().

protected getConsumerTokenParts(Iterator $tokens) : array<string|int, IHeaderPart>

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

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

getPartForToken()

Creates and returns a \ZBateson\MailMimeParser\Header\Part\Token out of the passed string token and returns it, unless the token is an escaped literal, in which case a LiteralPart is returned.

protected getPartForToken(string $token, bool $isLiteral) : IHeaderPart
Parameters
$token : string
$isLiteral : bool
Return values
IHeaderPart

getSubConsumers()

Returns an array of sub-consumers.

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

Called during construction to set up the list of sub-consumers that will take control from this consumer should a token match a sub-consumer's start token.

Return values
array<string|int, AbstractConsumer>

Array of sub-consumers

getTokenParts()

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

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

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

Parameters
$tokens : Iterator

The token iterator.

Return values
array<string|int, IHeaderPart>

getTokenSeparators()

Returns semi-colon and equals char as token separators.

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

getTokenSplitPattern()

Overridden to use a specialized regex for finding mime-encoded parts (RFC 2047).

protected getTokenSplitPattern() : string

Some implementations seem to place mime-encoded parts within quoted parameters, and split the mime-encoded parts across multiple split parameters. The specialized regex doesn't allow double quotes inside a mime encoded part, so it can be "continued" in another parameter.

Return values
string

the regex pattern

isEndToken()

Returns true if the passed string token marks the end marker for the current consumer.

protected abstract isEndToken(string $token) : bool
Parameters
$token : string

The current token

Return values
bool

isStartToken()

Returns true if the passed string token marks the beginning marker for the current consumer.

protected abstract isStartToken(string $token) : bool
Parameters
$token : string

The current token

Return values
bool

parseTokensIntoParts()

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

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

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, IHeaderPart>

An array of parsed parts

processParts()

Post processing involves creating Part\LiteralPart or Part\ParameterPart objects out of created Token and LiteralParts.

protected processParts(array<string|int, IHeaderPart$parts) : array<string|int, IHeaderPart>
Parameters
$parts : array<string|int, IHeaderPart>

The parsed parts.

Return values
array<string|int, IHeaderPart>

Array of resulting final parts.

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 AbstractConsumer::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

addSpaces()

Checks if the passed space part should be added to the returned parts and adds it.

private addSpaces(array<string|int, HeaderPart$parts, array<string|int, HeaderPart&$retParts, int $curIndex[, HeaderPart &$spacePart = null ]) : self

Never adds a space if it's the first part, otherwise only add it if either part isn't set to ignore the space

Parameters
$parts : array<string|int, HeaderPart>
$retParts : array<string|int, HeaderPart>
$curIndex : int
$spacePart : HeaderPart = null
Return values
self

addSpaceToRetParts()

Loops over the $parts array from the current position, checks if the space should be added, then adds it to $retParts and returns.

private addSpaceToRetParts(array<string|int, HeaderPart$parts, array<string|int, HeaderPart&$retParts, int $curIndex, HeaderPart &$spacePart, HeaderPart $lastPart) : self
Parameters
$parts : array<string|int, HeaderPart>
$retParts : array<string|int, HeaderPart>
$curIndex : int
$spacePart : HeaderPart
$lastPart : HeaderPart
Return values
self

addToSplitPart()

Adds the passed parameter with the given name and value to a SplitParameterToken, at the passed index. If one with the given name doesn't exist, it is created.

private addToSplitPart(ArrayObject $splitParts, string $name, string $value, int $index, bool $isEncoded) : SplitParameterToken
Parameters
$splitParts : ArrayObject
$name : string
$value : string
$index : int
$isEncoded : bool
Return values
SplitParameterToken

finalizeParameterParts()

Loops over parts in the passed array, creating ParameterParts out of any parsed SplitParameterTokens, replacing them in the array.

private finalizeParameterParts(ArrayObject $combined) : array<string|int, IHeaderPart>|array<string|int, mixed>

The method then calls filterIgnoreSpaces to filter out empty elements in the combined array and returns an array.

Parameters
$combined : ArrayObject
Return values
array<string|int, IHeaderPart>|array<string|int, mixed>

getPartFor()

Instantiates and returns either a MimeLiteralPart if $strName is empty, a SplitParameterToken if the parameter is a split parameter and is the first in a series, null if it's a split parameter but is not the first part in its series, or a ParameterPart is returned otherwise.

private getPartFor(string $strName, string $strValue, ArrayObject $splitParts) : MimeLiteralPart|SplitParameterToken|ParameterPart

If the part is a SplitParameterToken, it's added to the passed $splitParts as well with its name as a key.

Parameters
$strName : string
$strValue : string
$splitParts : ArrayObject
Return values
MimeLiteralPart|SplitParameterToken|ParameterPart

isSpaceToken()

Returns true if the passed HeaderPart is a Token instance and a space.

private isSpaceToken(HeaderPart $part) : bool
Parameters
$part : HeaderPart
Return values
bool

parseRawValue()

Parses the raw header value into header parts.

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

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, IHeaderPart>

the array of parsed parts

processTokenPart()

Handles parameter separator tokens during final processing.

private processTokenPart(string $tokenValue, ArrayObject $combined, ArrayObject $splitParts, string &$strName, string &$strCat) : bool

If the end token is found, a new IHeaderPart is assigned to the passed $combined array. If an '=' character is found, $strCat is assigned to $strName and emptied.

Returns true if the token was processed, and false otherwise.

Parameters
$tokenValue : string
$combined : ArrayObject
$splitParts : ArrayObject
$strName : string
$strCat : string
Return values
bool

Search results