MailMimeParser 1.2

Message extends MimePart

A parsed mime message with optional mime parts depending on its type.

A mime message may have any number of mime parts, and each part may have any number of sub-parts, etc...

Tags
author

Zaahid Bateson

Table of Contents

$messageHelperService  : MessageHelperService
__construct()  : mixed
Constructor
addAttachmentPart()  : mixed
Adds an attachment part for the passed raw data string or handle and given parameters.
addAttachmentPartFromFile()  : mixed
Adds an attachment part using the passed file.
from()  : Message
Convenience method to parse a handle or string into a Message without requiring including MailMimeParser, instantiating it, and calling parse.
getAllAttachmentParts()  : array<string|int, MessagePart>
Returns all attachment parts.
getAttachmentCount()  : int
Returns the number of attachments available.
getAttachmentPart()  : MessagePart
Returns the attachment part at the given 0-based index, or null if none is set.
getCharset()  : string
Returns the upper-cased charset of the Content-Type header's charset parameter if set, ISO-8859-1 if the Content-Type is text/plain or text/html and the charset parameter isn't set, or null otherwise.
getContentDisposition()  : string
Returns the content's disposition, defaulting to 'inline' if not set.
getContentId()  : string|null
Returns the Content ID of the part.
getContentTransferEncoding()  : string
Returns the content-transfer-encoding used for this part, defaulting to '7bit' if not set.
getContentType()  : string
Returns the lower-cased, trimmed value of the Content-Type header.
getFilename()  : string
Returns a filename for the part if one is defined, or null otherwise.
getHtmlContent()  : string
Returns the content of the inline text/html part at the given index.
getHtmlPart()  : MessagePart
Returns the text/html part at the given index (or null if not found.)
getHtmlPartCount()  : int
Returns the number of text/html parts in this message.
getHtmlResourceHandle()  : resource
Returns a resource handle for the 'inline' text/html content at the passed $index, or null if unavailable.
getHtmlStream()  : StreamInterface
Returns a Psr7 Stream for the 'inline' text/html content at the passed $index, or null if unavailable.
getPartByContentId()  : MessagePart
Convenience method to find a part by its Content-ID header.
getSignaturePart()  : MimePart
Returns the signature part of a multipart/signed message or null.
getSignedMessageAsString()  : string
Returns a string containing the entire body of a signed message for verification or calculating a signature.
getSignedMessageStream()  : StreamInterface
Returns a stream that can be used to read the content part of a signed message, which can be used to sign an email or verify a signature.
getTextContent()  : string
Returns the content of the inline text/plain part at the given index.
getTextPart()  : MessagePart
Returns the text/plain part at the given index (or null if not found.)
getTextPartCount()  : int
Returns the number of text/plain parts in this message.
getTextResourceHandle()  : resource
Returns a resource handle for the 'inline' text/plain content at the passed $index, or null if unavailable.
getTextStream()  : StreamInterface
Returns a Psr7 Stream for the 'inline' text/plain content at the passed $index, or null if unavailable.
isMime()  : bool
Returns true if either a Content-Type or Mime-Version header are defined in this Message.
isMultiPart()  : bool
Returns true if this part's mime type is multipart/*
isTextPart()  : bool
Returns true if this part's mime type is text/plain, text/html or if the Content-Type header defines a charset.
removeAllHtmlParts()  : bool
Removes all text/html inline parts in this message, optionally keeping other inline parts as attachments on the main message (defaults to keeping them).
removeAllTextParts()  : bool
Removes all text/plain inline parts in this message, optionally keeping other inline parts as attachments on the main message (defaults to keeping them).
removeAttachmentPart()  : mixed
Removes the attachment with the given index
removeHtmlPart()  : bool
Removes the html part of the message if one exists. Returns true on success.
removeTextPart()  : bool
Removes the text/plain part of the message at the passed index if one exists. Returns true on success.
setAsMultipartSigned()  : mixed
Turns the message into a multipart/signed message, moving the actual message into a child part, sets the content-type of the main message to multipart/signed and adds an empty signature part as well.
setHtmlPart()  : mixed
Sets the text/html part of the message to the passed $stringOrHandle, either creating a new part if one doesn't exist for text/html, or assigning the value of $stringOrHandle to an existing text/html part.
setSignature()  : mixed
Sets the signature body of the message to the passed $body for a multipart/signed message.
setTextPart()  : mixed
Sets the text/plain part of the message to the passed $stringOrHandle, either creating a new part if one doesn't exist for text/plain, or assigning the value of $stringOrHandle to an existing text/plain part.

