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.
|
public abstract addChild(ZBateson\MailMimeParser\Message\MessagePart $part, ?int $position = NULL) : static 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. - param \MessagePart $part The part to add.
- param int $position Optional insertion position 0-based index.
|
public abstract ZBateson\MailMimeParser\IErrorBag::addError(string $message, string $psrLogLevel, ?Throwable $exception = NULL) : static Creates and adds an Error object to this ErrorBag. |
public abstract SplSubject::attach(SplObserver $observer) |
public abstract ZBateson\MailMimeParser\Message\IMessagePart::attachContentStream(Psr\Http\Message\StreamInterface $stream, string $streamCharset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET) : static 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. - see \IMessagePart::setContent()to pass a string as the content.
- see \IMessagePart::getContentStream()to get the content stream.
- see \IMessagePart::detachContentStream()to detach the content stream.
- param \StreamInterface $stream the content
- param string $streamCharset the charset of $stream
|
public abstract SplSubject::detach(SplObserver $observer) |
public abstract ZBateson\MailMimeParser\Message\IMessagePart::detachContentStream() : static Detaches the content stream. - see \IMessagePart::getContentStream()to get the content stream.
- see \IMessagePart::attachContentStream()to attach a content stream.
|
public abstract ZBateson\MailMimeParser\IErrorBag::getAllErrors(bool $validate = false, string $minPsrLevel = 'error'Psr\Log\LogLevel::ERROR) : array Returns any errors on this object, and all IErrorBag children of this
object at or above the passed PSR log level from Psr\Log\LogLevel
(defaulting to LogLevel::ERROR). Care should be taken using this if the intention is to only 'preview' a
message without parsing it entirely, since this will cause the whole
message to be parsed as it traverses children, and could be slow on
messages with large attachments, etc...
If $validate is true, additional validation may be performed on children
to check for errors.
|
public abstract getAllParts(?callable $fnFilter = NULL) : array 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 callable $fnFilter Optional function accepting an IMessagePart and
returning true if the part should be included.
- return \IMessagePart[] An array of matching parts.
|
public abstract getAllPartsByMimeType(string $mimeType) : array 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. - see \IMultiPart::getPartByMimeType()to get a part by mime type.
- see \IMultiPart::getCountOfPartsByMimeType()to get a count of parts with
a mime type.
- param string $mimeType The mime type to find.
- return \IMessagePart[] An array of matching parts.
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getBinaryContentResourceHandle() : ?mixed 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. - see \IMessagePart::getBinaryContentStream()to get a stream instead.
- see \IMessagePart::saveContent()to save the binary contents to file.
- return resource|null the resource
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getBinaryContentStream() : ?Psr\Http\Message\StreamInterface 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 \StreamInterface|null the stream
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getCharset() : ?string Returns the charset of the content, or null if not applicable/defined. - return string|null the charset
|
public abstract getChild(int $index, ?callable $fnFilter = NULL) : ?ZBateson\MailMimeParser\Message\IMessagePart 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 int $index 0-based index
- param callable $fnFilter Optional function accepting an IMessagePart and
returning true if the part should be included.
- return \IMessagePart|null The matching direct child part or null if not
found.
|
public abstract getChildCount(?callable $fnFilter = NULL) : int 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 callable $fnFilter Optional function accepting an IMessagePart and
returning true if the part should be included.
- return int The number of children, or number of children matching the
the passed filtering callable.
|
public abstract getChildIterator() : RecursiveIterator Returns a \RecursiveIterator of child parts. - 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 \RecursiveIterator<\IMessagePart>
|
public abstract getChildParts(?callable $fnFilter = NULL) : array 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 callable $fnFilter Optional function accepting an IMessagePart and
returning true if the part should be included.
- return \IMessagePart[] An array of matching child parts.
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContent(string $charset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET) : ?string 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. - see \IMessagePart::getContentStream()
- param string $charset the target charset for the returned string
- return ?string the content
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContentDisposition(?string $default = NULL) : ?string Returns the content's disposition, or returns the value of $default if
not defined. - param string $default Optional default value to return if not
applicable/defined
- return string|null the disposition.
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContentId() : ?string Returns the Content ID of the part, or null if not defined. - return string|null the content ID.
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContentStream(string $charset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET) : ?Psr\Http\Message\StreamInterface 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:
$stream = $part->getContentStream();
$someChars = $part->read(4);
$stream2 = $part->getContentStream();
$moreChars = $part->read(4);
echo ($someChars === $moreChars);
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 string $charset Optional charset for the returned stream.
- return \StreamInterface|null the stream
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContentTransferEncoding(?string $default = NULL) : ?string Returns the content transfer encoding used to encode the content on this
part, or the value of $default if not defined. - param ?string $default Optional default value to return if not
applicable/defined
- return string|null the transfer encoding defined for the part.
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getContentType(string $default = 'text/plain') : ?string Returns the mime type of the content, or $default if one is not set. - param string $default Optional override for the default return value of
'text/plain.
- return string the mime type
|
public abstract getCountOfPartsByMimeType(string $mimeType) : int Returns the number of parts that have content types matching the passed
mime type. - see \IMultiPart::getPartByMimeType()to get a part by mime type.
- see \IMultiPart::getAllPartsByMimeType()to get all parts that match a
mime type.
- param string $mimeType The mime type to find.
- return int The number of matching parts.
|
public abstract ZBateson\MailMimeParser\IErrorBag::getErrorLoggingContextName() : string Returns a context name for the current object to help identify it in
logs. |
public abstract ZBateson\MailMimeParser\IErrorBag::getErrors(bool $validate = false, string $minPsrLevel = 'error'Psr\Log\LogLevel::ERROR) : array Returns any local errors this object has at or above the passed PSR log
level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR). If $validate is true, additional validation may be performed on the
object to check for errors. |
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getFilename() : ?string Returns a filename for the part if one is defined, or null otherwise. - return string|null the file name
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getParent() : ?ZBateson\MailMimeParser\Message\IMimePart Returns this part's parent. |
public abstract getPart(int $index, ?callable $fnFilter = NULL) : ?ZBateson\MailMimeParser\Message\IMessagePart 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 int $index The 0-based index (0 being this part if $fnFilter is
null or this part is satisfied by the filter).
- param callable $fnFilter Optional function accepting an IMessagePart and
returning true if the part should be included.
- return \IMessagePart|null A matching part, or null if not found.
|
public abstract getPartByContentId(string $contentId) : ?ZBateson\MailMimeParser\Message\IMessagePart Returns a part that has the given Content ID, or null if not found. Calls {@see \IMessagePart::getContentId()} to find a matching part. - param string $contentId The content ID to find a part for.
- return \IMessagePart|null The matching part.
|
public abstract getPartByMimeType(string $mimeType, int $index = 0) : ?ZBateson\MailMimeParser\Message\IMessagePart 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. - see \IMultiPart::getAllPartsByMimeType()to get all parts that match a
mime type.
- see \IMultiPart::getCountOfPartsByMimeType()to get a count of parts with
a mime type.
- param string $mimeType The mime type to find.
- param int $index Optional 0-based index (defaulting to '0').
- return \IMessagePart|null The part.
|
public abstract getPartCount(?callable $fnFilter = NULL) : int 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 callable $fnFilter Optional function accepting an IMessagePart and
returning true if the part should be included.
- return int The number of matching parts.
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getResourceHandle() : ?mixed 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 resource the resource handle containing the part.
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::getStream() : Psr\Http\Message\StreamInterface 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 \StreamInterface the stream containing the part.
|
public abstract ZBateson\MailMimeParser\IErrorBag::hasAnyErrors(bool $validate = false, string $minPsrLevel = 'error'Psr\Log\LogLevel::ERROR) : bool Returns true if there are errors on this object, or any IErrorBag child
of this object at or above the passed PSR log level in Psr\Log\LogLevel
(defaulting to LogLevel::ERROR). Note that this will stop after finding
the first error and return, so may be slightly more performant if an
error actually exists over calling getAllErrors if only interested in
whether an error exists. Care should be taken using this if the intention is to only 'preview' a
message without parsing it entirely, since this will cause the whole
message to be parsed as it traverses children, and could be slow on
messages with large attachments, etc...
If $validate is true, additional validation may be performed to check for
errors.
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::hasContent() : bool Returns true if the part contains a 'body' (content). |
public abstract ZBateson\MailMimeParser\IErrorBag::hasErrors(bool $validate = false, string $minPsrLevel = 'error'Psr\Log\LogLevel::ERROR) : bool Returns true if this object has an error in its error bag at or above
the passed $minPsrLevel (defaults to ERROR). If $validate is true,
additional validation may be performed. The PSR levels are defined in Psr\Log\LogLevel. |
public abstract ZBateson\MailMimeParser\Message\IMessagePart::isMime() : bool Returns true if the current part is a mime part. |
public abstract ZBateson\MailMimeParser\Message\IMessagePart::isTextPart() : bool Returns true if the content of this part is plain text. |
public abstract SplSubject::notify() |
public abstract removeAllParts(?callable $fnFilter = NULL) : int 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. - param callable $fnFilter Optional function accepting an IMessagePart and
returning true if the part should be included.
- return int The number of removed parts.
|
public abstract removePart(ZBateson\MailMimeParser\Message\IMessagePart $part) : ?int 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
php $part->getParent()->removePart(); .
- param \IMessagePart $part The part to remove
- return int|null The previous index position of the part within its old
parent.
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::save(?mixed $filenameResourceOrStream, string $filemode = 'w+') : static 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 string|resource|\StreamInterface $filenameResourceOrStream the
file, resource, or stream to write to.
- param string $filemode Optional filemode to open a file in (if
$filenameResourceOrStream is a string)
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::saveContent( $filenameResourceOrStream) : static 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 string|resource|\StreamInterface $filenameResourceOrStream
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::setCharsetOverride(string $charsetOverride, bool $onlyIfNoCharset = false) : static 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.
- see \IMessagePart::getContentStream()to get the content stream.
- param string $charsetOverride the actual charset of the content.
- param bool $onlyIfNoCharset if true, $charsetOverride is used only if
getCharset returns null.
|
public abstract ZBateson\MailMimeParser\Message\IMessagePart::setContent( $resource, string $resourceCharset = 'UTF-8'ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET) : static Sets the content of the part to the passed string, resource, or stream. - see \IMessagePart::getContentStream()to get the content stream.
- see \IMessagePart::attachContentStream()to attach a content stream.
- see \IMessagePart::detachContentStream()to detach the content stream.
- param string|resource|\StreamInterface $resource the content.
- param string $resourceCharset the charset of the passed $resource.
|