Q:

JavaMail: Searching for emails

I'm busying trying to implement/play around with the Oracle's JavaMail. I'm essentially using it to index large quantities of emails via IMAP (As I need the folder structure). I'll cut to the chase: Is there a quick way to search across all folders for a particular message-ID?
What I'm currently doing is downloading a subset of emails from a folder, and reading the 'References' header of each email. In order to compile the emails into common discussions/threads I need to find the remaining emails referenced in each email's header. Is there a good way to do this? Am I going about compiling messages into common threads the wrong way?
I've thought about iterating through each folder and doing a search, however this method is very slow...
Any input would be muchly appreciated ;-)

A:

There's some IMAP extensions that might help, but very few are implemented by more than one server, and typically not by the most popular servers.  So, pretty much, you're stuck doing it the hard way.  You can certainly parallelize the operations on folders if that will help.
Within the limits of what you have to do, there are often more and less efficient ways to do it using the IMAP protocol and the JavaMail API.  Be sure to look at the Folder.fetch method, for example.
You might also find this writeup of message threading to be helpful.

