MailMimeParser 3.0

ParserPartStreamContainer extends PartStreamContainer
in package
implements SplObserver

A part stream container that proxies requests for content streams to a parser to read the content.

Keeps reference to the original stream a part was parsed from, using that stream as the part's stream instead of the PartStreamContainer's MessagePartStream (which dynamically creates a stream from an IMessagePart) unless the part changed.

The ParserPartStreamContainer must also be attached to its underlying part with SplSubject::attach() so the ParserPartStreamContainer gets notified of any changes.

Tags
author

Zaahid Bateson

Interfaces, Classes, Traits and Enums

SplObserver

Table of Contents

$charsetStream  : StreamInterface|null
$contentParseRequested  : bool
$contentStream  : StreamInterface|null
$decodedStream  : StreamInterface|null
$detachParsedStream  : bool
$logger  : LoggerInterface
$mbWrapper  : MbWrapper
$parsedStream  : MessagePartStreamDecorator|null
$parserProxy  : ParserPartProxy
$partUpdated  : bool
$stream  : MessagePartStreamDecorator
$streamFactory  : StreamFactory
$throwExceptionReadingPartContentFromUnsupportedCharsets  : bool
$charset  : array<string|int, mixed>
$encoding  : array<string|int, mixed>
$errors  : array<string|int, mixed>
$validated  : bool
__construct()  : mixed
__destruct()  : mixed
addError()  : static
Creates and adds an Error object to this ErrorBag.
getAllErrors()  : array<string|int, Error>
Returns any errors on this object, and all IErrorBag children of this object at or above the passed PSR log level from Psr\Log\LogLevel (defaulting to LogLevel::ERROR).
getBinaryContentStream()  : MessagePartStreamDecorator|null
Checks what transfer-encoding decoder stream is attached on the underlying stream, and resets it if the requested arguments differ.
getContentStream()  : MessagePartStreamDecorator|null
Checks what transfer-encoding decoder stream and charset conversion stream are currently attached on the underlying contentStream, and resets them if the requested arguments differ from the currently assigned ones.
getErrorLoggingContextName()  : string
Returns the class name. Override to identify objects in logs.
getErrors()  : array<string|int, Error>
Returns any local errors this object has at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR).
getStream()  : MessagePartStreamDecorator
Returns the part's stream containing the part's headers, content, and children.
hasAnyErrors()  : bool
Returns true if there are errors on this object, or any IErrorBag child of this object at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR). Note that this will stop after finding the first error and return, so may be slightly more performant if an error actually exists over calling getAllErrors if only interested in whether an error exists.
hasContent()  : bool
Returns true if there's a content stream associated with the part.
hasErrors()  : bool
Returns true if this object has an error in its error bag at or above the passed $minPsrLevel (defaults to ERROR). If $validate is true, additional validation may be performed.
reset()  : static
Resets cached encoding and charset streams, and rewinds the stream.
setContentStream()  : static
Attaches the passed stream as the content portion of this StreamContainer.
setStream()  : static
Sets the part's stream containing the part's headers, content, and children.
update()  : void
attachCharsetFilter()  : static
Attaches a charset conversion filter to the attached content handle, for the passed arguments.
attachTransferEncodingFilter()  : static
Attaches a decoding filter to the attached content handle, for the passed $transferEncoding.
getErrorBagChildren()  : array<string|int, IErrorBag>
Return any children ErrorBag objects.
requestParsedContentStream()  : static
Requests content from the parser if not previously requested, and calls PartStreamContainer::setContentStream().
requestParsedStream()  : static
Ensures the parser has parsed the entire part, and sets $this->parsedStream to the original parsed stream (or a limited part of it corresponding to the current part this stream container belongs to).
validate()  : void
Perform any extra validation and call 'addError'.
isCharsetFilterChanged()  : bool
Returns true if the attached stream filter used for charset conversion on the current handle is different from the one needed based on the passed arguments.
isTransferEncodingFilterChanged()  : bool
Returns true if the attached stream filter used for decoding the content on the current handle is different from the one passed as an argument.
resetCharsetStream()  : static
Resets just the charset stream, and rewinds the decodedStream.

