partBuilderFactory = $pbf; $this->partHeaderContainerFactory = $phcf; $this->parserManager = $pm; $this->headerParser = $hp; } /** * Convenience method to read a line of up to 4096 characters from the * passed resource handle. * * If the line is larger than 4096 characters, the remaining characters in * the line are read and discarded, and only the first 4096 characters are * returned. * * @param resource $handle * * @return string|bool the read line or false on EOF or on error. */ public static function readLine($handle) { $size = 4096; $ret = $line = \fgets($handle, $size); while (\strlen($line) === $size - 1 && \substr($line, -1) !== "\n") { $line = \fgets($handle, $size); } return $ret; } /** * Parses the passed stream into an {@see ZBateson\MailMimeParser\IMessage} * object and returns it. * * @param StreamInterface $stream the stream to parse the message from * * @return \ZBateson\MailMimeParser\IMessage */ public function parse(StreamInterface $stream) { $headerContainer = $this->partHeaderContainerFactory->newInstance(); $partBuilder = $this->partBuilderFactory->newPartBuilder($headerContainer, $stream); $this->headerParser->parse( $partBuilder->getMessageResourceHandle(), $headerContainer ); $proxy = $this->parserManager->createParserProxyFor($partBuilder); return $proxy->getPart(); } }