Mark McLaren
Mark McLaren

Reputation: 11540

Gmail IMAP, Searching for optimal method for X most recently active Gmail threads

I am looking for the optimal way to acquire a list of the top X most recently active Gmail threads.

Background:

I am using Java accessing IMAP with OAuth in a Google Apps for Education domain. A Gmail Atom inbox feed is available which can list the last 20 threads containing unread messages. Access to this feed seems to be very fast much faster than anything I having managed to produce using OAuth/IMAP.

The advantage of using the IMAP approach over the Gmail Atom inbox feed is with IMAP I can access an arbitrary number of messages (not just 20), see read messages, get thread size, get any associated google labels, fetch quota details and check for flags. Essentially this will give my users a much more Gmail like experience (I only need a read only experience for our portal). My problem is IMAP access is significantly slower than the Atom feed. Comparison wise the IMAP method takes around 10 seconds whilst the Atom feed is usually returned within 2 seconds.

I am aware and have been working with the Gmail IMAP Extensions and Gmail Advanced Search syntax .

Current Method:

Imagine I want the top 40 threads from my IMAP inbox. Currently I download some arbitrary number of messages say (40 * 4), fetching only the X-GM-THRID. I iterate through these messages storing the thread id as I go (fetching more messages if required) until I either exhaust the list of inbox messages or I reach my target number of threads.

I then have a list of Gmail thread ids which I can use to perform an IMAP search (with an appropriate FetchProfile.Item's, depending on what message details are required).

I iterate through the search results producing something like (using the wonderful Google Guava/Google Collections Multimap):

Multimap<Long, Message> threadMultiMap = LinkedListMultimap.create();

and this is easily massaged into:

LinkedHashMap<Long, Message[]> threadMap; 

Is there a better way than iterating through the INBOX until X distinct message threads have been identified?

Upvotes: 3

Views: 1071

Answers (1)

agallego
agallego

Reputation: 91

Not actually an answer but a relevant query.


Mark, as per your api request, I'm posting a comment as an answer (http://code.google.com/p/java-gmail-imap/wiki/DisplayingGmailThreadBasedView)

Does your lib support 3 legged oauth, I tried looking for XoauthAuthenticator on the source in the repo and could not find it.

Thanks


Hi agallego,

I use java-gmail-imap with XOAUTH. There is nothing explicitly in JavaMail that requires any changes to work with XOAUTH.

If you look at the XOAUTH projects (google-mail-xoauth-tools and google-mail-xoauth-tool-java-two-legged) you will see that you can create a SASL provider that can be used to authenticate against Gmail. See e.g. XoauthAuthenticator.java

I hope this helps,

Mark

Upvotes: 1

Related Questions