MailMimeParser 0.4

MessageParser

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

Tags
author

Zaahid Bateson

Table of Contents

$message  : Message
$partFactory  : MimePartFactory
$partStreamRegistry  : PartStreamRegistry
__construct()  : mixed
Sets up the parser with its dependencies.
parse()  : Message
Parses the passed stream handle into the ZBateson\MailMimeParser\Message object and returns it.
attachStreamHandles()  : mixed
read()  : mixed
Reads the message from the input stream $handle into $message.
readHeaders()  : mixed
Reads header lines up to an empty line, adding them to the passed $part.
readMimeMessagePart()  : MimePart
Finds the boundaries for the current MimePart, reads its content and creates and returns the next part, setting its parent part accordingly.
readPartContent()  : bool
Reads the content of a mime part up to a boundary, or the entire message if no boundary is specified.
readUUEncodedOrPlainTextPart()  : string
Reads one part of a UUEncoded message and adds it to the passed Message as a MimePart.
addRawHeaderToPart()  : mixed
Ensures the header isn't empty, and contains a colon character, then splits it and assigns it to $part
addToParent()  : mixed
Adds the part to its parent.
findNextUUEncodedPartPosition()  : mixed
Extracts the filename and end position of a UUEncoded part.
findPartBoundaries()  : mixed
Finds the end of the Mime part at the current read position in $handle and sets $boundaryLength to the number of bytes in the part, and $endBoundaryFound to true if it's an 'end' boundary, meaning there are no further parts for the current mime part (ends with --).
getParentBoundary()  : string
Returns the boundary from the parent MimePart, or the current boundary if $parent is null
newMimePartForMessage()  : MimePart
Instantiates and returns a new MimePart setting the part's parent to either the passed $parent, or $message if $parent is null.
readLine()  : string
Reads a line of up to the passed number of 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.
readMimeMessageBoundaryParts()  : MimePart
Keeps reading if an end boundary is found, to find the parent's boundary and the part's content.

Properties

Methods

parse()

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

public parse(resource $fhandle) : Message
Parameters
$fhandle : resource

the resource handle to the input stream of the mime message

Return values
Message

attachStreamHandles()

protected attachStreamHandles(type $handle, MimePart $part, Message $message, type $contentStartPos, type $boundaryLength) : mixed
Parameters
$handle : type
$part : MimePart
$message : Message
$contentStartPos : type
$boundaryLength : type
Return values
mixed

read()

Reads the message from the input stream $handle into $message.

protected read(resource $handle, Message $message) : mixed

The method will loop to read headers and find and parse multipart-mime message parts and uuencoded attachments (as mime-parts), adding them to the passed Message object.

Parameters
$handle : resource
$message : Message
Return values
mixed

readHeaders()

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

protected readHeaders(resource $handle, MimePart $part) : mixed
Parameters
$handle : resource

the resource handle to read from

$part : MimePart

the current part to add headers to

Return values
mixed

readMimeMessagePart()

Finds the boundaries for the current MimePart, reads its content and creates and returns the next part, setting its parent part accordingly.

protected readMimeMessagePart(resource $handle, Message $message, MimePart $part) : MimePart
Parameters
$handle : resource

The handle to read from

$message : Message

The current Message

$part : MimePart
Return values
MimePart

readPartContent()

Reads the content of a mime part up to a boundary, or the entire message if no boundary is specified.

protected readPartContent(resource $handle, Message $message, MimePart $part, string $boundary, bool $skipPart) : bool

readPartContent may be called to skip to the first boundary to read its headers, in which case $skipPart should be true.

If the end boundary is found, the method returns true.

Parameters
$handle : resource

the input stream resource

$message : Message

the current Message object

$part : MimePart

the current MimePart object to load the content into.

$boundary : string

the MIME boundary

$skipPart : bool

pass true if the intention is to read up to the beginning MIME boundary's headers

Return values
bool

if the end boundary is found

readUUEncodedOrPlainTextPart()

Reads one part of a UUEncoded message and adds it to the passed Message as a MimePart.

protected readUUEncodedOrPlainTextPart(resource $handle, Message $message) : string

The method reads up to the first 'begin' part of the message, or to the end of the message if no 'begin' exists.

Parameters
$handle : resource
$message : Message
Return values
string

addRawHeaderToPart()

Ensures the header isn't empty, and contains a colon character, then splits it and assigns it to $part

private addRawHeaderToPart(string $header, MimePart $part) : mixed
Parameters
$header : string
$part : MimePart
Return values
mixed

addToParent()

Adds the part to its parent.

private addToParent(MimePart $part) : mixed
Parameters
$part : MimePart
Return values
mixed

findNextUUEncodedPartPosition()

Extracts the filename and end position of a UUEncoded part.

private findNextUUEncodedPartPosition(resource $handle) : mixed

The filename is set to the passed $nextFilename parameter. The end position is returned.

Parameters
$handle : resource

the current file handle

Return values
mixed

findPartBoundaries()

Finds the end of the Mime part at the current read position in $handle and sets $boundaryLength to the number of bytes in the part, and $endBoundaryFound to true if it's an 'end' boundary, meaning there are no further parts for the current mime part (ends with --).

private findPartBoundaries(resource $handle, string $boundary, int &$boundaryLength, bool &$endBoundaryFound) : mixed
Parameters
$handle : resource
$boundary : string
$boundaryLength : int
$endBoundaryFound : bool
Return values
mixed

getParentBoundary()

Returns the boundary from the parent MimePart, or the current boundary if $parent is null

private getParentBoundary(string $curBoundary[, MimePart $parent = null ]) : string
Parameters
$curBoundary : string
$parent : MimePart = null
Return values
string

newMimePartForMessage()

Instantiates and returns a new MimePart setting the part's parent to either the passed $parent, or $message if $parent is null.

private newMimePartForMessage(Message $message[, MimePart $parent = null ]) : MimePart
Parameters
$message : Message
$parent : MimePart = null
Return values
MimePart

readLine()

Reads a line of up to the passed number of 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 readLine(resource $handle[, int $size = 4096 ]) : string
Parameters
$handle : resource
$size : int = 4096
Return values
string

readMimeMessageBoundaryParts()

Keeps reading if an end boundary is found, to find the parent's boundary and the part's content.

private readMimeMessageBoundaryParts(resource $handle, Message $message, MimePart $parent, MimePart $part, string $boundary, bool $skipFirst) : MimePart
Parameters
$handle : resource
$message : Message
$parent : MimePart
$part : MimePart
$boundary : string
$skipFirst : bool
Return values
MimePart

Search results