Copied!

An interface representing an email message.

Defines an interface to retrieve content, attachments and other parts of an
email message.

AbstractInterface
Methods
public abstract ZBateson\MailMimeParser\Message\IMessagePart::__toString() : string
 

Returns the message/part as a string, containing its headers, content and
children.

Convenience method for calling getContents() on
{@see \IMessagePart::getStream()}.

  • see \IMessagePart::getStream()to get a Psr7 StreamInterface instead of a
    string.
  • see \IMessagePart::getResourceHandle()to get a resource handle.
  • see \IMessage::save()to write the part to a file, resource handle or
    Psr7 stream.
  • return phpDocumentor\Reflection\Types\String_
public abstract addAttachmentPart( $resource, $mimeType, $filename = NULL, $disposition = 'attachment', $encoding = 'base64')
 

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

Note that $disposition must be one of 'inline' or 'attachment', and will
default to 'attachment' if a different value is passed.

public abstract addAttachmentPartFromFile( $filePath, $mimeType, $filename = NULL, $disposition = 'attachment', $encoding = 'base64')
 

Adds an attachment part using the passed file.

Essentially creates a psr7 stream and calls
{@see \IMessage::addAttachmentPart}.

Note that $disposition must be one of 'inline' or 'attachment', and will
default to 'attachment' if a different value is passed.

public abstract ZBateson\MailMimeParser\Message\IMultiPart::addChild(ZBateson\MailMimeParser\Message\IMessagePart $part, $position = NULL)
 

Registers the passed part as a child of the current part.

If the $position parameter is non-null, adds the part at the passed
position index, otherwise adds it as the last child.

public abstract ZBateson\MailMimeParser\Message\IMimePart::addRawHeader( $name, $value)
 

Adds a header with the given $name and $value.

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 {@see \IMimePart::setRawHeader()} should be
called instead.

A new {@see \ZBateson\MailMimeParser\Header\IHeader} 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.

  • see \IMimePart::setRawHeader()Sets a header, potentially overwriting one
    if it already exists.
  • see \IMimePart::removeHeader()Removes all headers on this part with the
    passed name
  • see \IMimePart::removeSingleHeader()Removes a single header if more than
    one with the passed name exists.
  • param phpDocumentor\Reflection\Types\String_ $name The name of the header
  • param phpDocumentor\Reflection\Types\String_ $value The raw value of the header.
public abstract SplSubject::attach(SplObserver $observer)
public abstract ZBateson\MailMimeParser\Message\IMessagePart::attachContentStream(Psr\Http\Message\StreamInterface $stream, $streamCharset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET)
 

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 abstract SplSubject::detach(SplObserver $observer)
public abstract ZBateson\MailMimeParser\Message\IMessagePart::detachContentStream()
 

Detaches the content stream.

  • see \IMessagePart::getContentStream()to get the content stream.
  • see \IMessagePart::attachContentStream()to attach a content stream.
public abstract getAllAttachmentParts()
 

Returns all attachment parts.

