tags:

views:

182

answers:

2

I am working on a project to retrieve emails from a POP3 mailbox and save those to a database. I would like to find a way I can link original messages to replies so I can relationally show them as a chain. I was going to use subject lines those aren't going to be very reliable as they have the ability to change. Is there anything below the hood that I can use to link a reply message to an original message?

+1  A: 

There may be a way. Many SMTP servers include two headers in the messages:

  • Message-ID: The unique ID of the current message
  • In-Reply-To: the message ID that the current message is in reply to.

You could follow the chain of In-Reply-To identifiers back to the original message to find the entire email thread.

mjmarsh
A: 

Subject lines are the only universal way I'm afraid. Have a look at GMail, that's how they do it and it can be fooled into threading unrelated items if the subjects are the same.

I think email sent from Exchange has some sort of ID for a thread, but that only works inside an organisation running exchange, and I suspect it is not reliable if mails come from outside the organisation.

You could try and thread using the subject and apply some heuristics to separate unrelated items (e.g. emails with completely different recipients would be unrelated). It's not foolproof though.

Steve Haigh