/** * Creates a part stream handle for the start and end position of the * message stream, and attaches it to the passed MimePart. * * @param MimePart $part * @param Message $message * @param int $start * @param int $end */ public function attachPartStreamHandle(MimePart $part, Message $message, $start, $end) { $id = $message->getObjectId(); if (empty($this->registeredHandles[$id])) { return null; } $handle = fopen('mmp-mime-message://' . $id . '?start=' . $start . '&end=' . $end, 'r'); $encoding = strtolower($part->getHeaderValue('Content-Transfer-Encoding')); if ($encoding === 'quoted-printable') { stream_filter_append($handle, 'convert.quoted-printable-decode', STREAM_FILTER_READ); } elseif ($encoding === 'base64') { stream_filter_append($handle, 'convert.base64-decode', STREAM_FILTER_READ); } $contentType = strtolower($part->getHeaderValue('Content-Type')); if (empty($contentType) || strpos($contentType, 'text/') === 0) { stream_filter_append($handle, 'mailmimeparser-encode.' . $part->getHeaderParameter('Content-Type', 'charset')); } $this->registeredPartStreamHandles[$id] = $handle; $part->attachContentResourceHandle($handle); }