Properties

Methods

__construct()

Constructor

public __construct(PartStreamFilterManager $partStreamFilterManager, StreamFactory $streamFactory, PartFilterFactory $partFilterFactory, PartBuilder $partBuilder, MessageHelperService $messageHelperService[, StreamInterface $stream = null ][, StreamInterface $contentStream = null ]) : mixed
Parameters
$partStreamFilterManager : PartStreamFilterManager
$streamFactory : StreamFactory
$partFilterFactory : PartFilterFactory
$partBuilder : PartBuilder
$messageHelperService : MessageHelperService
$stream : StreamInterface = null
$contentStream : StreamInterface = null
Return values
mixed —

addAttachmentPart()

Adds an attachment part for the passed raw data string or handle and given parameters.

public addAttachmentPart(string|resource|StreamInterface $resource, string $mimeType[, string $filename = null ][, string $disposition = 'attachment' ][, string $encoding = 'base64' ]) : mixed
Parameters
$resource : string|resource|StreamInterface
$mimeType : string
$filename : string = null
$disposition : string = 'attachment'
$encoding : string = 'base64'

defaults to 'base64', only applied for a mime email

Return values
mixed —

addAttachmentPartFromFile()

Adds an attachment part using the passed file.

public addAttachmentPartFromFile(string $filePath, string $mimeType[, string $filename = null ][, string $disposition = 'attachment' ][, mixed $encoding = 'base64' ]) : mixed

Essentially creates a file stream and uses it.

Parameters
$filePath : string
$mimeType : string
$filename : string = null
$disposition : string = 'attachment'
$encoding : mixed = 'base64'
Return values
mixed —

from()

Convenience method to parse a handle or string into a Message without requiring including MailMimeParser, instantiating it, and calling parse.

public static from(resource|string $handleOrString) : Message
Parameters
$handleOrString : resource|string

the resource handle to the input stream of the mime message, or a string containing a mime message

Return values
Message —

getAllAttachmentParts()

Returns all attachment parts.

public getAllAttachmentParts() : array<string|int, MessagePart>

"Attachments" are any non-multipart, non-signature and any text or html html part witha Content-Disposition set to 'attachment'.

Return values
array<string|int, MessagePart> —

getAttachmentCount()

Returns the number of attachments available.

public getAttachmentCount() : int
Return values
int —

getAttachmentPart()

Returns the attachment part at the given 0-based index, or null if none is set.

public getAttachmentPart(int $index) : MessagePart
Parameters
$index : int
Return values
MessagePart —

getCharset()

Returns the upper-cased charset of the Content-Type header's charset parameter if set, ISO-8859-1 if the Content-Type is text/plain or text/html and the charset parameter isn't set, or null otherwise.

public getCharset() : string

If the charset parameter is set to 'binary' it is ignored and considered 'not set' (returns ISO-8859-1 for text/plain, text/html or null otherwise).

Return values
string —

getContentDisposition()

Returns the content's disposition, defaulting to 'inline' if not set.

public getContentDisposition([string $default = 'inline' ]) : string
Parameters
$default : string = 'inline'

pass to override the default returned disposition when not set.

Return values
string —

getContentId()

Returns the Content ID of the part.

public getContentId() : string|null

In MimePart, this is merely a shortcut to calling $part->getHeaderValue('Content-ID');.

Return values
string|null —

getContentTransferEncoding()

Returns the content-transfer-encoding used for this part, defaulting to '7bit' if not set.

public getContentTransferEncoding([string $default = '7bit' ]) : string
Parameters
$default : string = '7bit'

pass to override the default when not set.

Return values
string —

