예제 #1
0
 /**
  * Gets the attached file name
  *
  * @return Value
  */
 public function getFileName()
 {
     $value = '';
     $headers = $this->part->getHeaders();
     if ($headers->has('Content-Disposition')) {
         $contentDisposition = $this->part->getHeader('Content-Disposition');
         $value = Decode::splitContentType($contentDisposition->getFieldValue(), 'filename');
         $encoding = $contentDisposition->getEncoding();
     }
     if (empty($value) && $headers->has('Content-Type')) {
         /** @var \Zend\Mail\Header\ContentType $contentType */
         $contentType = $this->part->getHeader('Content-Type');
         $value = $contentType->getParameter('name');
         $encoding = $contentType->getEncoding();
     }
     if (empty($encoding)) {
         $encoding = 'ASCII';
     }
     // Extract name from quoted text.
     // zend mail library bug (incorrect header decode).
     // Zend\Mail\Headers line 82 ($currentLine .= ' ' . trim($line);)
     // Fixed in zend-mail 2.4
     if (preg_match('"([^\\"]+)"', $value, $result)) {
         $value = $result[0];
     }
     return new Value($value, $encoding);
 }
예제 #2
0
 /**
  * Gets the message attachments
  *
  * @return Attachment[]
  */
 public function getAttachments()
 {
     if (!$this->isMultipart()) {
         return array();
     }
     $result = array();
     foreach ($this as $part) {
         /** @var Part $part */
         $contentType = $this->getPartContentType($part);
         if ($contentType !== null) {
             $name = $contentType->getParameter('name');
             if ($name !== null) {
                 $contentDisposition = $this->getPartContentDisposition($part);
                 if ($contentDisposition !== null) {
                     if (null !== Decode::splitContentType('attachment')) {
                         $result[] = new Attachment($part);
                     }
                 } else {
                     // The Content-Disposition may be missed, because it is introduced only in RFC 2183
                     // In this case it is assumed that any part which has ";name="
                     // in the Content-Type is an attachment
                     $result[] = new Attachment($part);
                 }
             }
         }
     }
     return $result;
 }
예제 #3
0
 /**
  * Gets the attached file name
  *
  * @return Value
  */
 public function getFileName()
 {
     $value = '';
     $headers = $this->part->getHeaders();
     if ($headers->has('Content-Disposition')) {
         $contentDisposition = $this->part->getHeader('Content-Disposition');
         $value = Decode::splitContentType($contentDisposition->getFieldValue(), 'filename');
         $encoding = $contentDisposition->getEncoding();
     }
     if (empty($value) && $headers->has('Content-Type')) {
         /** @var \Zend\Mail\Header\ContentType $contentType */
         $contentType = $this->part->getHeader('Content-Type');
         $value = $contentType->getParameter('name');
         $encoding = $contentType->getEncoding();
     }
     if (empty($encoding)) {
         $encoding = 'ASCII';
     }
     return new Value($value, $encoding);
 }
 /**
  * Retrieves Message Content
  *
  * @param \Zend\Mail\Storage\Message $zendMailMessage
  * @return string|null
  */
 private function processContent($zendMailMessage)
 {
     $messageContent = '';
     if ($zendMailMessage->getBody()) {
         $parts = $zendMailMessage->getBody()->getParts();
         foreach ($parts as $part) {
             $split = Mime\Decode::splitContentType($part->type);
             if ($split['type'] == \Zend\Mime\Mime::TYPE_TEXT) {
                 $messageContent = $part->getContent();
             }
             if ($split['type'] == \Zend\Mime\Mime::MULTIPART_ALTERNATIVE) {
                 $boundary = $split['boundary'];
                 $bodyParts = Mime\Decode::splitMessageStruct($part->getContent(), $boundary);
                 foreach ($bodyParts as $bodyPart) {
                     $headers = $bodyPart['header'];
                     if ($headers->get('contenttype')->getType() == \Zend\Mime\Mime::TYPE_TEXT) {
                         $messageContent = $bodyPart['body'];
                     }
                 }
             }
         }
     }
     return $messageContent;
 }
예제 #5
0
파일: MessageTest.php 프로젝트: rexmac/zf2
 public function testContentTypeDecode()
 {
     $message = new Message(array('file' => $this->_file));
     $this->assertEquals(Mime\Decode::splitContentType($message->ContentType), array('type' => 'multipart/alternative', 'boundary' => 'crazy-multipart'));
 }
예제 #6
0
 /**
  * @return string|null
  */
 public function getEmbeddedContentId()
 {
     $contentIdValue = $this->getContentIdValue();
     if ($contentIdValue !== null) {
         $contentDisposition = $this->getContentDispositionValue();
         if (!$contentDisposition || Decode::splitContentType($contentDisposition, 'type') === 'inline') {
             return substr($contentIdValue, 1, strlen($contentIdValue) - 2);
         }
     }
     return null;
 }