I need to parse email content of the forwarded message. I need to classify the email messages into two categories:
- Primary Content (The most recent message of the email)
- Secondary content (All other messages of the email)
Here is my email content:
---------- Forwarded message ----------
From: Khalil Ahmad <otheremail@gmail.com>
Date: Fri, May 12, 2017 at 10:27 AM
Subject: Re: Discussion
To: Hammad Rasheed <myemail@gmail.com>
ok no problem
On Fri, May 12, 2017 at 10:26 AM, Hammad Rasheed <myemail@gmail.com>
wrote:
> Great.
>
> I just want to check how this reply thing works
>
> On Fri, May 12, 2017 at 10:23 AM, Khalil Ahmad <otheremail@gmail.com> wrote:
>
>> yup fine
>>
>> On Fri, May 12, 2017 at 10:23 AM, Hammad Rasheed <myemail@gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> How are you doing?
>>>
>>
>>
>
>
> --
> ---------------------------------------------------------------
> Hammad Rasheed
> Ph: 0332-123456
> myemail@gmail.com <myemail@gmail.com>
> Connect with me on Linkedin:
> http://www.linkedin.com/in/xxxxxxx
>
--
---------------------------------------------------------------
Hammad Rasheed
Ph: 0332-12345852
myemail@gmail.com <myemail@gmail.com>
Connect with me on Linkedin:
http://www.linkedin.com/in/xxxxxxx
--001a114b102aa2bdb7054f4d014a
I was able to extract all the forwarded messages using the following regex:
preg_match_all('~^>.*~m', $body, $secondary);
Now I need to the return message (last one) that was sent i.e "ok no problem" message that does not start with ">" character. But I am unable to make regex for that.
Can anyone please help?