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
- $handle : resource
- $headerFactory : HeaderFactory
- $headers : array<string|int, AbstractHeader>
- $messageWriter : MessageWriter
- $mimePartFactory : MimePartFactory
- $objectId : string
- $originalStreamHandle : mixed
- $parent : MimePart
- $parts : array<string|int, MimePart>
- $partWriter : MimePartWriter
- __construct() : mixed
- Constructs a Message.
- __destruct() : mixed
- Closes the attached resource handle.
- __toString() : string
- Shortcut to call Message::save with a php://temp stream and return the written email message as a string.
- addAttachmentPart() : MimePart
- Adds an attachment part for the passed raw data string or handle and given parameters.
- addAttachmentPartFromFile() : MimePart
- Adds an attachment part using the passed file.
- addPart() : mixed
- Registers the passed part as a child of the current part.
- attachContentResourceHandle() : mixed
- Attaches the resource handle for the part's content. The attached handle is closed when the MimePart object is destroyed.
- attachOriginalStreamHandle() : mixed
- Attaches the resource handle representing the original stream that created this part (including any sub-parts). The attached handle is closed when the MimePart object is destroyed.
- createSignaturePart() : mixed
- Creates and returns a new MimePart for the signature part of a multipart/signed message
- from() : mixed
- Convenience method to parse a handle or string into a Message without requiring including MailMimeParser, instantiating it, and calling parse.
- getAllAttachmentParts() : array<string|int, MimePart>
- Returns all attachment parts.
- getAllParts() : array<string|int, MimePart>
- Returns the current part, all child parts, and child parts of all children optionally filtering them with the provided PartFilter.
- getAllPartsByMimeType() : array<string|int, MimePart>
- 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() : MimePart
- Returns the attachment part at the given 0-based index, or null if none is set.
- getChild() : MimePart
- 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, MimePart>
- 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.
- getContentPart() : MimePart
- Returns the content MimePart, which could be a text/plain part, text/html part, multipart/alternative part, or null if none is set.
- getContentResourceHandle() : resource
- Returns the resource stream handle for the part's content or null if not set. rewind() is called on the stream before returning it.
- getCountOfPartsByMimeType() : int
- Returns the number of parts matching the passed $mimeType
- 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.
- getHeaders() : array<string|int, AbstractHeader>
- Returns the full array of headers for this part.
- 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() : MimePart
- 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.
- getHtmlStream() : resource
- Returns a resource handle where the 'inline' text/html content at the passed $index can be read or null if unavailable.
- getObjectId() : string
- Returns the unique object ID registered with the PartStreamRegistry service object.
- getOriginalMessageStringForSignatureVerification() : string
- Returns a string containing the original message's signed part, useful for verifying the email.
- getOriginalStreamHandle() : resource
- Returns a resource stream handle allowing a user to read the original stream (including headers and child parts) that was used to create the current part.
- getParent() : MimePart
- Returns this part's parent.
- getPart() : MimePart
- Returns the part at the given 0-based index, or null if none is set.
- getPartByMimeType() : MimePart
- Returns the part associated with the passed mime type if it exists.
- getPartCount() : int
- Returns the total number of parts in this and all children.
- getSignableBody() : string
- Returns the content part of a signed message for a signature to be calculated on the message.
- getSignaturePart() : MimePart
- Returns the signed part or null if not set.
- getTextContent() : string
- Returns the content of the inline text/plain part at the given index.
- getTextPart() : MimePart
- 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.
- getTextStream() : resource
- Returns a resource handle where the 'inline' text/plain content at the passed $index can be read 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.
- 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 the header with the given 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.
- 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 as a MIME message to the passed resource handle.
- 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 a signature part as well.
- setContent() : mixed
- Sets the content of the part to the passed string (effectively creates a php://temp stream with the passed content and calls attachContentResourceHandle with the opened stream).
- 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.
- setParent() : mixed
- Sets the parent part.
- setRawHeader() : mixed
- Adds a header with the given $name and $value.
- 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.
- createPartForAttachment() : MimePart
- Creates and returns a MimePart for use with a new attachment part being created.
- detachContentResourceHandle() : mixed
- Detaches the content resource handle from this part but does not close it.
- removeAllContentPartsByMimeType() : bool
- Removes the content part of the message with the passed mime type. If there is a remaining content part and it is an alternative part of the main message, the content part is moved to the message part.
- removePartByMimeType() : bool
- Removes the 'inline' part with the passed contentType, at the given index defaulting to the first
- setContentPartForMimeType() : mixed
- Either creates a mime part or sets the existing mime part with the passed mimeType to $strongOrHandle.
- copyTypeHeadersFromPartToPart() : mixed
- Copies Content-Type, Content-Disposition and Content-Transfer-Encoding headers from the $from header into the $to header. If the Content-Type header isn't defined in $from, defaults to text/plain and quoted-printable.
- createAlternativeContentPart() : MimePart
- Creates a new mime part as a multipart/alternative and assigns the passed $contentPart as a part below it before returning it.
- createContentPartForMimeType() : MimePart
- Creates a new content part for the passed mimeType and charset, making space by creating a multipart/alternative if needed
- createMultipartRelatedPartForInlineChildrenOf() : MimePart
- Creates a multipart/related part out of 'inline' children of $parent and returns it.
- createNewContentPartFromPart() : MimePart
- Creates a new content part from the passed part, allowing the part to be used for something else (e.g. changing a non-mime message to a multipart mime message).
- enforceMime() : mixed
- Enforces the message to be a mime message for a non-mime (e.g. uuencoded or unspecified) message. If the message has uuencoded attachments, sets up the message as a multipart/mixed message and creates a content part.
- ensureHtmlPartFirstForSignedMessage() : mixed
- Ensures a non-text part comes first in a signed multipart/alternative message as some clients seem to prefer the first content part if the client doesn't understand multipart/signed.
- findOtherContentPartFor() : MimeType
- Finds an alternative inline part in the message and returns it if one exists.
- getContentPartContainerFromAlternative() : bool|MimePart
- Returns the direct child of $alternativePart containing a part of $mimeType.
- getHandleForStringOrHandle() : resource
- Returns an open resource handle for the passed string or resource handle.
- getUniqueBoundary() : string
- Creates and returns a unique boundary.
- makeSpaceForMultipartSignedMessage() : mixed
- This function makes space by moving the main message part down one level.
- moveAllPartsAsAttachmentsExcept() : mixed
- Moves all parts under $from into this message except those with a content-type equal to $exceptMimeType. If the message is not a multipart/mixed message, it is set to multipart/mixed first.
- movePartContentAndChildrenToPart() : mixed
- Copies type headers (Content-Type, Content-Disposition, Content-Transfer-Encoding) from the $from MimePart to $to. Attaches the content resource handle of $from to $to, and loops over child parts, removing them from $from and adding them to $to.
- overwrite8bitContentEncoding() : mixed
- Loops over parts of this message and sets the content-transfer-encoding header to quoted-printable for text/* mime parts, and to base64 otherwise for parts that are '8bit' encoded.
- removeAllContentPartsFromAlternative() : bool
- Removes all parts of $mimeType from $alternativePart.
- replacePart() : mixed
- Replaces the $part MimePart with $replacement.
- setMessageAsAlternative() : mixed
- Sets this message to be a multipart/alternative message, making space for a second content part.
- setMessageAsMixed() : mixed
- Creates a new part out of the current contentPart and sets the message's type to be multipart/mixed.
- setMimeHeaderBoundaryOnPart() : mixed
- Creates a unique mime boundary and assigns it to the passed part's Content-Type header with the passed mime type.
Properties
$handle
protected
resource
$handle
$headerFactory
protected
HeaderFactory
$headerFactory
$headers
protected
array<string|int, AbstractHeader>
$headers
$messageWriter
protected
MessageWriter
$messageWriter
= null
$mimePartFactory
protected
MimePartFactory
$mimePartFactory
$objectId
protected
string
$objectId
Tags
$originalStreamHandle
protected
mixed
$originalStreamHandle
$parent
protected
MimePart
$parent
$parts
protected
array<string|int, MimePart>
$parts
= []
$partWriter
protected
MimePartWriter
$partWriter
= null
Methods
__construct()
Constructs a Message.
public
__construct(HeaderFactory $headerFactory, MessageWriter $messageWriter, MimePartFactory $mimePartFactory) : mixed
Parameters
- $headerFactory : HeaderFactory
- $messageWriter : MessageWriter
- $mimePartFactory : MimePartFactory
Return values
mixed —__destruct()
Closes the attached resource handle.
public
__destruct() : mixed
Return values
mixed —__toString()
Shortcut to call Message::save with a php://temp stream and return the written email message as a string.
public
__toString() : string
Return values
string —addAttachmentPart()
Adds an attachment part for the passed raw data string or handle and given parameters.
public
addAttachmentPart(string|handle $stringOrHandle, strubg $mimeType[, string $filename = null ][, string $disposition = 'attachment' ]) : MimePart
Parameters
- $stringOrHandle : string|handle
- $mimeType : strubg
- $filename : string = null
- $disposition : string = 'attachment'
Return values
MimePart —addAttachmentPartFromFile()
Adds an attachment part using the passed file.
public
addAttachmentPartFromFile(string $file, string $mimeType[, string $filename = null ][, string $disposition = 'attachment' ]) : MimePart
Essentially creates a file stream and uses it.
Parameters
- $file : string
- $mimeType : string
- $filename : string = null
- $disposition : string = 'attachment'
Return values
MimePart —addPart()
Registers the passed part as a child of the current part.
public
addPart(MimePart $part[, int $position = null ]) : mixed
If the $position parameter is non-null, adds the part at the passed position index.
Parameters
- $part : MimePart
- $position : int = null
Return values
mixed —attachContentResourceHandle()
Attaches the resource handle for the part's content. The attached handle is closed when the MimePart object is destroyed.
public
attachContentResourceHandle(resource $contentHandle) : mixed
Parameters
- $contentHandle : resource
Return values
mixed —attachOriginalStreamHandle()
Attaches the resource handle representing the original stream that created this part (including any sub-parts). The attached handle is closed when the MimePart object is destroyed.
public
attachOriginalStreamHandle(resource $handle) : mixed
This stream is not modified or changed as the part is changed and is only set during parsing in MessageParser.
Parameters
- $handle : resource
Return values
mixed —createSignaturePart()
Creates and returns a new MimePart for the signature part of a multipart/signed message
public
createSignaturePart(string $body) : mixed
Parameters
- $body : string
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) : mixed
Parameters
- $handleOrString : resource|string
-
the resource handle to the input stream of the mime message, or a string containing a mime message
Return values
mixed —getAllAttachmentParts()
Returns all attachment parts.
public
getAllAttachmentParts() : array<string|int, MimePart>
Attachments are any non-multipart, non-signature and non inline text or html part (a text or html part with a Content-Disposition set to 'attachment' is considered an attachment).
Return values
array<string|int, MimePart> —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, MimePart>
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, MimePart> —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, MimePart>
Parameters
- $mimeType : string
Return values
array<string|int, MimePart> —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) : MimePart
Parameters
- $index : int
Return values
MimePart —getChild()
Returns the direct child at the given 0-based index, or null if none is set.
public
getChild(int $index[, PartFilter $filter = null ]) : MimePart
Parameters
- $index : int
- $filter : PartFilter = null
Return values
MimePart —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, MimePart>
If a PartFilter is provided, the PartFilter is applied before returning.
Parameters
- $filter : PartFilter = null
Return values
array<string|int, MimePart> —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
Return values
string —getContentPart()
Returns the content MimePart, which could be a text/plain part, text/html part, multipart/alternative part, or null if none is set.
public
getContentPart() : MimePart
This function is deprecated in favour of getTextPart/getHtmlPart and getPartByMimeType.
Tags
Return values
MimePart —getContentResourceHandle()
Returns the resource stream handle for the part's content or null if not set. rewind() is called on the stream before returning it.
public
getContentResourceHandle() : resource
The resource is automatically closed by MimePart's destructor and should not be closed otherwise.
The returned resource handle is a stream with decoding filters appended to it. The attached filters are determined by looking at the part's Content-Encoding header. The following encodings are currently supported:
- Quoted-Printable
- Base64
- X-UUEncode
UUEncode may be automatically attached for a message without a defined Content-Encoding and Content-Type if it has a UUEncoded part to support older non-mime message attachments.
In addition, character encoding for text streams is converted to UTF-8 if MimePart::isTextPart returns true.
Return values
resource —getCountOfPartsByMimeType()
Returns the number of parts matching the passed $mimeType
public
getCountOfPartsByMimeType(string $mimeType) : int
Parameters
- $mimeType : string
Return values
int —getHeader()
Returns the AbstractHeader object for the header with the given $name
public
getHeader(string $name) : AbstractHeader
Note that mime headers aren't case sensitive.
Parameters
- $name : string
Return values
AbstractHeader —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 —getHeaders()
Returns the full array of headers for this part.
public
getHeaders() : array<string|int, AbstractHeader>
Return values
array<string|int, AbstractHeader> —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
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
Return values
string —getHtmlPart()
Returns the text/html part at the given index (or null if not found.)
public
getHtmlPart( $index) : MimePart
Parameters
Return values
MimePart —getHtmlPartCount()
Returns the number of text/html parts in this message.
public
getHtmlPartCount() : int
Return values
int —getHtmlStream()
Returns a resource handle where the 'inline' text/html content at the passed $index can be read or null if unavailable.
public
getHtmlStream(mixed $index) : resource
Parameters
- $index : mixed
Return values
resource —getObjectId()
Returns the unique object ID registered with the PartStreamRegistry service object.
public
getObjectId() : string
Return values
string —getOriginalMessageStringForSignatureVerification()
Returns a string containing the original message's signed part, useful for verifying the email.
public
getOriginalMessageStringForSignatureVerification() : string
If the signed part of the message ends in a final empty line, the line is removed as it's considered part of the signature's mime boundary. From RFC-3156:
Note: The accepted OpenPGP convention is for signed data to end
with a
The additional line should be inserted by the signer -- for verification
purposes if it's missing, it would seem the content part would've been
signed without a last
Return values
string —or null if the message doesn't have any children, or the child returns null for getOriginalStreamHandle
getOriginalStreamHandle()
Returns a resource stream handle allowing a user to read the original stream (including headers and child parts) that was used to create the current part.
public
getOriginalStreamHandle() : resource
The part contains an original stream handle only if it was explicitly set by a call to MimePart::attachOriginalStreamHandle. MailMimeParser only sets this during the parsing phase in MessageParser, and is not otherwise changed or updated. New parts added below this part, changed headers, etc... would not be reflected in the returned stream handle.
Return values
resource —the resource handle or null if not set
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 ]) : MimePart
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 MimePart with a specific Content-Type that may be satisfied by the current part.
Parameters
- $index : int
- $filter : PartFilter = null
Return values
MimePart —getPartByMimeType()
Returns the part associated with the passed mime type if it exists.
public
getPartByMimeType(string $mimeType, mixed $index) : MimePart
Parameters
- $mimeType : string
- $index : mixed
Return values
MimePart —or 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 —getSignableBody()
Returns the content part of a signed message for a signature to be calculated on the message.
public
getSignableBody() : string
Return values
string —getSignaturePart()
Returns the signed part or null if not set.
public
getSignaturePart() : MimePart
Return values
MimePart —getTextContent()
Returns the content of the inline text/plain part at the given index.
public
getTextContent(int $index) : 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
Return values
string —getTextPart()
Returns the text/plain part at the given index (or null if not found.)
public
getTextPart(int $index) : MimePart
Parameters
- $index : int
Return values
MimePart —getTextPartCount()
Returns the number of text/plain parts in this message.
public
getTextPartCount() : int
Return values
int —getTextStream()
Returns a resource handle where the 'inline' text/plain content at the passed $index can be read or null if unavailable.
public
getTextStream(int $index) : resource
Parameters
- $index : int
Return values
resource —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
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
removeAllParts()
Removes all parts that are matched by the passed PartFilter.
public
removeAllParts([PartFilter $filter = null ]) : mixed
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 the header with the given 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(mixed $index) : bool
Parameters
- $index : mixed
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(MimePart $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 : MimePart
Return values
int —or null if not found
removeTextPart()
Removes the text/plain part of the message at the passed index if one exists. Returns true on success.
public
removeTextPart(mixed $index) : bool
Parameters
- $index : mixed
Return values
bool —true on success
save()
Saves the message as a MIME message to the passed resource handle.
public
save(resource $handle) : mixed
Parameters
- $handle : resource
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 a signature part as well.
public
setAsMultipartSigned(string $micalg, string $protocol) : mixed
Parameters
- $micalg : string
-
The Message Integrity Check algorithm being used
- $protocol : string
-
The mime-type of the signature body
Return values
mixed —setContent()
Sets the content of the part to the passed string (effectively creates a php://temp stream with the passed content and calls attachContentResourceHandle with the opened stream).
public
setContent(string $string) : mixed
Parameters
- $string : string
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 $stringOrHandle[, 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
- $stringOrHandle : string|resource
- $charset : string = 'UTF-8'
Return values
mixed —setParent()
Sets the parent part.
public
setParent(MimePart $part) : mixed
Parameters
- $part : MimePart
Return values
mixed —setRawHeader()
Adds a header with the given $name and $value.
public
setRawHeader(string $name, string $value) : mixed
Creates a new \ZBateson\MailMimeParser\Header\AbstractHeader object and registers it as a header.
Parameters
- $name : string
- $value : 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 $stringOrHandle[, 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
- $stringOrHandle : string|resource
- $charset : string = 'UTF-8'
Return values
mixed —createPartForAttachment()
Creates and returns a MimePart for use with a new attachment part being created.
protected
createPartForAttachment() : MimePart
Return values
MimePart —detachContentResourceHandle()
Detaches the content resource handle from this part but does not close it.
protected
detachContentResourceHandle() : mixed
Return values
mixed —removeAllContentPartsByMimeType()
Removes the content part of the message with the passed mime type. If there is a remaining content part and it is an alternative part of the main message, the content part is moved to the message part.
protected
removeAllContentPartsByMimeType(string $mimeType[, bool $keepOtherContent = false ]) : bool
If the content part is part of an alternative part beneath the message, the alternative part is replaced by the remaining content part, optionally keeping other parts if $keepOtherContent is set to true.
Parameters
- $mimeType : string
- $keepOtherContent : bool = false
Return values
bool —true on success
removePartByMimeType()
Removes the 'inline' part with the passed contentType, at the given index defaulting to the first
protected
removePartByMimeType(mixed $mimeType, int $index) : bool
Parameters
- $mimeType : mixed
- $index : int
Return values
bool —true on success
setContentPartForMimeType()
Either creates a mime part or sets the existing mime part with the passed mimeType to $strongOrHandle.
protected
setContentPartForMimeType(string $mimeType, string|resource $stringOrHandle, string $charset) : mixed
Parameters
- $mimeType : string
- $stringOrHandle : string|resource
- $charset : string
Return values
mixed —copyTypeHeadersFromPartToPart()
Copies Content-Type, Content-Disposition and Content-Transfer-Encoding headers from the $from header into the $to header. If the Content-Type header isn't defined in $from, defaults to text/plain and quoted-printable.
private
copyTypeHeadersFromPartToPart(MimePart $from, MimePart $to) : mixed
Parameters
Return values
mixed —createAlternativeContentPart()
Creates a new mime part as a multipart/alternative and assigns the passed $contentPart as a part below it before returning it.
private
createAlternativeContentPart(MimePart $contentPart) : MimePart
Parameters
- $contentPart : MimePart
Return values
MimePart —the alternative part
createContentPartForMimeType()
Creates a new content part for the passed mimeType and charset, making space by creating a multipart/alternative if needed
private
createContentPartForMimeType(string $mimeType, string $charset) : MimePart
Parameters
- $mimeType : string
- $charset : string
Return values
MimePart —createMultipartRelatedPartForInlineChildrenOf()
Creates a multipart/related part out of 'inline' children of $parent and returns it.
private
createMultipartRelatedPartForInlineChildrenOf(MimePart $parent) : MimePart
Parameters
- $parent : MimePart
Return values
MimePart —createNewContentPartFromPart()
Creates a new content part from the passed part, allowing the part to be used for something else (e.g. changing a non-mime message to a multipart mime message).
private
createNewContentPartFromPart(MimePart $part) : MimePart
Parameters
- $part : MimePart
Return values
MimePart —the newly-created MimePart
enforceMime()
Enforces the message to be a mime message for a non-mime (e.g. uuencoded or unspecified) message. If the message has uuencoded attachments, sets up the message as a multipart/mixed message and creates a content part.
private
enforceMime() : mixed
Return values
mixed —ensureHtmlPartFirstForSignedMessage()
Ensures a non-text part comes first in a signed multipart/alternative message as some clients seem to prefer the first content part if the client doesn't understand multipart/signed.
private
ensureHtmlPartFirstForSignedMessage() : mixed
Return values
mixed —findOtherContentPartFor()
Finds an alternative inline part in the message and returns it if one exists.
private
findOtherContentPartFor(string $mimeType) : MimeType
If the passed $mimeType is text/plain, searches for a text/html part. Otherwise searches for a text/plain part to return.
Parameters
- $mimeType : string
Return values
MimeType —or null if not found
getContentPartContainerFromAlternative()
Returns the direct child of $alternativePart containing a part of $mimeType.
private
getContentPartContainerFromAlternative(string $mimeType, MimePart $alternativePart) : bool|MimePart
Used for alternative mime types that have a multipart/mixed or multipart/related child containing a content part of $mimeType, where the whole mixed/related part should be removed.
Parameters
- $mimeType : string
-
the content-type to find below $alternativePart
- $alternativePart : MimePart
-
The multipart/alternative part to look under
Return values
bool|MimePart —false if a part is not found
getHandleForStringOrHandle()
Returns an open resource handle for the passed string or resource handle.
private
getHandleForStringOrHandle(resource|string $stringOrHandle) : resource
For a string, creates a php://temp stream and returns it.
Parameters
- $stringOrHandle : resource|string
Return values
resource —getUniqueBoundary()
Creates and returns a unique boundary.
private
getUniqueBoundary(string $mimeType) : string
Parameters
- $mimeType : string
-
first 3 characters of a multipart type are used, e.g. REL for relative or ALT for alternative
Return values
string —makeSpaceForMultipartSignedMessage()
This function makes space by moving the main message part down one level.
private
makeSpaceForMultipartSignedMessage() : mixed
The content-type, content-disposition and content-transfer-encoding headers are copied from this message to the newly created part, the resource handle is moved and detached, any attachments and content parts with parents set to this message get their parents set to the newly created part.
Return values
mixed —moveAllPartsAsAttachmentsExcept()
Moves all parts under $from into this message except those with a content-type equal to $exceptMimeType. If the message is not a multipart/mixed message, it is set to multipart/mixed first.
private
moveAllPartsAsAttachmentsExcept(MimePart $from, string $exceptMimeType) : mixed
Parameters
- $from : MimePart
- $exceptMimeType : string
Return values
mixed —movePartContentAndChildrenToPart()
Copies type headers (Content-Type, Content-Disposition, Content-Transfer-Encoding) from the $from MimePart to $to. Attaches the content resource handle of $from to $to, and loops over child parts, removing them from $from and adding them to $to.
private
movePartContentAndChildrenToPart(MimePart $from, MimePart $to) : mixed
Parameters
Return values
mixed —overwrite8bitContentEncoding()
Loops over parts of this message and sets the content-transfer-encoding header to quoted-printable for text/* mime parts, and to base64 otherwise for parts that are '8bit' encoded.
private
overwrite8bitContentEncoding() : mixed
Used for multipart/signed messages which doesn't support 8bit transfer encodings.
Return values
mixed —removeAllContentPartsFromAlternative()
Removes all parts of $mimeType from $alternativePart.
private
removeAllContentPartsFromAlternative(string $mimeType, MimePart $alternativePart, bool $keepOtherContent) : bool
If $alternativePart contains a multipart/mixed or multipart/relative part with other parts of different content-types, the multipart part is removed, and parts of different content-types can optionally be moved to the main message part.
Parameters
- $mimeType : string
- $alternativePart : MimePart
- $keepOtherContent : bool
Return values
bool —replacePart()
Replaces the $part MimePart with $replacement.
private
replacePart(MimePart $part, MimePart $replacement) : mixed
Essentially removes $part from its parent, and adds $replacement in its same position. If $part is this Message, its type headers are moved from this message to $replacement, the content resource is moved, and children are assigned to $replacement.
Parameters
Return values
mixed —setMessageAsAlternative()
Sets this message to be a multipart/alternative message, making space for a second content part.
private
setMessageAsAlternative() : mixed
Creates a content part and assigns the content stream from the message to that newly created part.
Return values
mixed —setMessageAsMixed()
Creates a new part out of the current contentPart and sets the message's type to be multipart/mixed.
private
setMessageAsMixed() : mixed
Return values
mixed —setMimeHeaderBoundaryOnPart()
Creates a unique mime boundary and assigns it to the passed part's Content-Type header with the passed mime type.
private
setMimeHeaderBoundaryOnPart(MimePart $part, string $mimeType) : mixed
Parameters
- $part : MimePart
- $mimeType : string