Skip to content

Commit

Permalink
Use new Emogrifier class
Browse files Browse the repository at this point in the history
  • Loading branch information
emilsundberg committed May 10, 2021
1 parent a4c86ee commit 50c7136
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/Snowfire/Beautymail/CssInlinerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@

namespace Snowfire\Beautymail;

use Pelago\Emogrifier\CssInliner;

class CssInlinerPlugin implements \Swift_Events_SendListener
{
/**
* @var \Pelago\Emogrifier
*/
protected $inliner;

/**
* Initialize the CSS inliner.
*/
public function __construct()
{
$this->inliner = new \Pelago\Emogrifier();
}

/**
* Inline the CSS before an email is sent.
*
Expand All @@ -33,14 +22,16 @@ public function beforeSendPerformed(\Swift_Events_SendEvent $evt)
];

if ($message->getBody() && in_array($message->getContentType(), $properTypes)) {
$this->inliner->setHtml($message->getBody());
$message->setBody($this->inliner->emogrify());
$message->setBody(
CssInliner::fromHtml($message->getBody())->inlineCss()->render()
);
}

foreach ($message->getChildren() as $part) {
if (strpos($part->getContentType(), 'text/html') === 0) {
$this->inliner->setHtml($part->getBody());
$message->setBody($this->inliner->emogrify());
$message->setBody(
CssInliner::fromHtml($part->getBody())->inlineCss()->render()
);
}
}
}
Expand Down

0 comments on commit 50c7136

Please sign in to comment.