PHP parsing gmail mail reply -


i trying parse gmail emails, have 1 problem: how know message reply corresponds to?

i tried sorting email subject. example, if message has subject "hi jack", messages subject "re: hi jack" reply mail.

but do if have many emails same subject? how know email replies to?

do emails perhaps have unique code reply goes to? maybe there id or know children of message are(?).

threading subject not idea because there may noticed several different threads based on identical subjects.

you need examine 3 headers in message make threading (or other kind of grouping) possible:

message-id: contains unique message identifier (what call "unique code") in string surrounded < , > characters e.g. <123456@user1pc> muas create identifiers in above form or similar that. header should generated when new message sent.

in-reply-to: contains message particular reply related e.g. <789abcd@user2pc>. header should copied message-id replies to.

references: contains list of recent references messages in "thread". format similar above except separated e.g. <123456@user1pc> <789abcd@user2pc> there can use locate message in thread.

if 1 message has been replied or posted few days later might hard locate without list of references. list of references trimmed mail clients reasonable size. reasonable, mean, trimming enough able locate message in thread keep header under reasonable size (not having many references). example may contain 5-10 references more enough connect other messages. references: useful in case if original message (first one) has been deleted without it, can still utilize references: list build threaded (grouped) messages.

so, in order thread messages, need read of them, , sort threads based on information can extract above headers.

if references or message ids not in form can recognize (e.g. <example@something> can bail out not threading these messages , displaying them unthreaded. generic algorithm threading/locating might this:

  1. take first message id
  2. examine nearby (by date) messages see if 1 of them contains message id in references list or in-reply-to - if there none - can't group keep standalone message.
  3. group messages somehow, perhaps based on date:, or received: header
  4. place message "done" list don't need examine further (or related references)
  5. continue until can't find more references , move next message not in "done" list , repeat steps until process entire message list.

it take while done @ least have starting point into.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -