Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Filtering Email Body, Removing Reply Quotes

Tags:

php

email

piping

I'm working on an email piping script that needs to save just the reply content and not the original quoted email. I'm using a mime parser class (http://www.phpclasses.org/package/3169-PHP-Decode-MIME-e-mail-messages.html) to get all the information that I need from the email:

Message ID: [email protected]
Reply ID: [email protected]

Subject: Re: MessageX
To:  [email protected]
From: Someone [email protected]

Body: Hello,
Blah Blah Blah
-Someone

On Wed, Mar 16, 2011 at 3:52 PM,  <[email protected]> wrote:
> Hello,
>
> Some other blah, blah, blah.
>
> Thank you,
> Me

In the body section, I'm getting the original quoted email. How can I filter this out? I know email clients often add ">" next to quoted content, but I'm not sure if this would be good enough. Thanks for your help.

like image 553
davishmcclurg Avatar asked Mar 16 '11 22:03

davishmcclurg


1 Answers

This might be doable with a regular expression. Try:

$text = preg_replace('#(^\w.+:\n)?(^>.*(\n|$))+#mi', "", $text);
like image 63
mario Avatar answered Sep 30 '22 21:09

mario