Properties

$charsetStream

protected StreamInterface|null $charsetStream = null

attached charset stream to $decodedStream

$contentParseRequested

protected bool $contentParseRequested = false

false if the content for the part represented by this container has not yet been requested from the parser.

$contentStream

protected StreamInterface|null $contentStream = null

a stream containing this part's content

$decodedStream

protected StreamInterface|null $decodedStream = null

the content stream after attaching transfer encoding streams to $contentStream.

$detachParsedStream

protected bool $detachParsedStream = false

true if the stream should be detached when this container is destroyed.

$logger

protected LoggerInterface $logger

$mbWrapper

protected MbWrapper $mbWrapper

to test charsets and see if they're supported.

$partUpdated

protected bool $partUpdated = false

set to true if the part's been updated since it was created.

$throwExceptionReadingPartContentFromUnsupportedCharsets

protected bool $throwExceptionReadingPartContentFromUnsupportedCharsets

if false, reading from a content stream with an unsupported charset will be tried with the default charset, otherwise the stream created with the unsupported charset, and an exception will be thrown when read from.

$charset

private array<string|int, mixed> $charset = ['from' => null, 'to' => null, 'filter' => null]

map of the active charset filter on the current handle.

$encoding

private array<string|int, mixed> $encoding = ['type' => null, 'filter' => null]

map of the active encoding filter on the current handle.

$errors

private array<string|int, mixed> $errors = []

array of Error objects belonging to this object.

$validated

private bool $validated = false

true once the object has been validated.

Methods

__construct()

public __construct(LoggerInterface $logger, StreamFactory $streamFactory, MbWrapper $mbWrapper, bool $throwExceptionReadingPartContentFromUnsupportedCharsets, ParserPartProxy $parserProxy) : mixed
Parameters
$logger : LoggerInterface
$streamFactory : StreamFactory
$mbWrapper : MbWrapper
$throwExceptionReadingPartContentFromUnsupportedCharsets : bool
$parserProxy : ParserPartProxy
Return values
mixed

addError()

Creates and adds an Error object to this ErrorBag.

public addError(string $message, string $psrLogLevel[, Throwable|null $exception = null ]) : static
Parameters
$message : string
$psrLogLevel : string
$exception : Throwable|null = null
Return values
static

getAllErrors()

Returns any errors on this object, and all IErrorBag children of this object at or above the passed PSR log level from Psr\Log\LogLevel (defaulting to LogLevel::ERROR).

public getAllErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : array<string|int, Error>

Care should be taken using this if the intention is to only 'preview' a message without parsing it entirely, since this will cause the whole message to be parsed as it traverses children, and could be slow on messages with large attachments, etc...

If $validate is true, additional validation may be performed on children to check for errors.

Parameters
$validate : bool = false
$minPsrLevel : string = LogLevel::ERROR
Return values
array<string|int, Error>

getContentStream()

Checks what transfer-encoding decoder stream and charset conversion stream are currently attached on the underlying contentStream, and resets them if the requested arguments differ from the currently assigned ones.

public getContentStream(IMessagePart $part, string|null $transferEncoding, string|null $fromCharset, string|null $toCharset) : MessagePartStreamDecorator|null
Parameters
$part : IMessagePart

the part the stream belongs to

$transferEncoding : string|null

the transfer encoding

$fromCharset : string|null

the character set the content is encoded in

$toCharset : string|null

the target encoding to return

Return values
MessagePartStreamDecorator|null

getErrorLoggingContextName()

Returns the class name. Override to identify objects in logs.

public getErrorLoggingContextName() : string
Return values
string

getErrors()

Returns any local errors this object has at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR).

public getErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : array<string|int, Error>

If $validate is true, additional validation may be performed on the object to check for errors.

