Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process the HTML body of a message #308

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/CssInlinerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ private function loadCssFromFiles(array $cssFiles): string

private function processHtmlTextPart(TextPart $part): TextPart
{
[$cssFiles, $bodyString] = $this->extractCssFilesFromMailBody($part->getBody());

$bodyString = $this->converter->convert($bodyString, $this->cssToAlwaysInclude . "\n" . $this->loadCssFromFiles($cssFiles));

return new TextPart($bodyString, $part->getPreparedHeaders()->getHeaderParameter('Content-Type', 'charset') ?: 'utf-8', 'html');
return new TextPart($this->convertString($part->getBody()), $part->getPreparedHeaders()->getHeaderParameter('Content-Type', 'charset') ?: 'utf-8', 'html');
}

private function handleSymfonyEmail(Email $message): void
Expand All @@ -105,6 +101,10 @@ private function handleSymfonyEmail(Email $message): void
)
));
}

if (!empty($message->getHtmlBody())) {
$message->html($this->convertString((string) $message->getHtmlBody()));
}
}

private function extractCssFilesFromMailBody(string $message): array
Expand Down Expand Up @@ -143,4 +143,11 @@ private function extractCssFilesFromMailBody(string $message): array

return [$cssFiles, $message];
}

private function convertString(string $body): string
{
[$cssFiles, $bodyString] = $this->extractCssFilesFromMailBody($body);

return $this->converter->convert($bodyString, $this->cssToAlwaysInclude . "\n" . $this->loadCssFromFiles($cssFiles));
}
}