/** * @param \Swift_Mime_MimeEntity $message * * @throws \TijsVerkoyen\CssToInlineStyles\Exception */ private function convert(\Swift_Mime_MimeEntity $message) { if ($message->getContentType() !== 'text/plain') { $this->inliner->setCSS(''); $this->inliner->setHTML($message->getBody()); $message->setBody($this->inliner->convert()); } }
protected function createMessage(array $message, \Swift_Mime_MimeEntity $entity) { if (stripos($message["type"], 'multipart/') !== false) { if (strpos($message["type"], '/alternative')) { $nestingLevel = \Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE; } elseif (strpos($message["type"], '/related')) { $nestingLevel = \Swift_Mime_MimeEntity::LEVEL_RELATED; } elseif (strpos($message["type"], '/mixed')) { $nestingLevel = \Swift_Mime_MimeEntity::LEVEL_MIXED; } $childrens = array(); foreach ($message["parts"] as $part) { $headers = $this->createHeadersSet($part["headers"]); $encoder = $this->getEncoder($part["headers"]["content-transfer-encoding"]); if (stripos($part["type"], 'multipart/') !== false) { $newEntity = new \Swift_Mime_MimePart($headers, $encoder, $this->cache, $this->grammar); } else { $newEntity = new \Swift_Mime_SimpleMimeEntity($headers, $encoder, $this->cache, $this->grammar); } $this->createMessage($part, $newEntity); $ref = new \ReflectionObject($newEntity); $m = $ref->getMethod('_setNestingLevel'); $m->setAccessible(true); $m->invoke($newEntity, $nestingLevel); $childrens[] = $newEntity; } $entity->setContentType($part["type"]); $entity->setChildren($childrens); } else { $entity->setBody($message["body"], $message["type"]); } }