/** * 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); }
/** * 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; }
/** * 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; }
public function testContentTypeDecode() { $message = new Message(array('file' => $this->_file)); $this->assertEquals(Mime\Decode::splitContentType($message->ContentType), array('type' => 'multipart/alternative', 'boundary' => 'crazy-multipart')); }
/** * @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; }