Java-gmail-imap - Extending JavaMail 1.4.4 to support the Gmail IMAP Extensions

  •        1180

What's new?Version 0.5 adds support for the XLIST command which populates the returned folders list with additional attributes. These can be used to map localized folder names to the special folders equivalents (e.g. the Todos folder in Spanish is identified as AllMail). The current list of special folders is: Inbox, Starred, Sent Items, Draft, Spam, All Mail. See XLIST example. An extension of JavaMail 1.4.4 to support the GMail IMAP protocol extensions Gmail supports IMAP but has also provided some IMAP extensions for developer use. Gmail IMAP Extensions This project extends JavaMail 1.4.4 to provide additional support for some of these extensions. This makes it possible to present the user with a thread based view of their e-mails (as GMail does). IMAPMessage gains several new methods including: long getGoogleMessageId();long getGoogleMessageThreadId();String[] getGoogleMessageLabels();How to make use of this A copy of the source code of JavaMail 1.4.4 has been made and the package structure has been relocated to the following packages - to avoid confusion: com.google.code.com.sun.mail com.google.code.javax.mail So this is not a drop in replacement for JavaMail 1.4.4 but it should mostly work in the same way. If you are interested in what changes were necessary to JavaMail 1.4.4 to enable support for the GMail IMAP protocol extensions then please look at the source code repository under the 0.1 tag. One possible use of this code is when accessing Gmail accounts using oAuth - see: google-mail-xoauth-tools. Once you have obtained your IMAPSSLStore you can use the FetchProfile mechanism to use the IMAP extension data that is made available by the code in this project: Example: Obtaining X_GM_MSGID, X_GM_THRID and X_GM_LABELS values for messages: ... IMAPSSLStore store = ... Folder inbox = null; try { inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_ONLY); Message[] ms = inbox.getMessages(); FetchProfile fp = new FetchProfile(); fp.add(IMAPFolder.FetchProfileItem.X_GM_MSGID); fp.add(IMAPFolder.FetchProfileItem.X_GM_THRID); fp.add(IMAPFolder.FetchProfileItem.X_GM_LABELS); inbox.fetch(ms, fp); for (Message m : ms) { IMAPMessage im = (IMAPMessage) m; System.out.println(im.getGoogleMessageId()); // Hex version - useful for linking to Gmail System.out.println(Long.toHexString(im.getGoogleMessageId())); System.out.println(im.getGoogleMessageThreadId()); String[] labels = im.getGoogleMessageLabels(); if(labels!=null){ for(String label: labels){ System.out.println("Label: " + label); } } } } finally { if (inbox.isOpen()) { inbox.close(true); } store.close(); }...Searching Support: The SearchTerm implementation allows for searching GMail by message id (X-GM-MSGID), thread Id (X-GM-THRID), label (X-GM-LABELS) and using the advanced search syntax (X-GM-RAW). (Although SearchTerm using X-GM-RAW is not fully implemented) Example: Searching for messages in the same thread: ...public static void simpleSearch(IMAPSSLStore store) throws MessagingException { FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE); fp.add(IMAPFolder.FetchProfileItem.X_GM_THRID); IMAPFolder folder = null; try { folder = (IMAPFolder) store.getFolder("INBOX"); if (folder != null) { folder.open(Folder.READ_ONLY); int msgCount = folder.getMessageCount(); IMAPMessage lastMsg = (IMAPMessage) folder.getMessage(msgCount); folder.fetch(new Message[]{lastMsg}, fp); long threadId = lastMsg.getGoogleMessageThreadId(); System.out.println(threadId); GmailThreadIDTerm term = new GmailThreadIDTerm(threadId + ""); Message[] thread = folder.search(term); folder.fetch(thread, fp); for(Message m: thread){ System.out.println("### " + m.getSubject()); } } } finally { if (folder.isOpen()) { folder.close(true); } store.close(); }}...The following is an example transcript of a call to SEARCH using the X-GM-THRID attribute, which could result by running the above Java method: A5 SEARCH X-GM-THRID 1375670460152672467 ALL* SEARCH 8 9 10 12A5 OK SEARCH completed (Success)Possible future directionsCompression support It would be nice to be able to make use of Gmail's COMPRESS (RFC4978) functionality. I made a quick assessment of the JavaMail source that is responsible for this (Protocol.java I think) and changing it to support compression might be a bit beyond my talents right now. I also got the impression it might not be worth the effort: Is it worthwhile using IMAP COMPRESS (DEFLATE)?. Produce an efficient thread gathering mechanism I have a working method to gather the top X threads from Gmail. It would be really good if I could improve on this method. Google Apps Script has a method to retrieve a range of Inbox threads (getInboxThreads()) which leads me to suspect that there are features in their IMAP implementation that Google has not made public. I'd be very grateful for any suggestions: Searching for optimal method for X most recently active Gmail threads Enjoy!

http://code.google.com/p/java-gmail-imap

Tags
Implementation
License
Platform

   




Related Projects

vim-olive - Vim Mode Line Verifier


Vim Mode Line Verifier

vim-mash - Motion Activated Search Highlighter for Vim


Motion Activated Search Highlighter for Vim

vim-grillz - Flash your wicked grillz!


Flash your wicked grillz!

vim-foist - Complete whole lines from any partial therein


Complete whole lines from any partial therein

vim-efmc - Vim Error Format Compiler


Vim Error Format Compiler


uzbl-utrs - mkng uzbl tlrbl


mkng uzbl tlrbl

toycsv - A toy CSV parser written in ruby + lexr + racc


A toy CSV parser written in ruby + lexr + racc

tiktok - TikTok provides a simple asynchronous timer object for VimL.


TikTok provides a simple asynchronous timer object for VimL.

tabby - Using Vim's Tabs the Right Way


Using Vim's Tabs the Right Way

SohiVila - GNU source-highlight Vim language


GNU source-highlight Vim language

SinTax - A DSL for generating Vim syntax highlighting files


A DSL for generating Vim syntax highlighting files

rkdots - Generate a graphviz visualisation of the given javascript statement.


Generate a graphviz visualisation of the given javascript statement.

RelNumBar - Show relativenumbers alongside normal numbers in Vim


Show relativenumbers alongside normal numbers in Vim

Punisher - Punisher hurts you where it hurts most - your time.


Punisher hurts you where it hurts most - your time.

noisy - Don't chat quietly (weechat channel noises)


Don't chat quietly (weechat channel noises)

newlisp-manual - Asciidoc version of the newLISP manual


Asciidoc version of the newLISP manual

Land-of-newLISP - Selected snippets from Land of Lisp rewritten in newLISP


Selected snippets from Land of Lisp rewritten in newLISP

Fossilise - Poor man's collaborative editing in Vim


Poor man's collaborative editing in Vim

firstly - Convert Between Numeric, Spelt, and Short & Long Ordinal Forms of Numbers


Convert Between Numeric, Spelt, and Short & Long Ordinal Forms of Numbers