示例#1
0
 public function testSetRawHeader()
 {
     $hf = $this->mockHeaderFactory;
     $firstHeader = $this->getMockedParameterHeader('First-Header', 'Value');
     $secondHeader = $this->getMockedParameterHeader('Second-Header', 'Second Value');
     $hf->expects($this->exactly(2))->method('newInstance')->withConsecutive([$firstHeader->getName(), $firstHeader->getValue()], [$secondHeader->getName(), $secondHeader->getValue()])->willReturnOnConsecutiveCalls($firstHeader, $secondHeader);
     $part = new MimePart($hf);
     $part->setRawHeader($firstHeader->getName(), $firstHeader->getValue());
     $part->setRawHeader($secondHeader->getName(), $secondHeader->getValue());
     $this->assertSame($firstHeader, $part->getHeader($firstHeader->getName()));
     $this->assertSame($secondHeader, $part->getHeader($secondHeader->getName()));
     $this->assertEquals($firstHeader->getValue(), $part->getHeaderValue($firstHeader->getName()));
     $this->assertEquals($secondHeader->getValue(), $part->getHeaderValue($secondHeader->getName()));
     $this->assertCount(2, $part->getHeaders());
     $this->assertEquals(['first-header' => $firstHeader, 'second-header' => $secondHeader], $part->getHeaders());
 }
示例#2
0
 /**
  * Either adds the passed part to $this->textPart if its content type is
  * text/plain, to $this->htmlPart if it's text/html, or adds the part to the
  * parts array otherwise.
  * 
  * @param \ZBateson\MailMimeParser\MimePart $part
  */
 public function addPart(MimePart $part)
 {
     $type = $part->getHeaderValue('Content-Type');
     if ((empty($type) || strtolower($type) === 'text/plain') && empty($this->textPart)) {
         $this->textPart = $part;
     } elseif (strtolower($type) === 'text/html' && empty($this->htmlPart)) {
         $this->htmlPart = $part;
     } else {
         $this->parts[] = $part;
     }
 }
示例#3
0
 /**
  * Returns true if the $part should be assigned as this message's main
  * html part content.
  * 
  * @param \ZBateson\MailMimeParser\MimePart $part
  * @return bool
  */
 private function isMessageHtmlPart(MimePart $part)
 {
     $type = strtolower($part->getHeaderValue('Content-Type', 'text/plain'));
     return $type === 'text/html' && empty($this->htmlPart);
 }
 /**
  * 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);
 }