This is a port of the discourse/email_reply_trimmer library. It's a small library to trim replies from plain text email.
Install via Composer:
composer require andrifix/email-reply-trimmerTo trim replies:
$trimmed_body = EmailReplyTrimmer::trim($email_body);You can also split the trimmed content and the elided part (the removed reply):
[$trimmedBody, $elidedContent] = EmailReplyTrimmer::trim($emailBody, true);To extract the first embedded email section:
$extracted = EmailReplyTrimmer::extractEmbeddedEmail($emailBodyWithEmbedded);
if ($extracted) {
    [$embeddedEmail, $beforeEmbedded] = $extracted;
    echo "Text Before Embedded Email: $beforeEmbedded\n";
    echo "Embedded Email $embeddedEmail:\n";
} else {
    echo "No embedded email found.";
}