* @package Mammut\Documents */ class Part extends \Zend\Mime\Part { /** * Mammut IO handler * @var boolean true if the content is linked via Mammut\IO classes */ private $isMIO = false; /** * create a new Mime Part. * The (unencoded) content of the Part as passed * as a string or stream * * @param mixed $content Mammut\IO, String or Stream containing the content */ public function __construct($content){ $this->content = $content; if (is_resource($content)) { $this->isStream = true; } } /** * if this was created with a stream, return a filtered stream for * reading the content. very useful for large file attachments. * * @param string $EOL * @return mixed * @throws \RuntimeException if not a stream or unable to append filter */ public function getEncodedStream($EOL = Mime::LINEEND) { if (!$this->isStream) { throw new \RuntimeException('Attempt to get a stream from a string part'); } //stream_filter_remove(); // ??? is that right? switch ($this->encoding) { case Mime::ENCODING_QUOTEDPRINTABLE: $filter = stream_filter_append( $this->content, 'convert.quoted-printable-encode', STREAM_FILTER_READ, array( 'line-length' => 76, 'line-break-chars' => $EOL ) ); if (!is_resource($filter)) { throw new \RuntimeException('Failed to append quoted-printable filter'); } break; case Mime::ENCODING_BASE64: $filter = stream_filter_append( $this->content, 'convert.base64-encode', STREAM_FILTER_READ, array( 'line-length' => 76, 'line-break-chars' => $EOL ) ); if (!is_resource($filter)) { throw new \RuntimeException('Failed to append base64 filter'); } break; default: } return $this->content; } /** * Get the Content of the current Mime Part in the given encoding. * * @param string $EOL * @return string */ public function getContent($EOL = Mime::LINEEND) { if ($this->isStream) { return stream_get_contents($this->getEncodedStream($EOL)); } return Mime::encode($this->content, $this->encoding, $EOL); } /** * Get the RAW unencoded content from this part * @return string */ public function getRawContent() { if ($this->isStream) { return stream_get_contents($this->content); } return $this->content; } }