MailMimeParser 1.1

MessageParser

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

Tags
author

Zaahid Bateson

Table of Contents

$partBuilderFactory  : PartBuilderFactory
$partFactoryService  : PartFactoryService
$lastLineSeparatorLength  : int
__construct()  : mixed
Sets up the parser with its dependencies.
parse()  : Message
Parses the passed stream into a ZBateson\MailMimeParser\Message object and returns it.
read()  : PartBuilder
Reads the message from the passed stream and returns a PartBuilder representing it.
readHeaders()  : mixed
Reads header lines up to an empty line, adding them to the passed $partBuilder.
readPart()  : mixed
Reads a part and any of its children, into the passed $partBuilder, either by calling readUUEncodedOrPlainTextMessage or readPartContent after reading headers.
readUUEncodedOrPlainTextMessage()  : string
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.
addRawHeaderToPart()  : mixed
Ensures the header isn't empty and contains a colon separator character, then splits it and calls $partBuilder->addHeader.
findContentBoundary()  : mixed
Reads 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 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.
readLine()  : 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.
readPartContent()  : mixed
Reads content for a single part of a MIME message.

Properties

$lastLineSeparatorLength

private int $lastLineSeparatorLength = 0

Methods

parse()

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

public parse(StreamInterface $stream) : Message
Parameters
$stream : StreamInterface

the stream to parse the message from

Return values
Message

read()

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

protected read(StreamInterface $stream) : PartBuilder
Parameters
$stream : StreamInterface
Return values
PartBuilder

readHeaders()

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

protected readHeaders(resource $handle, PartBuilder $partBuilder) : mixed
Parameters
$handle : resource

the resource handle to read from

$partBuilder : PartBuilder

the current part to add headers to

Return values
mixed

readPart()

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

protected readPart(resource $handle, PartBuilder $partBuilder) : mixed
Parameters
$handle : resource
$partBuilder : PartBuilder
Return values
mixed

readUUEncodedOrPlainTextMessage()

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.

protected readUUEncodedOrPlainTextMessage(resource $handle, PartBuilder $partBuilder) : string
Parameters
$handle : resource
$partBuilder : PartBuilder
Return values
string

addRawHeaderToPart()

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

private addRawHeaderToPart(string $header, PartBuilder $partBuilder) : mixed
Parameters
$header : string
$partBuilder : PartBuilder
Return values
mixed

findContentBoundary()

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

private findContentBoundary(resource $handle, PartBuilder $partBuilder) : mixed

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 : PartBuilder
Return values
mixed

readBoundaryLine()

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.

private readBoundaryLine(resource $handle, int &$lineSeparatorLength) : 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 : int
Return values
string

readLine()

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.

private readLine(resource $handle) : string
Parameters
$handle : resource
Return values
string

readPartContent()

Reads content for a single part of a MIME message.

private readPartContent(resource $handle, PartBuilder $partBuilder) : mixed

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 : PartBuilder
Return values
mixed

Search results