PHP - Filtering Email Body, Removing Reply Quotes

心不动则不痛 提交于 2019-12-18 11:55:51

问题


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: AANLkTimYRxMJwjLSdcDP5ksM=xxx@mail.gmail.com
Reply ID: 20110316205225.xxx@example.com

Subject: Re: MessageX
To:  q1-1234567890@example.com
From: Someone someone@someothersite.com

Body: Hello,
Blah Blah Blah
-Someone

On Wed, Mar 16, 2011 at 3:52 PM,  <q1-1234567890@example.com> 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.


回答1:


This might be doable with a regular expression. Try:

$text = preg_replace('#(^\w.+:\n)?(^>.*(\n|$))+#mi', "", $text);


来源:https://stackoverflow.com/questions/5332382/php-filtering-email-body-removing-reply-quotes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!