Search code examples
javagmailimapemail

Can i track an IMAP mail reply?


I am working on an IMAP client using java mail. We currently have a requirement of creating a "group by conversation" feature where user can view mails as conversation (Refer to how gmail groups mails that are replied and forwarded)

I am able to retrieve mails from the server, but in the mail parts i recieve, the replied mail is "fused" with actual mail and is treated like actual mail content.

eg: initial mail:

<div>This is the initial mail.</div>

replied mail:

This is the response Mail<br><br>
<div class="gmail_quote">
On Wed, Aug 26, 2009 at 4:26 PM, [censored] 
<span dir="ltr">&lt;
<a href="mailto:[censored]@[censored].com">
[censored]@[censored].com
</a>
&gt;
</span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
    <div>This is the initial mail.</div>
    <div></div>
</blockquote>
</div>
<br>

as shown above, there is no indication of what was actual and what was replied mail, how then is it possible to provide a grouping like gmail (regardless of server from where mail is read from)?


Solution

  • If you get the raw source of the messages you can relate messages to one another by looking at the following headers:

    Message-ID: <097819EBC7F79F4A850C8F088D35927302442A82AA@xxxxxxxxxxxxxxxxxxx>
    References: <4A8BE8F3.2060007@xxxxxxxxxxxxxx>
    In-Reply-To: <4A8BE8F3.2060007@xxxxxxxxxxxxxxx>