An interface representing a single part of an email.
The base type for a message or any child part of a message. The part may contain content, have a parent, and identify the type of content (e.g. mime-type or charset) agnostically.
The interface extends SplSubject -- any modifications to a message must notify any attached observers.
- author Zaahid Bateson
- Implements
SplSubject Stringable ZBateson \MailMimeParser \IErrorBag
Methods |
public abstract __toString() : string Returns the message/part as a string, containing its headers, content and children. Convenience method for calling getContents() on {@see \IMessagePart::getStream()}.
|
public abstract 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.
|
public abstract detachContentStream() : static Detaches the content stream.
|
public abstract 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.
|
public abstract 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:
|
public abstract getCharset() : ?string Returns the charset of the content, or null if not applicable/defined.
|
public abstract 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.
|
public abstract getContentDisposition(?string $default = NULL) : ?string Returns the content's disposition, or returns the value of $default if not defined.
|
public abstract getContentId() : ?string Returns the Content ID of the part, or null if not defined.
|
public abstract 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:
In this case the Stream was rewound, and $stream's second call to read 4 bytes reads the same first 4.
|
public abstract 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.
|
public abstract getContentType(string $default = 'text/plain') : ?string Returns the mime type of the content, or $default if one is not set.
|
public abstract getFilename() : ?string Returns a filename for the part if one is defined, or null otherwise.
|
public abstract getParent() : ?ZBateson Returns this part's parent. |
public abstract 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:
|
public abstract 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:
|
public abstract hasContent() : bool Returns true if the part contains a 'body' (content). |
public abstract isMime() : bool Returns true if the current part is a mime part. |
public abstract isTextPart() : bool Returns true if the content of this part is plain text. |
public abstract 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:
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.
|
public abstract 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.
|
public abstract 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.
|
public abstract 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.
|