MimePartWriter
Writes a MimePart to a resource handle.
The class is responsible for writing out the headers and content of a MimePart to an output stream buffer, taking care of encoding and filtering.
Tags
Table of Contents
- $defaultStreamFilterParams : array<string|int, mixed>
- $typeToEncodingMap : array<string|int, mixed>
- getInstance() : mixed
- Returns the singleton instance for the class, instantiating it if not already created.
- writePartContentTo() : mixed
- Writes out the content portion of the mime part based on the headers that are set on the part, taking care of character/content-transfer encoding.
- writePartHeadersTo() : mixed
- Writes out the headers of the passed MimePart and follows them with an empty line.
- writePartTo() : mixed
- Writes out the MimePart to the passed resource.
- copyContentStream() : mixed
- Copies the content of the $fromHandle stream into the $toHandle stream, maintaining the current read position in $fromHandle. The passed MimePart is where $fromHandle originated after setting up filters on $fromHandle.
- setCharsetStreamFilterOnPartStream() : resource
- Sets up a mailmimeparser-encode stream filter on the content resource handle of the passed MimePart if applicable and returns a reference to the filter.
- setTransferEncodingFilterOnStream() : resource
- Appends a stream filter on the passed MimePart's content resource handle based on the type of encoding for the passed part.
- trimTextBeforeCopying() : mixed
- Trims out any starting and ending CRLF characters in the stream.
Properties
$defaultStreamFilterParams
private
static array<string|int, mixed>
$defaultStreamFilterParams
= ['line-length' => 76, 'line-break-chars' => "
"]
$typeToEncodingMap
private
static array<string|int, mixed>
$typeToEncodingMap
= ['quoted-printable' => 'mmp-convert.quoted-printable-encode', 'base64' => 'mmp-convert.base64-encode', 'x-uuencode' => 'mailmimeparser-uuencode', 'x-uue' => 'mailmimeparser-uuencode', 'uuencode' => 'mailmimeparser-uuencode', 'uue' => 'mailmimeparser-uuencode']
Methods
getInstance()
Returns the singleton instance for the class, instantiating it if not already created.
public
static getInstance() : mixed
Return values
mixed —writePartContentTo()
Writes out the content portion of the mime part based on the headers that are set on the part, taking care of character/content-transfer encoding.
public
writePartContentTo(MimePart $part, resource $handle) : mixed
Parameters
- $part : MimePart
- $handle : resource
Return values
mixed —writePartHeadersTo()
Writes out the headers of the passed MimePart and follows them with an empty line.
public
writePartHeadersTo(MimePart $part, resource $handle) : mixed
Parameters
- $part : MimePart
- $handle : resource
Return values
mixed —writePartTo()
Writes out the MimePart to the passed resource.
public
writePartTo(MimePart $part, resource $handle) : mixed
Takes care of character and content transfer encoding on the output based on what headers are set.
Parameters
- $part : MimePart
- $handle : resource
Return values
mixed —copyContentStream()
Copies the content of the $fromHandle stream into the $toHandle stream, maintaining the current read position in $fromHandle. The passed MimePart is where $fromHandle originated after setting up filters on $fromHandle.
private
copyContentStream(MimePart $part, resource $fromHandle, resource $toHandle) : mixed
Parameters
- $part : MimePart
- $fromHandle : resource
- $toHandle : resource
Return values
mixed —setCharsetStreamFilterOnPartStream()
Sets up a mailmimeparser-encode stream filter on the content resource handle of the passed MimePart if applicable and returns a reference to the filter.
private
setCharsetStreamFilterOnPartStream(MimePart $part) : resource
Parameters
- $part : MimePart
Return values
resource —a reference to the appended stream filter or null
setTransferEncodingFilterOnStream()
Appends a stream filter on the passed MimePart's content resource handle based on the type of encoding for the passed part.
private
setTransferEncodingFilterOnStream(MimePart $part, resource $handle, StreamLeftover $leftovers) : resource
Parameters
- $part : MimePart
- $handle : resource
- $leftovers : StreamLeftover
Return values
resource —the stream filter
trimTextBeforeCopying()
Trims out any starting and ending CRLF characters in the stream.
private
trimTextBeforeCopying(string &$read, bool &$first, string &$lastChars) : mixed
Parameters
- $read : string
-
the read string, and where the result will be written to
- $first : bool
-
set to true if this is the first set of read characters from the stream (ltrims CRLF)
- $lastChars : string
-
contains any CRLF characters from the last $read line if it ended with a CRLF (because they're trimmed from the end, and get prepended to $read).