getContentType()

Returns the lower-cased, trimmed value of the Content-Type header.

public getContentType([string $default = 'text/plain' ]) : string

Parses the Content-Type header, defaults to returning text/plain if not defined.

Parameters
$default : string = 'text/plain'

pass to override the returned value when not set

Return values
string —

getFilename()

Returns a filename for the part if one is defined, or null otherwise.

public getFilename() : string
Return values
string —

getHtmlContent()

Returns the content of the inline text/html part at the given index.

public getHtmlContent(int $index[, string $charset = MailMimeParser::DEFAULT_CHARSET ]) : string

Reads the entire stream content into a string and returns it. Returns null if the message doesn't have an inline html part.

Parameters
$index : int
$charset : string = MailMimeParser::DEFAULT_CHARSET
Return values
string —

getHtmlPart()

Returns the text/html part at the given index (or null if not found.)

public getHtmlPart(int $index) : MessagePart
Parameters
$index : int
Return values
MessagePart —

getHtmlPartCount()

Returns the number of text/html parts in this message.

public getHtmlPartCount() : int
Return values
int —

getHtmlResourceHandle()

Returns a resource handle for the 'inline' text/html content at the passed $index, or null if unavailable.

public getHtmlResourceHandle(int $index[, string $charset = MailMimeParser::DEFAULT_CHARSET ]) : resource

Note: this method should not be used and has been deprecated. Instead, use Psr7 streams with getHtmlStream. Multibyte chars will not be read correctly with getHtmlResourceHandle/fread.

Parameters
$index : int
$charset : string = MailMimeParser::DEFAULT_CHARSET
Tags
deprecated

since version 1.2.1

Return values
resource —

getHtmlStream()

Returns a Psr7 Stream for the 'inline' text/html content at the passed $index, or null if unavailable.

public getHtmlStream(int $index[, string $charset = MailMimeParser::DEFAULT_CHARSET ]) : StreamInterface
Parameters
$index : int
$charset : string = MailMimeParser::DEFAULT_CHARSET
Return values
StreamInterface —

getPartByContentId()

Convenience method to find a part by its Content-ID header.

public getPartByContentId(string $contentId) : MessagePart
Parameters
$contentId : string
Return values
MessagePart —

getSignaturePart()

Returns the signature part of a multipart/signed message or null.

public getSignaturePart() : MimePart

The signature part is determined to always be the 2nd child of a multipart/signed message, the first being the 'body'.

Using the 'protocol' parameter of the Content-Type header is unreliable in some instances (for instance a difference of x-pgp-signature versus pgp-signature).

Return values
MimePart —

getSignedMessageAsString()

Returns a string containing the entire body of a signed message for verification or calculating a signature.

public getSignedMessageAsString() : string

Non-CRLF new lines are replaced to always be CRLF.

Return values
string —

or null if the message doesn't have any children

getSignedMessageStream()

Returns a stream that can be used to read the content part of a signed message, which can be used to sign an email or verify a signature.

public getSignedMessageStream() : StreamInterface

The method simply returns the stream for the first child. No verification of whether the message is in fact a signed message is performed.

Note that unlike getSignedMessageAsString, getSignedMessageStream doesn't replace new lines.

Return values
StreamInterface —

or null if the message doesn't have any children

getTextContent()

Returns the content of the inline text/plain part at the given index.

public getTextContent(int $index[, string $charset = MailMimeParser::DEFAULT_CHARSET ]) : string

Reads the entire stream content into a string and returns it. Returns null if the message doesn't have an inline text part.

Parameters
$index : int
$charset : string = MailMimeParser::DEFAULT_CHARSET
Return values
string —

getTextPart()

Returns the text/plain part at the given index (or null if not found.)

public getTextPart(int $index) : MessagePart
Parameters
$index : int
Return values
MessagePart —

getTextPartCount()

Returns the number of text/plain parts in this message.

public getTextPartCount() : int
Return values
int —

getTextResourceHandle()

Returns a resource handle for the 'inline' text/plain content at the passed $index, or null if unavailable.

