Ejemplo n.º 1
0
 protected function initializeMtomSoapMessage(array $contentTypeHeader, $content)
 {
     if (!isset($contentTypeHeader['start']) || !isset($contentTypeHeader['start-info']) || !isset($contentTypeHeader['boundary'])) {
         throw new \InvalidArgumentException();
     }
     $mimeMessage = Message::createFromMessage($content, $contentTypeHeader['boundary']);
     $mimeParts = $mimeMessage->getParts();
     $soapMimePartId = trim($contentTypeHeader['start'], '<>');
     $soapMimePartType = $contentTypeHeader['start-info'];
     $rootPart = array_shift($mimeParts);
     $rootPartType = $this->splitContentTypeHeader($rootPart->type);
     // TODO: add more checks to achieve full compatibility to MTOM spec
     // http://www.w3.org/TR/soap12-mtom/
     if ($rootPart->id != $soapMimePartId || $rootPartType['_type'] != 'application/xop+xml' || $rootPartType['type'] != $soapMimePartType) {
         throw new \InvalidArgumentException();
     }
     foreach ($mimeParts as $mimePart) {
         $this->soapAttachments->add(new SoapAttachment($mimePart->id, $mimePart->type, $mimePart->getContent()));
     }
     // handle content decoding / prevent encoding
     return $rootPart->getContent();
 }
Ejemplo n.º 2
0
    /**
     * check if decoding a string into a \Zend\Mime\Message object works
     *
     */
    public function testDecodeMimeMessage()
    {
        $text = <<<EOD
This is a message in Mime Format.  If you see this, your mail reader does not support this format.

--=_af4357ef34b786aae1491b0a2d14399f
Content-Type: application/octet-stream
Content-Transfer-Encoding: 8bit

This is a test
--=_af4357ef34b786aae1491b0a2d14399f
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-ID: <12>

This is another test
--=_af4357ef34b786aae1491b0a2d14399f--
EOD;
        $res = Mime\Message::createFromMessage($text, '=_af4357ef34b786aae1491b0a2d14399f');
        $parts = $res->getParts();
        $this->assertEquals(2, count($parts));
        $part1 = $parts[0];
        $this->assertEquals('application/octet-stream', $part1->type);
        $this->assertEquals('8bit', $part1->encoding);
        $part2 = $parts[1];
        $this->assertEquals('image/gif', $part2->type);
        $this->assertEquals('base64', $part2->encoding);
        $this->assertEquals('12', $part2->id);
    }
Ejemplo n.º 3
0
 /**
  * @dataProvider dataTestFromMessageDecode
  */
 public function testFromMessageDecode($input, $encoding, $result)
 {
     $parts = Mime\Message::createFromMessage('--089e0141a1902f83ee04e0a07b7a' . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n" . 'Content-Transfer-Encoding: ' . $encoding . "\r\n" . "\r\n" . $result . "\r\n" . '--089e0141a1902f83ee04e0a07b7a--', '089e0141a1902f83ee04e0a07b7a')->getParts();
     $this->assertSame($input . "\n", $parts[0]->getRawContent());
 }