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
Table of Contents
- $charsetOverride : string
- $children : array<string|int, MessagePart>
- $contentStream : StreamInterface
- $headerContainer : HeaderContainer
- $ignoreTransferEncoding : bool
- $messageHelperService : MessageHelperService
- $parent : ParentPart
- $partFilterFactory : PartFilterFactory
- $partStreamFilterManager : PartStreamFilterManager
- $stream : StreamInterface
- $streamFactory : StreamFactory
- __construct() : mixed
- Constructor
- __destruct() : mixed
- Overridden to close streams.
- __toString() : string
- Returns the message/part as a string.
- 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.
- addChild() : mixed
- Registers the passed part as a child of the current part.
- addRawHeader() : mixed
- Adds a header with the given $name and $value.
- attachContentStream() : mixed
- Attaches the stream or resource handle for the part's content. The stream is closed when another stream is attached, or the MimePart is destroyed.
- detachContentStream() : mixed
- Detaches and closes the content stream.
- 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.
- getAllHeaders() : array<string|int, AbstractHeader>
- Returns an array of headers in this part.
- getAllHeadersByName() : array<string|int, AbstractHeader>
- Returns an array of headers that match the passed name.
- getAllParts() : array<string|int, MessagePart>
- Returns the current part, all child parts, and child parts of all children optionally filtering them with the provided PartFilter.
- getAllPartsByMimeType() : array<string|int, MessagePart>
- Returns an array of all parts associated with the passed mime type if any exist or null otherwise.
- 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.
- getBinaryContentResourceHandle() : resource|null
- Returns a resource handle for the content's raw data stream, or null if the part doesn't have a content stream.
- getBinaryContentStream() : StreamInterface
- Returns the raw data stream for the current part, if it exists, or null if there's no content associated with the stream.
- getCharset() : string
- Returns the charset of the content, or null if not applicable/defined.
- getChild() : MessagePart
- Returns the direct child at the given 0-based index, or null if none is set.
- getChildCount() : int
- Returns the number of direct children under this part.
- getChildParts() : array<string|int, MessagePart>
- Returns all direct child parts.
- getContent() : string
- Shortcut to reading stream content and assigning it to a string. Returns null if the part doesn't have a content stream.
- getContentDisposition() : string
- Returns the content's disposition.
- getContentId() : string|null
- Returns the Content ID of the part, or null if not defined.
- getContentResourceHandle() : resource|null
- Returns a resource handle for the content's stream, or null if the part doesn't have a content stream.
- getContentStream() : StreamInterface
- Returns the StreamInterface for the part's content or null if the part doesn't have a content section.
- getContentTransferEncoding() : string
- Returns the content-transfer-encoding used for this part.
- getContentType() : string
- Returns the mime type of the content.
- getCountOfPartsByMimeType() : int
- Returns the number of parts matching the passed $mimeType
- getFilename() : string
- Returns a filename for the part if one is defined, or null otherwise.
- getHeader() : AbstractHeader
- Returns the AbstractHeader object for the header with the given $name.
- getHeaderParameter() : string
- Returns a parameter of the header $header, given the parameter named $param.
- getHeaderValue() : string
- Returns the string value for the header with the given $name.
- 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.
- getParent() : MimePart
- Returns this part's parent.
- getPart() : MessagePart
- Returns the part at the given 0-based index, or null if none is set.
- getPartByContentId() : MessagePart
- Convenience method to find a part by its Content-ID header.
- getPartByMimeType() : MessagePart|null
- Returns the part associated with the passed mime type, at the passed index, if it exists.
- getPartCount() : int
- Returns the total number of parts in this and all children.
- getRawHeaderIterator() : Iterator
- Returns an iterator to the headers in this collection. Each returned element is an array with its first element set to the header's name, and the second to its raw value:
- getRawHeaders() : array<string|int, array<string|int, string>>
- Returns an array of all headers for the mime part with the first element holding the name, and the second its value.
- getResourceHandle() : resource
- Returns a resource handle containing this part, including any headers for a MimePart, its content, and all its children.
- 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.
- getStream() : StreamInterface
- Returns a Psr7 StreamInterface containing this part, including any headers for a MimePart, its content, and all its children.
- 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.
- hasContent() : bool
- Returns true if there's a content stream associated with the part.
- 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 has a text/* and has a defined 'charset' attribute.
- markAsChanged() : mixed
- Marks the part as changed, forcing the part to be rewritten when saved.
- 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).
- removeAllParts() : mixed
- Removes all parts that are matched by the passed PartFilter.
- 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
- removeHeader() : mixed
- Removes all headers from this part with the passed name.
- removeHtmlPart() : bool
- Removes the html part of the message if one exists. Returns true on success.
- removePart() : int
- Removes the child part from this part and returns its position or null if it wasn't found.
- removeSingleHeader() : mixed
- Removes a single header with the passed name (in cases where more than one may exist, and others should be preserved).
- removeTextPart() : bool
- Removes the text/plain part of the message at the passed index if one exists. Returns true on success.
- save() : mixed
- Saves the message/part to the passed file, resource, or stream.
- saveContent() : mixed
- Saves the binary content of the stream to the passed file, resource or stream.
- 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.
- setCharsetOverride() : mixed
- Overrides the default character set used for reading content from content streams in cases where a user knows the source charset is not what is specified.
- setContent() : mixed
- Sets the content of the part to the passed resource.
- 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.
- setRawHeader() : mixed
- Adds a header with the given $name and $value. An optional $offset may be passed, which will overwrite a header if one exists with the given name and offset. Otherwise a new header is added. The passed $offset may be ignored in that case if it doesn't represent the next insert position for the header with the passed name... instead it would be 'pushed' on at the next position.
- 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.
- getAllNonFilteredParts() : array<string|int, MessagePart>
- Returns all parts, including the current object, and all children below it (including children of children, etc...)
- onChange() : mixed
- Called when operations change the content of the MessagePart.
Properties
$charsetOverride
protected
string
$charsetOverride
$children
protected
array<string|int, MessagePart>
$children
= []
$contentStream
protected
StreamInterface
$contentStream
$headerContainer
protected
HeaderContainer
$headerContainer
$ignoreTransferEncoding
protected
bool
$ignoreTransferEncoding
$messageHelperService
protected
MessageHelperService
$messageHelperService
$parent
protected
ParentPart
$parent
$partFilterFactory
protected
PartFilterFactory
$partFilterFactory
$partStreamFilterManager
protected
PartStreamFilterManager
$partStreamFilterManager
$stream
protected
StreamInterface
$stream
$streamFactory
protected
StreamFactory
$streamFactory
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 —__destruct()
Overridden to close streams.
public
__destruct() : mixed
Return values
mixed —__toString()
Returns the message/part as a string.
public
__toString() : string
Convenience method for calling getStream()->getContents().
Return values
string —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 —addChild()
Registers the passed part as a child of the current part.
public
addChild(MessagePart $part[, int $position = null ]) : mixed
If the $position parameter is non-null, adds the part at the passed position index.
Parameters
- $part : MessagePart
- $position : int = null
Return values
mixed —addRawHeader()
Adds a header with the given $name and $value.
public
addRawHeader(string $name, string $value) : mixed
Note: If a header with the passed name already exists, a new header is created with the same name. This should only be used when that is intentional - in most cases setRawHeader should be called.
Creates a new \ZBateson\MailMimeParser\Header\AbstractHeader object and registers it as a header.
Parameters
- $name : string
- $value : string
Return values
mixed —attachContentStream()
Attaches the stream or resource handle for the part's content. The stream is closed when another stream is attached, or the MimePart is destroyed.
public
attachContentStream(StreamInterface $stream[, string $streamCharset = MailMimeParser::DEFAULT_CHARSET ]) : mixed
Parameters
- $stream : StreamInterface
- $streamCharset : string = MailMimeParser::DEFAULT_CHARSET
Return values
mixed —detachContentStream()
Detaches and closes the content stream.
public
detachContentStream() : mixed
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> —getAllHeaders()
Returns an array of headers in this part.
public
getAllHeaders() : array<string|int, AbstractHeader>
Return values
array<string|int, AbstractHeader> —getAllHeadersByName()
Returns an array of headers that match the passed name.
public
getAllHeadersByName(string $name) : array<string|int, AbstractHeader>
Parameters
- $name : string
Return values
array<string|int, AbstractHeader> —getAllParts()
Returns the current part, all child parts, and child parts of all children optionally filtering them with the provided PartFilter.
public
getAllParts([PartFilter $filter = null ]) : array<string|int, MessagePart>
The first part returned is always the current MimePart. This is often desirable as it may be a valid MimePart for the provided PartFilter.
Parameters
- $filter : PartFilter = null
-
an optional filter
Return values
array<string|int, MessagePart> —getAllPartsByMimeType()
Returns an array of all parts associated with the passed mime type if any exist or null otherwise.
public
getAllPartsByMimeType(string $mimeType) : array<string|int, MessagePart>
Parameters
- $mimeType : string
Return values
array<string|int, MessagePart> —or null
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 —getBinaryContentResourceHandle()
Returns a resource handle for the content's raw data stream, or null if the part doesn't have a content stream.
public
getBinaryContentResourceHandle() : resource|null
The method wraps a call to MessagePart::getBinaryContentStream() and returns a resource handle for the returned Stream.
Return values
resource|null —getBinaryContentStream()
Returns the raw data stream for the current part, if it exists, or null if there's no content associated with the stream.
public
getBinaryContentStream() : StreamInterface
This is basically the same as calling MessagePart::getContentStream(), except no automatic charset conversion is done. Note that for non-text streams, this doesn't have an effect, as charset conversion is not performed in that case, and is useful only when:
- The charset defined is not correct, and the conversion produces errors; or
- You'd like to read the raw contents without conversion, for instance to save it to file or allow a user to download it as-is (in a download link for example).
Return values
StreamInterface —getCharset()
Returns the charset of the content, or null if not applicable/defined.
public
abstract getCharset() : string
Return values
string —getChild()
Returns the direct child at the given 0-based index, or null if none is set.
public
getChild(int $index[, PartFilter $filter = null ]) : MessagePart
Parameters
- $index : int
- $filter : PartFilter = null
Return values
MessagePart —getChildCount()
Returns the number of direct children under this part.
public
getChildCount([PartFilter $filter = null ]) : int
Parameters
- $filter : PartFilter = null
Return values
int —getChildParts()
Returns all direct child parts.
public
getChildParts([PartFilter $filter = null ]) : array<string|int, MessagePart>
If a PartFilter is provided, the PartFilter is applied before returning.
Parameters
- $filter : PartFilter = null
Return values
array<string|int, MessagePart> —getContent()
Shortcut to reading stream content and assigning it to a string. Returns null if the part doesn't have a content stream.
public
getContent([string $charset = MailMimeParser::DEFAULT_CHARSET ]) : string
The returned string is encoded to the passed $charset character encoding, defaulting to UTF-8.
Parameters
- $charset : string = MailMimeParser::DEFAULT_CHARSET
Tags
Return values
string —getContentDisposition()
Returns the content's disposition.
public
abstract getContentDisposition() : string
Return values
string —getContentId()
Returns the Content ID of the part, or null if not defined.
public
abstract getContentId() : string|null
Return values
string|null —getContentResourceHandle()
Returns a resource handle for the content's stream, or null if the part doesn't have a content stream.
public
getContentResourceHandle([string $charset = MailMimeParser::DEFAULT_CHARSET ]) : resource|null
The method wraps a call to MessagePart::getContentStream() and returns a resource handle for the returned Stream.
Note: this method should not be used and has been deprecated. Instead, use Psr7 streams with getContentStream. Multibyte chars will not be read correctly with fread.
Parameters
- $charset : string = MailMimeParser::DEFAULT_CHARSET
Tags
Return values
resource|null —getContentStream()
Returns the StreamInterface for the part's content or null if the part doesn't have a content section.
public
getContentStream([string $charset = MailMimeParser::DEFAULT_CHARSET ]) : StreamInterface
The library automatically handles decoding and charset conversion (to the target passed $charset) based on the part's transfer encoding as returned by MessagePart::getContentTransferEncoding() and the part's charset as returned by MessagePart::getCharset(). The returned stream is ready to be read from directly.
Note that the returned Stream is a shared object. If called multiple time with the same $charset, and the value of the part's Content-Transfer-Encoding header not having changed, the stream will be rewound. This would affect other existing variables referencing the stream, for example:
// assuming $part is a part containing the following
// string for its content: '12345678'
$stream = $part->getContentStream();
$someChars = $part->read(4);
$stream2 = $part->getContentStream();
$moreChars = $part->read(4);
echo ($someChars === $moreChars); //1
In this case the Stream was rewound, and $stream's second call to read 4 bytes reads the same first 4.
Parameters
- $charset : string = MailMimeParser::DEFAULT_CHARSET
Return values
StreamInterface —getContentTransferEncoding()
Returns the content-transfer-encoding used for this part.
public
abstract getContentTransferEncoding() : string
Return values
string —getContentType()
Returns the mime type of the content.
public
abstract getContentType() : string
Return values
string —getCountOfPartsByMimeType()
Returns the number of parts matching the passed $mimeType
public
getCountOfPartsByMimeType(string $mimeType) : int
Parameters
- $mimeType : string
Return values
int —getFilename()
Returns a filename for the part if one is defined, or null otherwise.
public
getFilename() : string
Return values
string —getHeader()
Returns the AbstractHeader object for the header with the given $name.
public
getHeader(string $name, int $offset) : AbstractHeader
If the optional $offset is passed, and multiple headers exist with the same name, the one at the passed offset is returned.
Note that mime headers aren't case sensitive.
Parameters
- $name : string
- $offset : int
Return values
AbstractHeader —|\ZBateson\MailMimeParser\Header\AddressHeader |\ZBateson\MailMimeParser\Header\DateHeader |\ZBateson\MailMimeParser\Header\GenericHeader |\ZBateson\MailMimeParser\Header\IdHeader |\ZBateson\MailMimeParser\Header\ParameterHeader |\ZBateson\MailMimeParser\Header\ReceivedHeader |\ZBateson\MailMimeParser\Header\SubjectHeader
getHeaderParameter()
Returns a parameter of the header $header, given the parameter named $param.
public
getHeaderParameter(string $header, string $param[, string $defaultValue = null ]) : string
Only headers of type \ZBateson\MailMimeParser\Header\ParameterHeader have parameters. Content-Type and Content-Disposition are examples of headers with parameters. "Charset" is a common parameter of Content-Type.
Parameters
- $header : string
- $param : string
- $defaultValue : string = null
Return values
string —getHeaderValue()
Returns the string value for the header with the given $name.
public
getHeaderValue(string $name[, string $defaultValue = null ]) : string
Note that mime headers aren't case sensitive.
Parameters
- $name : string
- $defaultValue : string = null
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
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 —getParent()
Returns this part's parent.
public
getParent() : MimePart
Return values
MimePart —getPart()
Returns the part at the given 0-based index, or null if none is set.
public
getPart(int $index[, PartFilter $filter = null ]) : MessagePart
Note that the first part returned is the current part itself. This is often desirable for queries with a PartFilter, e.g. looking for a MessagePart with a specific Content-Type that may be satisfied by the current part.
Parameters
- $index : int
- $filter : PartFilter = null
Return values
MessagePart —getPartByContentId()
Convenience method to find a part by its Content-ID header.
public
getPartByContentId(string $contentId) : MessagePart
Parameters
- $contentId : string
Return values
MessagePart —getPartByMimeType()
Returns the part associated with the passed mime type, at the passed index, if it exists.
public
getPartByMimeType(string $mimeType, int $index) : MessagePart|null
Parameters
- $mimeType : string
- $index : int
Return values
MessagePart|null —getPartCount()
Returns the total number of parts in this and all children.
public
getPartCount([PartFilter $filter = null ]) : int
Note that the current part is considered, so the minimum getPartCount is 1 without a filter.
Parameters
- $filter : PartFilter = null
Return values
int —getRawHeaderIterator()
Returns an iterator to the headers in this collection. Each returned element is an array with its first element set to the header's name, and the second to its raw value:
public
getRawHeaderIterator() : Iterator
[ 'Header-Name', 'Header Value' ]
Return values
Iterator —getRawHeaders()
Returns an array of all headers for the mime part with the first element holding the name, and the second its value.
public
getRawHeaders() : array<string|int, array<string|int, string>>
Return values
array<string|int, array<string|int, string>> —getResourceHandle()
Returns a resource handle containing this part, including any headers for a MimePart, its content, and all its children.
public
getResourceHandle() : resource
Return values
resource —the resource handle
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
getStream()
Returns a Psr7 StreamInterface containing this part, including any headers for a MimePart, its content, and all its children.
public
getStream() : StreamInterface
Return values
StreamInterface —the resource handle
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
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 —hasContent()
Returns true if there's a content stream associated with the part.
public
hasContent() : bool
Return values
bool —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 has a text/* and has a defined 'charset' attribute.
public
abstract isTextPart() : bool
Return values
bool —markAsChanged()
Marks the part as changed, forcing the part to be rewritten when saved.
public
markAsChanged() : mixed
Normal operations to a MessagePart automatically mark the part as changed and markAsChanged() doesn't need to be called in those cases.
The function can be called to indicate an external change that requires rewriting this part, for instance changing a message from a non-mime message to a mime one, would require rewriting non-mime children to insure suitable headers are written.
Internally, the function discards the part's stream, forcing a stream to be created when calling getStream().
Return values
mixed —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
removeAllParts()
Removes all parts that are matched by the passed PartFilter.
public
removeAllParts([PartFilter $filter = null ]) : mixed
Note: the current part will not be removed. Although the function naming matches getAllParts, which returns the current part, it also doesn't only remove direct children like getChildParts. Internally this function uses getAllParts but the current part is filtered out if returned.
Parameters
- $filter : PartFilter = null
Return values
mixed —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 —removeHeader()
Removes all headers from this part with the passed name.
public
removeHeader(string $name) : mixed
Parameters
- $name : string
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
removePart()
Removes the child part from this part and returns its position or null if it wasn't found.
public
removePart(MessagePart $part) : int
Note that if the part is not a direct child of this part, the returned position is its index within its parent (calls removePart on its direct parent).
Parameters
- $part : MessagePart
Return values
int —or null if not found
removeSingleHeader()
Removes a single header with the passed name (in cases where more than one may exist, and others should be preserved).
public
removeSingleHeader(string $name, mixed $offset) : mixed
Parameters
- $name : string
- $offset : mixed
Return values
mixed —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
save()
Saves the message/part to the passed file, resource, or stream.
public
save(string|resource|StreamInterface $filenameResourceOrStream) : mixed
If the passed parameter is a string, it's assumed to be a filename to write to. The file is opened in 'w+' mode, and closed before returning.
When passing a resource or Psr7 Stream, the resource is not closed, nor rewound.
Parameters
- $filenameResourceOrStream : string|resource|StreamInterface
Return values
mixed —saveContent()
Saves the binary content of the stream to the passed file, resource or stream.
public
saveContent(string|resource|Stream $filenameResourceOrStream) : mixed
Note that charset conversion is not performed in this case, and the contents of the part are saved in their binary format as transmitted (but after any content-transfer decoding is performed). MessagePart::getBinaryContentStream() for a more detailed description of the stream.
If the passed parameter is a string, it's assumed to be a filename to write to. The file is opened in 'w+' mode, and closed before returning.
When passing a resource or Psr7 Stream, the resource is not closed, nor rewound.
Parameters
- $filenameResourceOrStream : string|resource|Stream
Return values
mixed —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 —setCharsetOverride()
Overrides the default character set used for reading content from content streams in cases where a user knows the source charset is not what is specified.
public
setCharsetOverride(string $charsetOverride[, bool $onlyIfNoCharset = false ]) : mixed
If set, the returned value from MessagePart::getCharset is ignored.
Note that setting an override on a Message and calling getTextStream, getTextContent, getHtmlStream or getHtmlContent will not be applied to those sub-parts, unless the text/html part is the Message itself. Instead, Message:getTextPart() should be called, and setCharsetOverride called on the returned MessagePart.
Parameters
- $charsetOverride : string
- $onlyIfNoCharset : bool = false
-
if true, $charsetOverride is used only if getCharset returns null.
Return values
mixed —setContent()
Sets the content of the part to the passed resource.
public
setContent(string|resource|StreamInterface $resource[, string $charset = MailMimeParser::DEFAULT_CHARSET ]) : mixed
Parameters
- $resource : string|resource|StreamInterface
- $charset : string = MailMimeParser::DEFAULT_CHARSET
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 —setRawHeader()
Adds a header with the given $name and $value. An optional $offset may be passed, which will overwrite a header if one exists with the given name and offset. Otherwise a new header is added. The passed $offset may be ignored in that case if it doesn't represent the next insert position for the header with the passed name... instead it would be 'pushed' on at the next position.
public
setRawHeader(string $name, string $value, int $offset) : mixed
$part = $myParentHeaderPart;
$part->setRawHeader('New-Header', 'value');
echo $part->getHeaderValue('New-Header'); // 'value'
$part->setRawHeader('New-Header', 'second', 4);
echo is_null($part->getHeader('New-Header', 4)); // '1' (true)
echo $part->getHeader('New-Header', 1)
->getValue(); // 'second'
A new \ZBateson\MailMimeParser\Header\AbstractHeader object is created from the passed value. No processing on the passed string is performed, and so the passed name and value must be formatted correctly according to related RFCs. In particular, be careful to encode non-ascii data, to keep lines under 998 characters in length, and to follow any special formatting required for the type of header.
Parameters
- $name : string
- $value : string
- $offset : int
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 —getAllNonFilteredParts()
Returns all parts, including the current object, and all children below it (including children of children, etc...)
protected
getAllNonFilteredParts() : array<string|int, MessagePart>
Return values
array<string|int, MessagePart> —onChange()
Called when operations change the content of the MessagePart.
protected
onChange() : mixed
The function causes calls to getStream() to return a dynamic MessagePartStream instead of the read stream for this MessagePart and all parent MessageParts.