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: 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");; 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) {; 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.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 ( 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!



Related Projects


raspBerry+ is a web-based administration platform for Blackberry Enterprise Server for MS Exchange (BES). You can group-based activate/kill/delete/add and get status of users, their handhelds and services. With a little download-area and a comment-system


RASP's A Sneakernet Proxy; download using a thumbdrive.


RasmusDSP is an embeddable Audio/MIDI processor. It contains various filters and generators (including SoundFont 2.0 compatible synthesizer). Has a script interpreter which is used to describe instruments, route Audio/MIDI signal between processor units.


An acronym for cRoss-plAtform accesS control for Enterprise Applications. Rasea aims to become a reference in access control as a service based on the RBAC model.


Rascal, the Advanced Scientific CALculator, is a platform independent modular calculator. Based on modules for integer, doubles, strings, vectors and matrices it can be easily extended with existing C or C++ code.


RARS is the Robot Auto Racing Simulation, in which the drivers are robot programs. It is intended as a competition among programmers. It consists of a simulation of the physics of cars, a graphic display of the race, and a robot driver for each car.


This small program allows you to play a video directly from a RAR file and do so in real-time. Both VLC and MPlayer are supported video players.


RAReXtract is a Front-End for the UnRAR command line utility for Mac OS X 10.5 (Leopard). Its purpose is the rapid and convenient extraction of RAR archives with a double click.

RAR Expander

Rar Expander is a MacOSX program which extracts the files contained in single or multi-volume RAR archives. It uses the official unRAR library internally so it is fully compatible with archives produced by WinRAR.


This program uses a brute force algorithm to guess your encrypted compressed file\'s password. If you forget your encrypted file password, this program is the solution. This program can crack zip,7z and rar file passwords.


RArcInfo is a package for R ( to import data from binary Arc/Info V7.X coverages and E00 files . This will allow R users to used it as a primary GIS tool.

rar brute force shell script - rarbrute

This is rarbrute, a shell script to brute force encrypted rar files under unix and linux. A long wordlist and a paper about security in internet cafes is included.

Raquel Database System

The system will : 1. use RAQUEL (= Relational Algebra Query, Update and Executive Language) for programming, implementing Third Manifesto principles. 2. have a 'Lego-like' architecture of building blocks and plug-ins, for wider applicability.


RAPv4 is an engine for building web application with only a business description (in XML format). NEW 04/2006 : Stable 2006 release. Add new functions like mail, sms, web services, graph, map engine (GIS), Excel output, QBE... and also a beta release of


2d Scroller. Clone of Raptor: Call of the Shadows and Tyrian. Fun game written in c++ using allegro.


Lightweight XML based transformation tool written in C that builds upon expat, tidylib and XSLT to tranform authored web content (incl. Word processor generated HTML) into styled web content suitable for publication.


RapidSMS is an open-source internet and communications platform


RapidSmith is a research-based FPGA CAD tool framework written in Java for modern Xilinx FPGAs. Based on XDL, its objective is to serve as a rapid prototyping platform for research ideas and algorithms relating to low level FPGA CAD tools.

Rapidshare Mass Downloader

What this program does is bringing out human interaction while downloading files from rapidshare(without premium account). It downloads all the rapidshare links sequentially to the specified location.

rapido visual profiler

rapido is a visual profiler for linux-x86. It traces function call using the ptrace interface and displays the information collected in a nice visual flow chart. rapido does not require the re-compilation of the application.