EmailReplyParser icon indicating copy to clipboard operation
EmailReplyParser copied to clipboard

Multi-line HTML comments mess with EmailReplyParser

Open tomfotherby opened this issue 2 years ago • 0 comments

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.

tomfotherby avatar May 10 '23 17:05 tomfotherby