Parameters
$validate : bool = false
$minPsrLevel : string = LogLevel::ERROR
Return values
array<string|int, Error>

hasAnyErrors()

Returns true if there are errors on this object, or any IErrorBag child of this object at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR). Note that this will stop after finding the first error and return, so may be slightly more performant if an error actually exists over calling getAllErrors if only interested in whether an error exists.

public hasAnyErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : bool

Care should be taken using this if the intention is to only 'preview' a message without parsing it entirely, since this will cause the whole message to be parsed as it traverses children, and could be slow on messages with large attachments, etc...

If $validate is true, additional validation may be performed to check for errors.

Parameters
$validate : bool = false
$minPsrLevel : string = LogLevel::ERROR
Return values
bool

hasContent()

Returns true if there's a content stream associated with the part.

public hasContent() : bool
Return values
bool

hasErrors()

Returns true if this object has an error in its error bag at or above the passed $minPsrLevel (defaults to ERROR). If $validate is true, additional validation may be performed.

public hasErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : bool

The PSR levels are defined in Psr\Log\LogLevel.

Parameters
$validate : bool = false
$minPsrLevel : string = LogLevel::ERROR
Return values
bool

reset()

Resets cached encoding and charset streams, and rewinds the stream.

public reset() : static
Return values
static

setContentStream()

Attaches the passed stream as the content portion of this StreamContainer.

public setContentStream([StreamInterface|null $contentStream = null ]) : static

The content stream would represent the content portion of $this->stream.

If the content is overridden, $this->stream should point to a dynamic MessagePartStream that dynamically creates the RFC822 formatted message based on the IMessagePart this PartStreamContainer belongs to.

setContentStream can be called with 'null' to indicate the IMessagePart does not contain any content.

Parameters
$contentStream : StreamInterface|null = null
Return values
static

update()

public update(SplSubject $subject) : void
Parameters
$subject : SplSubject
Return values
void

attachCharsetFilter()

Attaches a charset conversion filter to the attached content handle, for the passed arguments.

protected attachCharsetFilter(string $fromCharset, string $toCharset) : static
Parameters
$fromCharset : string

the character set the content is encoded in

$toCharset : string

the target encoding to return

Return values
static

attachTransferEncodingFilter()

Attaches a decoding filter to the attached content handle, for the passed $transferEncoding.

protected attachTransferEncodingFilter(string|null $transferEncoding) : static
Parameters
$transferEncoding : string|null
Return values
static

getErrorBagChildren()

Return any children ErrorBag objects.

protected abstract getErrorBagChildren() : array<string|int, IErrorBag>
Return values
array<string|int, IErrorBag>

requestParsedContentStream()

Requests content from the parser if not previously requested, and calls PartStreamContainer::setContentStream().

protected requestParsedContentStream() : static
Return values
static

requestParsedStream()

Ensures the parser has parsed the entire part, and sets $this->parsedStream to the original parsed stream (or a limited part of it corresponding to the current part this stream container belongs to).

protected requestParsedStream() : static
Return values
static

validate()

Perform any extra validation and call 'addError'.

protected validate() : void

getErrors and getAllErrors call validate() if their $validate parameter is true. validate() is only called once on an object with getErrors getAllErrors.

Return values
void

isCharsetFilterChanged()

Returns true if the attached stream filter used for charset conversion on the current handle is different from the one needed based on the passed arguments.

private isCharsetFilterChanged(string $fromCharset, string $toCharset) : bool
Parameters
$fromCharset : string
$toCharset : string
Return values
bool

isTransferEncodingFilterChanged()

Returns true if the attached stream filter used for decoding the content on the current handle is different from the one passed as an argument.

private isTransferEncodingFilterChanged(string|null $transferEncoding) : bool
Parameters
$transferEncoding : string|null
Return values
bool

resetCharsetStream()

Resets just the charset stream, and rewinds the decodedStream.

private resetCharsetStream() : static
Return values
static

Search results