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"><
<a href="mailto:[censored]@[censored].com">
[censored]@[censored].com
</a>
>
</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)?
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>
Track By Subjects only
Most of Outlook and other email clients only group by the subject lines, for example they strip FW: RE: etc from subject's beginning and compare them without case sensitivity, and they mark them as same group. Mostly in reply/forward people dont change subject, and I doubt there is any other easiest way.
The other way to do this is (very expensive), you have to extract pure TEXT out of html content, and then for the same recepient/sender emails in last couple of days, you can find out if an old email's pure text content exists in any new email and then mark them as conversation.
getInReplyTo only returns message ID, you will have to manually load each message from each folder and find right Message ID, also you must cast your folder to IMAPFolder, did you do that?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With