public getTextResourceHandle(int $index[, string $charset = MailMimeParser::DEFAULT_CHARSET ]) : resource

Note: this method should not be used and has been deprecated. Instead, use Psr7 streams with getTextStream. Multibyte chars will not be read correctly with getTextResourceHandle/fread.

Parameters
$index : int
$charset : string = MailMimeParser::DEFAULT_CHARSET
Tags
deprecated

since version 1.2.1

Return values
resource —

getTextStream()

Returns a Psr7 Stream for the 'inline' text/plain content at the passed $index, or null if unavailable.

public getTextStream(int $index[, string $charset = MailMimeParser::DEFAULT_CHARSET ]) : StreamInterface
Parameters
$index : int
$charset : string = MailMimeParser::DEFAULT_CHARSET
Return values
StreamInterface —

isMime()

Returns true if either a Content-Type or Mime-Version header are defined in this Message.

public isMime() : bool
Return values
bool —

isMultiPart()

Returns true if this part's mime type is multipart/*

public isMultiPart() : bool
Return values
bool —

isTextPart()

Returns true if this part's mime type is text/plain, text/html or if the Content-Type header defines a charset.

public isTextPart() : bool
Return values
bool —

removeAllHtmlParts()

Removes all text/html inline parts in this message, optionally keeping other inline parts as attachments on the main message (defaults to keeping them).

public removeAllHtmlParts([bool $keepOtherPartsAsAttachments = true ]) : bool
Parameters
$keepOtherPartsAsAttachments : bool = true
Return values
bool —

true on success

removeAllTextParts()

Removes all text/plain inline parts in this message, optionally keeping other inline parts as attachments on the main message (defaults to keeping them).

public removeAllTextParts([bool $keepOtherPartsAsAttachments = true ]) : bool
Parameters
$keepOtherPartsAsAttachments : bool = true
Return values
bool —

true on success

removeAttachmentPart()

Removes the attachment with the given index

public removeAttachmentPart(int $index) : mixed
Parameters
$index : int
Return values
mixed —

removeHtmlPart()

Removes the html part of the message if one exists. Returns true on success.

public removeHtmlPart(int $index) : bool
Parameters
$index : int
Return values
bool —

true on success

removeTextPart()

Removes the text/plain part of the message at the passed index if one exists. Returns true on success.

public removeTextPart(int $index) : bool
Parameters
$index : int
Return values
bool —

true on success

setAsMultipartSigned()

Turns the message into a multipart/signed message, moving the actual message into a child part, sets the content-type of the main message to multipart/signed and adds an empty signature part as well.

public setAsMultipartSigned(string $micalg, string $protocol) : mixed

After calling setAsMultipartSigned, call getSignedMessageAsString to return a

Parameters
$micalg : string

The Message Integrity Check algorithm being used

$protocol : string

The mime-type of the signature body

Return values
mixed —

setHtmlPart()

Sets the text/html part of the message to the passed $stringOrHandle, either creating a new part if one doesn't exist for text/html, or assigning the value of $stringOrHandle to an existing text/html part.

public setHtmlPart(string|resource|StreamInterface $resource[, string $charset = 'UTF-8' ]) : mixed

The optional $charset parameter is the charset for saving to. $stringOrHandle is expected to be in UTF-8 regardless of the target charset.

Parameters
$resource : string|resource|StreamInterface
$charset : string = 'UTF-8'
Return values
mixed —

setSignature()

Sets the signature body of the message to the passed $body for a multipart/signed message.

public setSignature(string $body) : mixed
Parameters
$body : string
Return values
mixed —

setTextPart()

Sets the text/plain part of the message to the passed $stringOrHandle, either creating a new part if one doesn't exist for text/plain, or assigning the value of $stringOrHandle to an existing text/plain part.

public setTextPart(string|resource|StreamInterface $resource[, string $charset = 'UTF-8' ]) : mixed

The optional $charset parameter is the charset for saving to. $stringOrHandle is expected to be in UTF-8 regardless of the target charset.

Parameters
$resource : string|resource|StreamInterface
$charset : string = 'UTF-8'
Return values
mixed —

Search results