Пример #1
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;
     }
 }
Пример #2
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')]);
     }
 }
Пример #4
0
 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'));
 }
Пример #5
0
 /**
  * Sets up a default Content-Type header of text/plain.
  * 
  * @param HeaderFactory $headerFactory
  */
 public function __construct(HeaderFactory $headerFactory)
 {
     parent::__construct($headerFactory);
     $this->setRawHeader('Content-Type', 'text/plain');
 }
 /**
  * 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);
 }