Skip to content

Commit 73bbe7c

Browse files
committed
Remove full head content in HTML to text converter
When extracting text from HTML part all the content between opening and closing tag should be removed
1 parent 43e2aa9 commit 73bbe7c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Mime/BodyRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ private function convertHtmlToText(string $html): string
7474
return $this->converter->convert($html);
7575
}
7676

77-
return strip_tags(preg_replace('{<(head|style)\b.*?</\1>}i', '', $html));
77+
return strip_tags(preg_replace('{<(head|style)\b.*?</\1>}is', '', $html));
7878
}
7979
}

Tests/Mime/BodyRendererTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ public function testRenderHtmlOnly()
3737
$this->assertEquals(str_replace('=', '=3D', $html), $body->getParts()[1]->bodyToString());
3838
}
3939

40+
public function testRenderMultiLineHtmlOnly()
41+
{
42+
$html = <<<HTML
43+
<head>
44+
<style type="text/css">
45+
css
46+
</style>
47+
</head>
48+
<b>HTML</b>
49+
HTML;
50+
$email = $this->prepareEmail(null, $html);
51+
$body = $email->getBody();
52+
$this->assertInstanceOf(AlternativePart::class, $body);
53+
$this->assertEquals('HTML', str_replace(["\r", "\n"], '', $body->getParts()[0]->bodyToString()));
54+
$this->assertEquals(str_replace(['=', "\n"], ['=3D', "\r\n"], $html), $body->getParts()[1]->bodyToString());
55+
}
56+
4057
public function testRenderHtmlOnlyWithTextSet()
4158
{
4259
$email = $this->prepareEmail(null, '<b>HTML</b>');

0 commit comments

Comments
 (0)