MailMimeParser 3.0

SubjectConsumerService extends AbstractGenericConsumerService
in package

Extends AbstractGenericConsumerService to use a MimeTokenPartFactory, and to preserve all whitespace and escape sequences as-is (unlike other headers subject headers don't have escape chars such as '\\' for a backslash).

SubjectConsumerService doesn't define any sub-consumers.

Tags
author

Zaahid Bateson

Table of Contents

$logger  : LoggerInterface
$partFactory  : HeaderPartFactory
$subConsumers  : array<string|int, mixed>
$tokenSplitPattern  : string|null
__construct()  : mixed
__invoke()  : array<string|int, IHeaderPart>
Invokes parsing of a header's value into header parts.
advanceToNextToken()  : static
Determines if the iterator should be advanced to the next token after reading tokens or finding a start token.
getAllConsumers()  : array<string|int, AbstractConsumerService>
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|null
Overridden to preserve whitespace.
getTokenParts()  : array<string|int, IHeaderPart>
Returns an array of \ZBateson\MailMimeParser\Header\Part\HeaderPart for the current token on the iterator.
getTokenSeparators()  : array<string|int, string>
Returns an array of regular expression separators specific to this consumer.
getTokenSplitPattern()  : string
Returns a regex pattern used to split the input header string.
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>
Performs any final processing on the array of parsed parts before returning it to the consumer client. The passed $parts array is guaranteed to not be empty.
splitRawValue()  : array<string|int, string>
Returns an array of split tokens from the input string.
parseRawValue()  : array<string|int, IHeaderPart>
Parses the raw header value into header parts.

Properties

$subConsumers

protected array<string|int, mixed> $subConsumers = []

array of sub-consumers used by this consumer if any, or an empty array if none exist.

$tokenSplitPattern

private string|null $tokenSplitPattern = null

the generated token split pattern on first run, so it doesn't need to be regenerated every time.

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

getAllConsumers()

Returns this consumer and all unique sub consumers.

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

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

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<string|int, string> $tokens) : array<string|int, IHeaderPart>

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

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

getPartForToken()

Overridden to preserve whitespace.

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

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.

Parameters
$token : string
$isLiteral : bool
Return values
IHeaderPart|null

getTokenParts()

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

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

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

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

getTokenSeparators()

Returns an array of regular expression separators specific to this consumer.

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

The returned patterns are used to split the header value into tokens for the consumer to parse into parts.

Each array element makes part of a generated regular expression that is used in a call to preg_split(). RegEx patterns can be used, and care should be taken to escape special characters.

Return values
array<string|int, string>

Array of regex patterns.

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<string|int, string> $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 AbstractConsumerService::processParts for any final processing if there are any parts.

Parameters
$tokens : Iterator<string|int, string>

An iterator over a string of tokens

Return values
array<string|int, IHeaderPart>

An array of parsed parts

processParts()

Performs any final processing on the array of parsed parts before returning it to the consumer client. The passed $parts array is guaranteed to not be empty.

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

The default implementation simply returns the passed array after filtering out null/empty parts.

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

The method calls preg_split using AbstractConsumerService::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, string>

the array of tokens

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

Search results