public function testGetHeaderParameter() { $hf = $this->mockHeaderFactory; $header = $this->getMockedParameterHeader('First-Header', 'Value', 'param-value'); $hf->expects($this->exactly(1))->method('newInstance')->withConsecutive([$header->getName(), $header->getValue()])->willReturnOnConsecutiveCalls($header); $part = new MimePart($hf); $part->setRawHeader($header->getName(), $header->getValue()); $this->assertEquals('param-value', $part->getHeaderParameter('first-header', 'param')); }
/** * Attaches a mailmimeparser-encode stream filter based on the part's * defined charset. * * @param \ZBateson\MailMimeParser\MimePart $part * @param resource $handle */ private function attachCharsetFilterToStream(MimePart $part, $handle) { $contentType = strtolower($part->getHeaderValue('Content-Type', 'text/plain')); if (strpos($contentType, 'text/') === 0) { stream_filter_append($handle, 'mailmimeparser-encode', STREAM_FILTER_READ, ['charset' => $part->getHeaderParameter('Content-Type', 'charset')]); } }
/** * Finds the boundaries for the current MimePart, reads its content and * creates and returns the next part, setting its parent part accordingly. * * @param resource $handle The handle to read from * @param \ZBateson\MailMimeParser\Message $message The current Message * @param \ZBateson\MailMimeParser\MimePart $part * @return MimePart */ protected function readMimeMessagePart($handle, Message $message, MimePart $part) { $boundary = $part->getHeaderParameter('Content-Type', 'boundary'); $skipFirst = true; $parent = $part; if (empty($boundary) || !preg_match('~multipart/\\w+~i', $part->getHeaderValue('Content-Type'))) { // either there is no boundary (possibly no parent boundary either) and message is read // till the end, or we're in a boundary already and content should be read till the parent // boundary is reached if ($part->getParent() !== null) { $parent = $part->getParent(); $boundary = $parent->getHeaderParameter('Content-Type', 'boundary'); } $skipFirst = false; } return $this->readMimeMessageBoundaryParts($handle, $message, $parent, $part, $boundary, $skipFirst); }