EmailReplyParser
EmailReplyParser copied to clipboard
Multi-line HTML comments mess with EmailReplyParser
One of our emails has a multi-line HTML comment in it and I noticed it messes with EmailReplyParser.
Example PHP code:
<?php
$parser = new EmailReplyParser\Parser\EmailParser();
$emailContent = "Start of test message,
<!--
a multi-line HTML comment
-->
End of of test message.";
echo $parser->parse($emailContent)->getVisibleText();
Outputs:
Start of test message,
<!--
a multi-line HTML comment%
:warning: Notice that it did not output "End of of test message."
The workaround is to remove the comments before giving the content to EmailReplyParser.
// Remove HTML comments from email content (because the EmailReplyParser doesn't like them)
$emailContent = preg_replace('/<!--(.|\s)*?-->/', '', $text);
echo $parser->parse($emailContent)->getVisibleText();
Using EmailReplyParser v2.10.0 with PHP 7.4.