The method returns all parts other than the main content part for a
non-mime message, and all parts under a mime message except:

  • text/plain and text/html parts with a Content-Disposition not set to
    'attachment'
  • all multipart/* parts
  • any signature part
public abstract ZBateson\MailMimeParser\Message\IMimePart::getAllHeaders()
 

Returns an array of all headers in this part.

  • see \IMimePart::getHeader()to retrieve a single header object.
  • see \IMimePart::getHeaderValue()to get the string value portion of a
    specific header only.
  • see \IMimePart::getHeaderParameter()to get the string value portion of a
    specific header's parameter only.
  • see \IMimePart::getAllHeadersByName()to retrieve an array of all headers
    with a certain name.
  • see \IMimePart::getRawHeaders()to retrieve a two-dimensional string[][]
    array of raw headers in this part.
  • see \IMimePart::getRawHeaderIterator()to retrieve an iterator traversing
    a two-dimensional string[] array of raw headers.
  • return phpDocumentor\Reflection\Types\Array_ an array of header
    objects
public abstract ZBateson\MailMimeParser\Message\IMimePart::getAllHeadersByName( $name)
 

Returns an array of headers that match the passed name.

  • see \IMimePart::getHeader()to retrieve a single header object.
  • see \IMimePart::getHeaderValue()to get the string value portion of a
    specific header only.
  • see \IMimePart::getHeaderParameter()to get the string value portion of a
    specific header's parameter only.
  • see \IMimePart::getAllHeaders()to retrieve an array of all header
    objects for this part.
  • see \IMimePart::getRawHeaders()to retrieve a two-dimensional string[][]
    array of raw headers in this part.
  • see \IMimePart::getRawHeaderIterator()to retrieve an iterator traversing
    a two-dimensional string[] array of raw headers.
  • param phpDocumentor\Reflection\Types\String_ $name
  • return phpDocumentor\Reflection\Types\Array_ an array of header
    objects
public abstract ZBateson\MailMimeParser\Message\IMultiPart::getAllParts( $fnFilter = NULL)
 

Returns the current part, all child parts, and child parts of all
children optionally filtering them with the provided PartFilter.

Note that the first part returned is the current part itself. This is
often desirable for queries with a passed filter, e.g. looking for an
IMessagePart with a specific Content-Type that may be satisfied by the
current part.

The passed callable must accept an {@see \IMessagePart} as an argument,
and return true if it should be accepted, or false to filter the part
out. Some default filters are provided by static functions returning
callables in {@see \PartFilter}.

  • see \IMultiPart::getPart()to find a part at a specific 0-based index
    with an optional filter.
  • see \IMultiPart::getPartCount()to get the number of parts with an
    optional filter.
  • see \IMultiPart::getChildParts()to get an array of all direct children
    of the current part.
  • param phpDocumentor\Reflection\Types\Callable_ $fnFilter Optional function accepting an IMessagePart and
    returning true if the part should be included.
  • return phpDocumentor\Reflection\Types\Array_ An array of matching parts.
public abstract ZBateson\MailMimeParser\Message\IMultiPart::getAllPartsByMimeType( $mimeType)
 

Returns an array of all parts that have a content type matching the
passed mime type.

Creates a filter that looks at the return value of
{@see \IMessagePart::getContentType()} for all parts (including the
current part), returning an array of matching parts.

public abstract getAttachmentCount()
 

Returns the number of attachments available.

public abstract getAttachmentPart( $index)
 

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

The method returns all parts other than the main content part for a
non-mime message, and all parts under a mime message except:

  • text/plain and text/html parts with a Content-Disposition not set to
    'attachment'
  • all multipart/* parts
  • any signature part
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getBinaryContentResourceHandle()
 

Returns a resource handle for the content's raw data stream, or null if
the part doesn't have a content stream.

The method wraps a call to {@see \IMessagePart::getBinaryContentStream()}
and returns a resource handle for the returned Stream.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::getBinaryContentStream()
 

Returns the raw data stream for the current part, if it exists, or null
if there's no content associated with the stream.

This is basically the same as calling
{@see \IMessagePart::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).
  • see \IMessagePart::getContentStream()to get the content stream with
    charset conversions applied.
  • see \IMessagePart::getBinaryContentResourceHandle()to get a resource
    handle instead.
  • see \IMessagePart::saveContent()to save the binary contents to file.
  • return phpDocumentor\Reflection\Types\Compound the stream
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getCharset()
 

Returns the charset of the content, or null if not applicable/defined.

public abstract ZBateson\MailMimeParser\Message\IMultiPart::getChild( $index, $fnFilter = NULL)
 

Returns the direct child at the given 0-based index and optional filter,
or null if none exist or do not match.

The passed callable must accept an {@see \IMessagePart} as an argument,
and return true if it should be accepted, or false to filter the part
out. Some default filters are provided by static functions returning
callables in {@see \PartFilter}.

  • see \IMultiPart::getChildParts()to get an array of all direct children
    of the current part.
  • see \IMultiPart::getChildCount()to get a count of direct children of
    this part.
  • see \IMultiPart::getChildIterator()to get an iterator of children of
    this part.
  • see \IMultiPart::getPart()to find a part at a specific 0-based index
    with an optional filter.
  • param phpDocumentor\Reflection\Types\Integer $index 0-based index
  • param phpDocumentor\Reflection\Types\Callable_ $fnFilter Optional function accepting an IMessagePart and
    returning true if the part should be included.
  • return phpDocumentor\Reflection\Types\Compound The matching direct child part or null if not
    found.
public abstract ZBateson\MailMimeParser\Message\IMultiPart::getChildCount( $fnFilter = NULL)
 

Returns the number of direct children under this part (optionally
counting only filtered items if a callable filter is passed).

The passed callable must accept an {@see \IMessagePart} as an argument,
and return true if it should be accepted, or false to filter the part
out. Some default filters are provided by static functions returning
callables in {@see \PartFilter}.

  • see \IMultiPart::getChild()to get a direct child of the current part.
  • see \IMultiPart::getChildParts()to get an array of all direct children
    of the current part.
  • see \IMultiPart::getChildIterator()to get an iterator of children of
    this part.
  • see \IMultiPart::getPartCount()to get the number of parts with an
    optional filter.
  • param phpDocumentor\Reflection\Types\Callable_ $fnFilter Optional function accepting an IMessagePart and
    returning true if the part should be included.
  • return phpDocumentor\Reflection\Types\Integer The number of children, or number of children matching the
    the passed filtering callable.
public abstract ZBateson\MailMimeParser\Message\IMultiPart::getChildIterator()
 

Returns a \RecursiveIterator of child parts.

The {@see https://www.php.net/manual/en/class.recursiveiterator.php \RecursiveIterator}
allows iterating over direct children, or using
a {@see https://www.php.net/manual/en/class.recursiveiteratoriterator.php \RecursiveIteratorIterator}
to iterate over direct children, and all their children.

  • see https://www.php.net/manual/en/class.recursiveiterator.phpRecursiveIterator
  • see https://www.php.net/manual/en/class.recursiveiteratoriterator.phpRecursiveIteratorIterator
  • see \IMultiPart::getChild()to get a direct child of the current part.
  • see \IMultiPart::getChildParts()to get an array of all direct children
    of the current part.
  • see \IMultiPart::getChildCount()to get a count of direct children of
    this part.
  • see \IMultiPart::getAllParts()to get an array of all parts with an
    optional filter.
  • return phpDocumentor\Reflection\Types\Object_
public abstract ZBateson\MailMimeParser\Message\IMultiPart::getChildParts( $fnFilter = NULL)
 

Returns an array of all direct child parts, optionally filtering them
with a passed callable.

The passed callable must accept an {@see \IMessagePart} as an argument,
and return true if it should be accepted, or false to filter the part
out. Some default filters are provided by static functions returning
callables in {@see \PartFilter}.

  • see \IMultiPart::getChild()to get a direct child of the current part.
  • see \IMultiPart::getChildCount()to get a count of direct children of
    this part.
  • see \IMultiPart::getChildIterator()to get an iterator of children of
    this part.
  • see \IMultiPart::getAllParts()to get an array of all parts with an
    optional filter.
  • param phpDocumentor\Reflection\Types\Callable_ $fnFilter Optional function accepting an IMessagePart and
    returning true if the part should be included.
  • return phpDocumentor\Reflection\Types\Array_ An array of matching child parts.
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContent( $charset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET)
 

Shortcut to reading stream content and assigning it to a string. Returns
null if the part doesn't have a content stream.

The returned string is encoded to the passed $charset character encoding.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContentDisposition( $default = NULL)
 

Returns the content's disposition, or returns the value of $default if
not defined.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContentId()
 

Returns the Content ID of the part, or null if not defined.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContentStream( $charset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET)
 

Returns the StreamInterface for the part's content or null if the part
doesn't have a content section.

To get a stream without charset conversion if you know the part's content
contains a binary stream, call {@see \self::getBinaryContentStream()}
instead.

The library automatically handles decoding and charset conversion (to the
target passed $charset) based on the part's transfer encoding as returned
by {@see \IMessagePart::getContentTransferEncoding()} and the part's
charset as returned by {@see \IMessagePart::getCharset()}. The returned
stream is ready to be read from directly.

Note that the returned Stream is a shared object. If called multiple
times with the same $charset, and the value of the part's
Content-Transfer-Encoding header has not 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.

  • see \IMessagePart::getBinaryContentStream()to get the content stream
    without any charset conversions.
  • see \IMessagePart::saveContent()to save the binary contents to file.
  • see \IMessagePart::setCharsetOverride()to override the charset of the
    content and ignore the charset returned from calling
    IMessagePart::getCharset() when reading.
  • param phpDocumentor\Reflection\Types\String_ $charset Optional charset for the returned stream.
  • return phpDocumentor\Reflection\Types\Compound the stream
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContentTransferEncoding( $default = NULL)
 

Returns the content transfer encoding used to encode the content on this
part, or the value of $default if not defined.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContentType( $default = 'text/plain')
 

Returns the mime type of the content, or $default if one is not set.

public abstract ZBateson\MailMimeParser\Message\IMultiPart::getCountOfPartsByMimeType( $mimeType)
 

Returns the number of parts that have content types matching the passed
mime type.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::getFilename()
 

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

public abstract ZBateson\MailMimeParser\Message\IMimePart::getHeader( $name, $offset = 0)
 

Returns the IHeader object for the header with the given $name.

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, and the '-' character is

If a header with the given $name and $offset doesn't exist, null is
returned.

  • see \IMimePart::getHeaderValue()to get the string value portion of a
    specific header only.
  • see \IMimePart::getHeaderParameter()to get the string value portion of a
    specific header's parameter only.
  • see \IMimePart::getAllHeaders()to retrieve an array of all header
    objects for this part.
  • see \IMimePart::getAllHeadersByName()to retrieve an array of all headers
    with a certain name.
  • see \IMimePart::getRawHeaders()to retrieve a two-dimensional string[][]
    array of raw headers in this part.
  • see \IMimePart::getRawHeaderIterator()to retrieve an iterator traversing
    a two-dimensional string[] array of raw headers.
  • param phpDocumentor\Reflection\Types\String_ $name The name of the header to retrieve.
  • param phpDocumentor\Reflection\Types\Integer $offset Optional offset if there are multiple headers with the
    given name.
  • return phpDocumentor\Reflection\Types\Compound the header object
public abstract ZBateson\MailMimeParser\Message\IMimePart::getHeaderParameter( $header, $param, $defaultValue = NULL)
 

Returns the value of the parameter named $param on a header with the
passed $header name, or null if the parameter doesn't exist and a
$defaultValue isn't passed.

Only headers of type
{@see \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.

  • see \IMimePart::getHeader()to retrieve a single header object.
  • see \IMimePart::getHeaderValue()to get the string value portion of a
    specific header only.
  • see \IMimePart::getAllHeaders()to retrieve an array of all header
    objects for this part.
  • see \IMimePart::getAllHeadersByName()to retrieve an array of all headers
    with a certain name.
  • see \IMimePart::getRawHeaders()to retrieve the array the returned
    iterator iterates over.
  • see \IMimePart::getRawHeaderIterator()to retrieve an iterator instead of
    the returned two-dimensional array
  • param phpDocumentor\Reflection\Types\String_ $header The name of the header.
  • param phpDocumentor\Reflection\Types\String_ $param The name of the parameter.
  • param phpDocumentor\Reflection\Types\String_ $defaultValue Optional default value to return if the
    parameter doesn't exist.
  • return phpDocumentor\Reflection\Types\Compound The value of the parameter.
public abstract ZBateson\MailMimeParser\Message\IMimePart::getHeaderValue( $name, $defaultValue = NULL)
 

Returns the string value for the header with the given $name, or null if
the header doesn't exist and no alternative $defaultValue is passed.

Note that mime headers aren't case sensitive.

  • see \IMimePart::getHeader()to retrieve a single header object.
  • see \IMimePart::getHeaderParameter()to get the string value portion of a
    specific header's parameter only.
  • see \IMimePart::getAllHeaders()to retrieve an array of all header
    objects for this part.
  • see \IMimePart::getAllHeadersByName()to retrieve an array of all headers
    with a certain name.
  • see \IMimePart::getRawHeaders()to retrieve the array the returned
    iterator iterates over.
  • see \IMimePart::getRawHeaderIterator()to retrieve an iterator instead of
    the returned two-dimensional array
  • param phpDocumentor\Reflection\Types\String_ $name The name of the header
  • param phpDocumentor\Reflection\Types\String_ $defaultValue Optional default value to return if the
    header doesn't exist on this part.
  • return phpDocumentor\Reflection\Types\Compound the value of the header
public abstract getHtmlContent( $index = 0, $charset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET)
 

Returns the content of the inline text/html part as a string.

If the message contains more than one text/html 'inline' part, the
default behavior is to return the first part. The content for additional
parts can be returned by passing a 0-based index.

If a part at the passed index doesn't exist, null is returned.

public abstract getHtmlPart( $index = 0)
 

Returns the inline text/html IMessagePart for a message.

If the message contains more than one text/html 'inline' part, the
default behavior is to return the first part. Additional parts can be
returned by passing a 0-based index.

If there are no inline text/plain parts in this message, null is
returned.

  • see \IMessage::getHtmlStream()to get the html content stream directly.
  • see \IMessage::getHtmlStream()to get the html content in a string.
  • see \IMessage::getTextPart()to get the text part(s).
  • see \IMessage::getTextPartCount()to get a count of text parts.
  • see \IMessage::getHtmlPartCount()to get a count of html parts.
  • param phpDocumentor\Reflection\Types\Integer $index Optional index of part to return.
  • return phpDocumentor\Reflection\Types\Compound
public abstract getHtmlPartCount()
 

Returns the number of inline text/html parts this message contains.

  • see \IMessage::getTextPart()to get the text part(s).
  • see \IMessage::getTextPartCount()to get a count of text parts.
  • see \IMessage::getHtmlPart()to get the HTML part(s).
  • return phpDocumentor\Reflection\Types\Integer
public abstract getHtmlStream( $index = 0, $charset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET)
 

Returns a Psr7 Stream for the 'inline' text/html content.

If the message contains more than one text/html 'inline' part, the
default behavior is to return the first part. The streams for additional
parts can be returned by passing a 0-based index.

If a part at the passed index doesn't exist, null is returned.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::getParent()
 

Returns this part's parent.

public abstract ZBateson\MailMimeParser\Message\IMultiPart::getPart( $index, $fnFilter = NULL)
 

Returns the part at the given 0-based index for this part (part 0) and
all parts under it, or null if not found with the passed filter function.

Note that the first part returned is the current part itself. This is
usually desirable for queries with a passed filter, e.g. looking for an
part with a specific Content-Type that may be satisfied by the current
part.

The passed callable must accept an {@see \IMessagePart} as an argument,
and return true if it should be accepted, or false to filter the part
out. Some default filters are provided by static functions returning
callables in {@see \PartFilter}.

  • see \IMultiPart::getAllParts()to get an array of all parts with an
    optional filter.
  • see \IMultiPart::getPartCount()to get the number of parts with an
    optional filter.
  • see \IMultiPart::getChild()to get a direct child of the current part.
  • param phpDocumentor\Reflection\Types\Integer $index The 0-based index (0 being this part if $fnFilter is
    null or this part is satisfied by the filter).
  • param phpDocumentor\Reflection\Types\Callable_ $fnFilter Optional function accepting an IMessagePart and
    returning true if the part should be included.
  • return phpDocumentor\Reflection\Types\Compound A matching part, or null if not found.
public abstract ZBateson\MailMimeParser\Message\IMultiPart::getPartByContentId( $contentId)
 

Returns a part that has the given Content ID, or null if not found.

Calls {@see \IMessagePart::getContentId()} to find a matching part.

public abstract ZBateson\MailMimeParser\Message\IMultiPart::getPartByMimeType( $mimeType, $index = 0)
 

Returns the part that has a content type matching the passed mime type at
the given index, or null if there are no matching parts.

Creates a filter that looks at the return value of
{@see \IMessagePart::getContentType()} for all parts (including the
current part) and returns a matching one at the given 0-based index.

public abstract ZBateson\MailMimeParser\Message\IMultiPart::getPartCount( $fnFilter = NULL)
 

Returns the total number of parts in this and all children.

Note that the current part is considered, so the minimum getPartCount is
1 without a filter.

The passed callable must accept an {@see \IMessagePart} as an argument,
and return true if it should be accepted, or false to filter the part
out. Some default filters are provided by static functions returning
callables in {@see \PartFilter}.

  • see \IMultiPart::getPart()to find a part at a specific 0-based index
    with an optional filter.
  • see \IMultiPart::getAllParts()to get an array of all parts with an
    optional filter.
  • see \IMultiPart::getChildCount()to get a count of direct children of
    this part.
  • param phpDocumentor\Reflection\Types\Callable_ $fnFilter Optional function accepting an IMessagePart and
    returning true if the part should be included.
  • return phpDocumentor\Reflection\Types\Integer The number of matching parts.
public abstract ZBateson\MailMimeParser\Message\IMimePart::getRawHeaderIterator()
 

Returns an iterator to all headers in this part. Each returned element
is an array with its first element set to the header's name, and the
second to its raw value:

[ 'Header-Name', 'Header Value' ]

  • see \IMimePart::getHeader()to retrieve a single header object.
  • see \IMimePart::getHeaderValue()to get the string value portion of a
    specific header only.
  • see \IMimePart::getHeaderParameter()to get the string value portion of a
    specific header's parameter only.
  • see \IMimePart::getAllHeaders()to retrieve an array of all header
    objects for this part.
  • see \IMimePart::getAllHeadersByName()to retrieve an array of all headers
    with a certain name.
  • see \IMimePart::getRawHeaders()to retrieve the array the returned
    iterator iterates over.
  • return phpDocumentor\Reflection\Types\Object_ an iterator for raw headers
public abstract ZBateson\MailMimeParser\Message\IMimePart::getRawHeaders()
 

Returns a two dimensional string array of all headers for the mime part
with the first element holding the name, and the second its raw string
value:

[ [ '1st-Header-Name', 'Header Value' ], [ '2nd-Header-Name', 'Header Value' ] ]

  • see \IMimePart::getHeader()to retrieve a single header object.
  • see \IMimePart::getHeaderValue()to get the string value portion of a
    specific header only.
  • see \IMimePart::getHeaderParameter()to get the string value portion of a
    specific header's parameter only.
  • see \IMimePart::getAllHeaders()to retrieve an array of all header
    objects for this part.
  • see \IMimePart::getAllHeadersByName()to retrieve an array of all headers
    with a certain name.
  • see \IMimePart::getRawHeaderIterator()to retrieve an iterator instead of
    the returned two-dimensional array
  • return phpDocumentor\Reflection\Types\Array_ an array of raw headers
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getResourceHandle()
 

Returns a resource handle for the string representation of this part,
containing its headers, content and children. For an IMessage, this
would be the entire RFC822 (or greater) email.

If the part has not been modified and represents a parsed part, the
original stream should be returned. Otherwise a stream representation of
the part including its modifications should be returned. This insures
that an unmodified, signed message could be passed on that way even after
parsing and reading.

The returned stream is not guaranteed to be RFC822 (or greater) compliant
for the following reasons:

  • The original email or part, if not modified, is returned as-is and may
    not be compliant.
  • Although certain parts may have been modified, an original unmodified
    header from the original email or part may not be compliant.
  • A user may set headers in a non-compliant format.
  • see \IMessagePart::getStream()to get a Psr7 StreamInterface instead of a
    resource handle.
  • see \IMessagePart::__toString()to write the part to a string and return
    it.
  • see \IMessage::save()to write the part to a file, resource handle or
    Psr7 stream.
  • return phpDocumentor\Reflection\Types\Resource_ the resource handle containing the part.
public abstract getSignaturePart()
 

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

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).

public abstract getSignedMessageAsString()
 

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

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

public abstract 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.

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, and before calculating a signature, LFs not preceded
by CR should be replaced with CRLFs.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::getStream()
 

Returns a Psr7 StreamInterface for the string representation of this
part, containing its headers, content and children.

If the part has not been modified and represents a parsed part, the
original stream should be returned. Otherwise a stream representation of
the part including its modifications should be returned. This insures
that an unmodified, signed message could be passed on that way even after
parsing and reading.

The returned stream is not guaranteed to be RFC822 (or greater) compliant
for the following reasons:

  • The original email or part, if not modified, is returned as-is and may
    not be compliant.
  • Although certain parts may have been modified, an original unmodified
    header from the original email or part may not be compliant.
  • A user may set headers in a non-compliant format.
  • see \IMessagePart::getResourceHandle()to get a resource handle.
  • see \IMessagePart::__toString()to write the part to a string and return
    it.
  • see \IMessage::save()to write the part to a file, resource handle or
    Psr7 stream.
  • return phpDocumentor\Reflection\Types\Object_ the stream containing the part.
public abstract getTextContent( $index = 0, $charset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET)
 

Returns the content of the inline text/plain part as a string.

If the message contains more than one text/plain 'inline' part, the
default behavior is to return the first part. The content for additional
parts can be returned by passing a 0-based index.

If a part at the passed index doesn't exist, null is returned.

public abstract getTextPart( $index = 0)
 

Returns the inline text/plain IMessagePart for a message.

If the message contains more than one text/plain 'inline' part, the
default behavior is to return the first part. Additional parts can be
returned by passing a 0-based index.

If there are no inline text/plain parts in this message, null is
returned.

  • see \IMessage::getTextPartCount()to get a count of text parts.
  • see \IMessage::getTextStream()to get the text content stream directly.
  • see \IMessage::getTextContent()to get the text content in a string.
  • see \IMessage::getHtmlPart()to get the HTML part(s).
  • see \IMessage::getHtmlPartCount()to get a count of html parts.
  • param phpDocumentor\Reflection\Types\Integer $index Optional index of part to return.
  • return phpDocumentor\Reflection\Types\Compound
public abstract getTextPartCount()
 

Returns the number of inline text/plain parts this message contains.

  • see \IMessage::getTextPart()to get the text part(s).
  • see \IMessage::getHtmlPart()to get the HTML part(s).
  • see \IMessage::getHtmlPartCount()to get a count of html parts.
  • return phpDocumentor\Reflection\Types\Integer
public abstract getTextStream( $index = 0, $charset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET)
 

Returns a Psr7 Stream for the 'inline' text/plain content.

If the message contains more than one text/plain 'inline' part, the
default behavior is to return the first part. The streams for additional
parts can be returned by passing a 0-based index.

If a part at the passed index doesn't exist, null is returned.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::hasContent()
 

Returns true if the part contains a 'body' (content).

public abstract ZBateson\MailMimeParser\Message\IMessagePart::isMime()
 

Returns true if the current part is a mime part.

public abstract ZBateson\MailMimeParser\Message\IMimePart::isMultiPart()
 

Returns true if this part's content type matches multipart/*

public abstract ZBateson\MailMimeParser\Message\IMimePart::isSignaturePart()
 

Returns true if this part is the 'signature' part of a signed message.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::isTextPart()
 

Returns true if the content of this part is plain text.

public abstract SplSubject::notify()
public abstract removeAllHtmlParts( $moveRelatedPartsBelowMessage = true)
 

Removes all text/html inline parts in this message.

If the message contains a multipart/alternative part, the html parts are
removed from below the alternative part only. If there is only one
remaining part after that, it is moved up, replacing the
multipart/alternative part.

If the multipart/alternative part further contains a multipart/related
(or mixed) part which holds an inline html part, only parts from that
child multipart are removed, and if the passed
$moveRelatedPartsBelowMessage is true, any non-html parts are moved to be
below the message directly (changing the message into a multipart/mixed
message if need be).

For more control, call
{@see \ZBateson\MailMimeParser\Message\IMessagePart::removePart()} with
parts you wish to remove.

public abstract ZBateson\MailMimeParser\Message\IMultiPart::removeAllParts( $fnFilter = NULL)
 

Removes all parts below the current part. If a callable filter is
passed, removes only those matching the passed filter. The number of
removed parts is returned.

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.

public abstract removeAllTextParts( $moveRelatedPartsBelowMessage = true)
 

Removes all text/plain inline parts in this message.

If the message contains a multipart/alternative part, the text parts are
removed from below the alternative part only. If there is only one
remaining part after that, it is moved up, replacing the
multipart/alternative part.

If the multipart/alternative part further contains a multipart/related
(or mixed) part which holds an inline text part, only parts from that
child multipart are removed, and if the passed
$moveRelatedPartsBelowMessage is true, any non-text parts are moved to be
below the message directly (changing the message into a multipart/mixed
message if need be).

For more control, call
{@see \ZBateson\MailMimeParser\Message\IMessagePart::removePart()} with
parts you wish to remove.

public abstract removeAttachmentPart( $index)
 

Removes the attachment at the given index.

Attachments are considered to be all parts other than the main content
part for a non-mime message, and all parts under a mime message except:

  • text/plain and text/html parts with a Content-Disposition not set to
    'attachment'
  • all multipart/* parts
  • any signature part
public abstract ZBateson\MailMimeParser\Message\IMimePart::removeHeader( $name)
 

Removes all headers from this part with the passed name.

  • see \IMimePart::addRawHeader()Adds a header to the part regardless of
    whether or not a header with that name already exists.
  • see \IMimePart::setRawHeader()Sets a header, potentially overwriting one
    if it already exists.
  • see \IMimePart::removeSingleHeader()Removes a single header if more than
    one with the passed name exists.
  • param phpDocumentor\Reflection\Types\String_ $name The name of the header(s) to remove.
public abstract removeHtmlPart( $index = 0)
 

Removes the text/html part of the message at the passed index if one
exists (defaults to first part if an index isn't passed).

Returns true if a part exists at the passed index and has been removed.

public abstract ZBateson\MailMimeParser\Message\IMultiPart::removePart(ZBateson\MailMimeParser\Message\IMessagePart $part)
 

Removes the child part from this part and returns its previous position
or null if it wasn't found.

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).

This also means that parts from unrelated parts/messages could be removed
by a call to removePart -- it will always remove the part from its parent
if it has one, essentially calling


public abstract ZBateson\MailMimeParser\Message\IMimePart::removeSingleHeader( $name, $offset = 0)
 

Removes a single header with the passed name (in cases where more than
one may exist, and others should be preserved).

  • see \IMimePart::addRawHeader()Adds a header to the part regardless of
    whether or not a header with that name already exists.
  • see \IMimePart::setRawHeader()Sets a header, potentially overwriting one
    if it already exists.
  • see \IMimePart::removeHeader()Removes all headers on this part with the
    passed name
  • param phpDocumentor\Reflection\Types\String_ $name The name of the header to remove
  • param phpDocumentor\Reflection\Types\Integer $offset Optional offset of the header to remove (defaults to
    0 -- the first header).
public abstract removeTextPart( $index = 0)
 

Removes the text/plain part of the message at the passed index if one
exists (defaults to first part if an index isn't passed).

Returns true if a part exists at the passed index and has been removed.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::save( $filenameResourceOrStream, $filemode = 'w+')
 

Writes a string representation of this part, including its headers,
content and children to the passed file, resource, or stream.

If the part has not been modified and represents a parsed part, the
original stream should be written to the file. Otherwise a stream
representation of the part including its modifications should be written.
This insures that an unmodified, signed message could be passed on this
way even after parsing and reading.

The written stream is not guaranteed to be RFC822 (or greater) compliant
for the following reasons:

  • The original email or part, if not modified, is returned as-is and may
    not be compliant.
  • Although certain parts may have been modified, an original unmodified
    header from the original email or part may not be compliant.
  • A user may set headers in a non-compliant format.

If the passed $filenameResourceOrStream is a string, it's assumed to be a
filename to write to.

When passing a resource or Psr7 Stream, the resource is not closed, nor
rewound after being written to.

  • see \IMessagePart::getResourceHandle()to get a resource handle.
  • see \IMessagePart::__toString()to get the part in a string.
  • see \IMessage::save()to write the part to a file, resource handle or
    Psr7 stream.
  • param phpDocumentor\Reflection\Types\Compound $filenameResourceOrStream the
    file, resource, or stream to write to.
  • param phpDocumentor\Reflection\Types\String_ $filemode Optional filemode to open a file in (if
    $filenameResourceOrStream is a string)
public abstract ZBateson\MailMimeParser\Message\IMessagePart::saveContent( $filenameResourceOrStream)
 

Saves the binary content of the stream to the passed file, resource or
stream.

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). {@see \IMessagePart::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.

  • see \IMessagePart::getContentStream()to get the content stream with
    charset conversions applied.
  • see \IMessagePart::getBinaryContentStream()to get the content as a
    binary stream.
  • see \IMessagePart::getBinaryContentResourceHandle()to get the content as
    a resource handle.
  • param phpDocumentor\Reflection\Types\Compound $filenameResourceOrStream
public abstract setAsMultipartSigned( $micalg, $protocol)
 

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.

After calling setAsMultipartSigned, call getSignedMessageAsString to
get the normalized string content to be used for calculated the message's
hash.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::setCharsetOverride( $charsetOverride, $onlyIfNoCharset = false)
 

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.

If set, the returned value from {@see \IMessagePart::getCharset()} must be
ignored during subsequent read operations and streams created out of this
part's content.

Note that setting an override on an
{@see \ZBateson\MailMimeParser\IMessage} and calling getTextStream,
getTextContent, getHtmlStream or getHtmlContent will not be applied to
those sub-parts, unless the text/html part is the IMessage itself.
Instead, {@see \ZBateson\MailMimeParser\IMessage::getTextPart()} should
be called, and setCharsetOverride called on the returned IMessagePart.

public abstract ZBateson\MailMimeParser\Message\IMessagePart::setContent( $resource, $resourceCharset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET)
 

Sets the content of the part to the passed string, resource, or stream.

public abstract setHtmlPart( $resource, $contentTypeCharset = 'UTF-8')
 

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

The optional $contentTypeCharset parameter is the charset for the
text/html part's Content-Type, not the charset of the passed $resource.
$resource must be encoded in UTF-8 regardless of the target charset.

public abstract ZBateson\MailMimeParser\Message\IMimePart::setRawHeader( $name, $value, $offset = 0)
 

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 only. 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.

$part = $myMimePart;
$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 {@see \ZBateson\MailMimeParser\Header\IHeader} 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.

  • see \IMimePart::addRawHeader()Adds a header to the part regardless of
    whether or not a header with that name already exists.
  • see \IMimePart::removeHeader()Removes all headers on this part with the
    passed name
  • see \IMimePart::removeSingleHeader()Removes a single header if more than
    one with the passed name exists.
  • param phpDocumentor\Reflection\Types\String_ $name The name of the new header, e.g. 'Content-Type'.
  • param phpDocumentor\Reflection\Types\String_ $value The raw value of the new header.
  • param phpDocumentor\Reflection\Types\Integer $offset An optional offset, defaulting to '0' and therefore
    overriding the first header of the given $name if one exists.
public abstract setSignature( $body)
 

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

public abstract setTextPart( $resource, $contentTypeCharset = 'UTF-8')
 

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

The optional $contentTypeCharset parameter is the charset for the
text/plain part's Content-Type, not the charset of the passed $resource.
$resource must be encoded in UTF-8 regardless of the target charset.

© 2023 Bruce Wells
Search Namespaces \ Classes
Configuration