/** * Test a email document with base64 encoding */ public function testEmailBase64() { $content = file_get_contents(__DIR__ . '/../../data/email_base64.txt'); $part = new Part($content); self::assertTrue($part->isMultiPart()); $this->setExpectedException('\\LogicException', "MultiPart content, there aren't body"); $part->getBody(); self::assertEquals('This is thé subject', $part->getHeader('Subject')); /** @var Part[] $parts */ $parts = $part->getParts(); self::assertEquals('This is the content', $parts[0]->getBody()); self::assertEquals('This is the côntént', $parts[1]->getBody()); }
/** * Decodes the content of a Mime part. * * @param \BeSimple\SoapCommon\Mime\Part $part Part to add content * @param string $content Content to decode * * @return null */ private static function decodeContent(Part $part, $content) { $encoding = strtolower($part->getHeader('Content-Transfer-Encoding')); $charset = strtolower($part->getHeader('Content-Type', 'charset')); if ($encoding == Part::ENCODING_BASE64) { $content = base64_decode($content); } elseif ($encoding == Part::ENCODING_QUOTED_PRINTABLE) { $content = quoted_printable_decode($content); } if ($charset != 'utf-8') { $content = iconv($charset, 'utf-8', $content); } $part->setContent($content); }