Parses a mail mime message into its component parts. To invoke, call MailMimeParser::parse.

author Zaahid Bateson
package MailMimeParser

 Methods

Sets up the parser with its dependencies.

__construct(\ZBateson\MailMimeParser\Message\Part\Factory\PartFactoryService $pfs, \ZBateson\MailMimeParser\Message\Part\Factory\PartBuilderFactory $pbf) 

Parameters

$pfs

\ZBateson\MailMimeParser\Message\Part\Factory\PartFactoryService

$pbf

\ZBateson\MailMimeParser\Message\Part\Factory\PartBuilderFactory

Parses the passed stream into a ZBateson\MailMimeParser\Message object and returns it.

parse(\Psr\Http\Message\StreamInterface $stream) : \ZBateson\MailMimeParser\Message

Parameters

$stream

\Psr\Http\Message\StreamInterface

the stream to parse the message from

Returns

\ZBateson\MailMimeParser\Message

Reads the message from the passed stream and returns a PartBuilder representing it.

read(\Psr\Http\Message\StreamInterface $stream) : \ZBateson\MailMimeParser\Message\Part\PartBuilder

Parameters

$stream

\Psr\Http\Message\StreamInterface

Returns

\ZBateson\MailMimeParser\Message\Part\PartBuilder

Reads header lines up to an empty line, adding them to the passed $partBuilder.

readHeaders(resource $handle, \ZBateson\MailMimeParser\Message\Part\PartBuilder $partBuilder) 

Parameters

$handle

resource

the resource handle to read from

$partBuilder

\ZBateson\MailMimeParser\Message\Part\PartBuilder

the current part to add headers to

Reads a part and any of its children, into the passed $partBuilder, either by calling readUUEncodedOrPlainTextMessage or readPartContent after reading headers.

readPart(resource $handle, \ZBateson\MailMimeParser\Message\Part\PartBuilder $partBuilder) 

Parameters

$handle

resource

$partBuilder

\ZBateson\MailMimeParser\Message\Part\PartBuilder

Reads content for a non-mime message. If there are uuencoded attachment parts in the message (denoted by 'begin' lines), those parts are read and added to the passed $partBuilder as children.

readUUEncodedOrPlainTextMessage(resource $handle, \ZBateson\MailMimeParser\Message\Part\PartBuilder $partBuilder) : string

Parameters

$handle

resource

$partBuilder

\ZBateson\MailMimeParser\Message\Part\PartBuilder

Returns

string

Ensures the header isn't empty and contains a colon separator character, then splits it and calls $partBuilder->addHeader.

addRawHeaderToPart(string $header, \ZBateson\MailMimeParser\Message\Part\PartBuilder $partBuilder) 

Parameters

$header

string

$partBuilder

\ZBateson\MailMimeParser\Message\Part\PartBuilder

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

findContentBoundary(resource $handle, \ZBateson\MailMimeParser\Message\Part\PartBuilder $partBuilder) 

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

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

$handle

resource

$partBuilder

\ZBateson\MailMimeParser\Message\Part\PartBuilder

Reads a line of 2048 characters. If the line is larger than that, the remaining characters in the line are read and discarded, and only the first part is returned.

readBoundaryLine(resource $handle, integer $lineSeparatorLength = 0) : string

This method is identical to readLine, except it calculates the number of characters that make up the line's new line characters (e.g. 2 for "\r\n" or 1 for "\n").

Parameters

$handle

resource

$lineSeparatorLength

integer

Returns

string

Reads a line of up to 4096 characters. If the line is larger than that, the remaining characters in the line are read and discarded, and only the first 4096 characters are returned.

readLine(resource $handle) : string

Parameters

$handle

resource

Returns

string

Reads content for a single part of a MIME message.

readPartContent(resource $handle, \ZBateson\MailMimeParser\Message\Part\PartBuilder $partBuilder) 

If the part being read is in turn a multipart part, readPart is called on it recursively to read its headers and content.

The start/end positions of the part's content are set on the passed $partBuilder, which in turn sets the end position of the part and its parents.

Parameters

$handle

resource

$partBuilder

\ZBateson\MailMimeParser\Message\Part\PartBuilder

 Properties

 

used to create PartBuilders

$partBuilderFactory : \ZBateson\MailMimeParser\Message\Part\Factory\PartBuilderFactory

Default

 

service instance used to create MimePartFactory objects.

$partFactoryService : \ZBateson\MailMimeParser\Message\Part\Factory\PartFactoryService

Default

 

maintains the character length of the last line separator, typically 2 for CRLF, to keep track of the correct 'end' position for a part because the CRLF before a boundary is considered part of the boundary.

$lastLineSeparatorLength : integer

Default

0