MessageParser
Parses a mail mime message into its component parts. To invoke, call MailMimeParser::parse.
Tags
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.
- readPartContent() : mixed
- Reads content for a single part of a MIME message.
Properties
$partBuilderFactory
protected
PartBuilderFactory
$partBuilderFactory
$partFactoryService
protected
PartFactoryService
$partFactoryService
$lastLineSeparatorLength
private
int
$lastLineSeparatorLength
= 0
Methods
__construct()
Sets up the parser with its dependencies.
public
__construct(PartFactoryService $pfs, PartBuilderFactory $pbf) : mixed
Parameters
- $pfs : PartFactoryService
- $pbf : PartBuilderFactory
Return values
mixed —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 —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