public function testSpaceInFieldName() { $header = 'test; foo =bar; baz =42'; $this->assertEquals(Mime\Decode::splitHeaderField($header, 'foo'), 'bar'); $this->assertEquals(Mime\Decode::splitHeaderField($header, 'baz'), 42); }
/** * Retrieves Message Attachments * * @param \Zend\Mail\Storage\Message $zendMailMessage * @return array */ private function processAttachments($zendMailMessage) { $attachments = array(); if ($zendMailMessage->getBody()) { $parts = $zendMailMessage->getBody()->getParts(); foreach ($parts as $part) { if ($part->disposition) { $disposition = \Zend\Mime\Decode::splitHeaderField($part->disposition); if ($disposition[0] == \Zend\Mime\Mime::DISPOSITION_ATTACHMENT && isset($disposition['filename'])) { $fileName = $disposition['filename']; $fileContent = $part->getContent(); $attachments[] = new Attachment($fileName, base64_decode($fileContent)); } } } } return $attachments; }
/** * Get a specific field from a header like content type or all fields as array * * If the header occurs more than once, only the value from the first header * is returned. * * Throws an Exception if the requested header does not exist. If * the specific header field does not exist, returns null. * * @param string $name name of header, like in getHeader() * @param string $wantedPart the wanted part, default is first, if null an array with all parts is returned * @param string $firstName key name for the first part * @return string|array wanted part or all parts as array($firstName => firstPart, partname => value) * @throws \Zend\Mime\Exception\RuntimeException */ public function getHeaderField($name, $wantedPart = '0', $firstName = '0') { return Mime\Decode::splitHeaderField(current($this->getHeader($name, 'array')), $wantedPart, $firstName); }
/** * Retrieves Message Attachments * * @param \Zend\Mail\Storage\Message $imapMessage * @return array */ private function processAttachments($imapMessage) { $attachments = array(); if ($imapMessage->isMultipart()) { foreach (new \RecursiveIteratorIterator($imapMessage) as $part) { $headers = $part->getHeaders(); if ($headers->get('contentdisposition')) { $contentDisposition = $headers->get('contentdisposition'); $disposition = \Zend\Mime\Decode::splitHeaderField($contentDisposition->getFieldValue()); if ($disposition[0] == (\Zend\Mime\Mime::DISPOSITION_ATTACHMENT || \Zend\Mime\Mime::DISPOSITION_INLINE) && isset($disposition['filename'])) { $fileName = $disposition['filename']; $fileContent = $part->getContent(); $attachments[] = new Attachment($fileName, base64_decode($fileContent)); } } } } return $attachments; }