Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to retrieve the original headers from a forwarded email in php

I'm trying to parse an email which had the following lifecycle (dummy example):

Two days ago :

from : [email protected]

to : [email protected]

Subjet : Hello !

Yesterday :

from : [email protected]

to : [email protected]

Subjet : Re : Hello !

Today :

The mail is forwaded to [email protected]. I have access to this mailbox and I'm able to retrieve the email via php and imap functions. I'm now able to parse the mail, and get the following informations:

from : [email protected]

to : [email protected]

Fwd : Re : Hello !

Is there anyway i can get the history of that email ? I would like to be able to display something like :

Mails history:

edit : to be more accurate, the only thing I really do need to get is what happend to the mail just before it was forwaded to [email protected] (in my example, sent from [email protected] to [email protected]). I do not really need to get what happend before.

I have searched on the Internet for a pretty long time, but since i'm not that fluent in English, I probably didn't use the best query...

Thanks for your help !

like image 285
supag Avatar asked Mar 26 '12 13:03

supag


1 Answers

Unless the information is contained in the mail itself, no.

You can look at the raw mail, including headers and raw body, to see what's in the mail. If it's not in there, and you don't have access to the other accounts it went through first, then you can't get the history of the message.

Messages can contain headers like this:

Message-Id: <[email protected]>
In-Reply-To: <[email protected]>
References: <[email protected]> <[email protected]> <[email protected]>

This is only really useful if you have access to the original messages referenced in these headers. If all you got is the last mail in the chain, this is not very useful.

Your best bet will be to look for quoted content inside the mail, like:

> On 2012/03/24, [email protected] wrote:

> ...

>> On 2012/03/23, [email protected] wrote:

>> ...

There's no standardized format for these lines though, each email program inserts its own version, sometimes user customized, sometimes localized. So they're hard to parse out reliably.

like image 84
deceze Avatar answered Oct 15 '22 04:10

deceze