MailMimeParser 2.4

MimeParser extends AbstractParser
in package

Parses content and children of MIME parts.

Tags
author

Zaahid Bateson

Table of Contents

$headerParser  : HeaderParser
$parserManager  : ParserManager
$parserMessageProxyFactory  : ParserPartProxyFactory
$parserPartProxyFactory  : ParserPartProxyFactory
$partBuilderFactory  : PartBuilderFactory
$partHeaderContainerFactory  : PartHeaderContainerFactory
__construct()  : mixed
canParse()  : bool
Returns true if the passed PartBuilder::isMime() method returns true.
getParserMessageProxyFactory()  : ParserPartProxyFactory
Returns the ParserPartProxyFactory responsible for creating IMessage parts for this parser.
getParserPartProxyFactory()  : ParserPartProxyFactory
Returns the ParserPartProxyFactory responsible for creating IMessagePart parts for this parser.
parseContent()  : static
parseNextChild()  : mixed
setParserManager()  : static
Sets up the passed ParserManager as the ParserManager for this part, which should be used when a new part is created (after its headers are read and a PartBuilder is created from it.)
createPart()  : ParserPartProxy|null
Calls the header parser to fill the passed $headerContainer, then calls $this->parserManager->createParserProxyFor($child);
findContentBoundary()  : self
Reads 2048-byte lines from the passed $handle, calling $partBuilder->setEndBoundaryFound with the passed line until it returns true or the stream is at EOF.
readBoundaryLine()  : string
Reads up to 2048 bytes of input from the passed resource handle, discarding portions of a line that are longer than that, and returning the read portions of the line.

Properties

$parserManager

protected ParserManager $parserManager

the ParserManager, which should call setParserManager when the parser is added.

$parserMessageProxyFactory

protected ParserPartProxyFactory $parserMessageProxyFactory

the parser's message proxy factory service responsible for creating an IMessage part wrapped in a ParserPartProxy.

$parserPartProxyFactory

protected ParserPartProxyFactory $parserPartProxyFactory

the parser's part proxy factory service responsible for creating IMessagePart parts wrapped in a ParserPartProxy.

Methods

__construct()

public __construct(ParserMessageProxyFactory $parserMessageProxyFactory, ParserMimePartProxyFactory $parserMimePartProxyFactory, PartBuilderFactory $partBuilderFactory, PartHeaderContainerFactory $partHeaderContainerFactory, HeaderParser $headerParser) : mixed
Parameters
$parserMessageProxyFactory : ParserMessageProxyFactory
$parserMimePartProxyFactory : ParserMimePartProxyFactory
$partBuilderFactory : PartBuilderFactory
$partHeaderContainerFactory : PartHeaderContainerFactory
$headerParser : HeaderParser
Return values
mixed

canParse()

Returns true if the passed PartBuilder::isMime() method returns true.

public canParse(PartBuilder $part) : bool
Parameters
$part : PartBuilder
Return values
bool

getParserMessageProxyFactory()

Returns the ParserPartProxyFactory responsible for creating IMessage parts for this parser.

public getParserMessageProxyFactory() : ParserPartProxyFactory

This is called by ParserManager after 'canParse' if it returns true so a ParserPartProxy can be created out of the PartBuilder.

Return values
ParserPartProxyFactory

getParserPartProxyFactory()

Returns the ParserPartProxyFactory responsible for creating IMessagePart parts for this parser.

public getParserPartProxyFactory() : ParserPartProxyFactory

This is called by ParserManager after 'canParse' if it returns true so a ParserPartProxy can be created out of the PartBuilder.

Return values
ParserPartProxyFactory

setParserManager()

Sets up the passed ParserManager as the ParserManager for this part, which should be used when a new part is created (after its headers are read and a PartBuilder is created from it.)

public setParserManager(ParserManager $pm) : static
Parameters
$pm : ParserManager

The ParserManager to set.

Return values
static

createPart()

Calls the header parser to fill the passed $headerContainer, then calls $this->parserManager->createParserProxyFor($child);

private createPart(ParserMimePartProxy $parent, PartHeaderContainer $headerContainer, PartBuilder $child) : ParserPartProxy|null

The method first checks though if the 'part' represents hidden content past a MIME end boundary, which some messages like to include, for instance:

--outer-boundary--
--boundary
content
--boundary--
some hidden information
--outer-boundary--

In this case, $this->parserPartProxyFactory is called directly to create a part, $this->parseContent is called immediately to parse it and discard it, and null is returned.

Parameters
$parent : ParserMimePartProxy
$headerContainer : PartHeaderContainer
$child : PartBuilder
Return values
ParserPartProxy|null

findContentBoundary()

Reads 2048-byte lines from the passed $handle, calling $partBuilder->setEndBoundaryFound with the passed line until it returns true or the stream is at EOF.

private findContentBoundary(ParserMimePartProxy $proxy) : self

setEndBoundaryFound returns true if the passed line matches a boundary for the $partBuilder itself or any of its parents.

Lines longer than 2048 bytes are returned as single lines of 2048 bytes, the longer line is not returned separately but is simply discarded.

Once a boundary is found, setStreamPartAndContentEndPos is called with the passed $handle's read pos before the boundary and its line separator were read.

Parameters
$proxy : ParserMimePartProxy
Return values
self

readBoundaryLine()

Reads up to 2048 bytes of input from the passed resource handle, discarding portions of a line that are longer than that, and returning the read portions of the line.

private readBoundaryLine(resource $handle, ParserMimePartProxy $proxy) : string

The method also calls $proxy->setLastLineEndingLength which is used in findContentBoundary() to set the exact end byte of a part.

Parameters
$handle : resource
$proxy : ParserMimePartProxy
Return values
string

Search results