views:

58

answers:

1

In Google Mail, I would like to get messages that has been assigned multiple labels. For example, if in the Inbox we have three emails:

Email_1 with Label_A and Label_B

Email_2 with Label_A and Label_B

Email_3 with Label_A and Label_C

then I want to select those with Label_A and Label_B at the same time, which are Email_1 and Email_2. Currently the following codes work for one-label situation, but is there any way to do it with more than one label? Thanks.


Properties props = System.getProperties();
Session session = Session.getInstance(props, null);

Store store = session.getStore("imaps");
store.connect("imap.gmail.com", -1, "[email protected]", "password");

Folder folder = store.getDefaultFolder();

folder = folder.getFolder("Label_A");
folder.open(Folder.READ_WRITE);      

int totalMessages = folder.getMessageCount();
int newMessages = folder.getNewMessageCount();
System.out.println("Total messages = " + totalMessages);
System.out.println("New messages = " + newMessages);

A: 

You should be able to do something like this:

private Store store;
private Folder Label_A; 
private Folder Label_B; 
    ...
        Label_A = store.getFolder("Label_A"); 
        Label_B = store.getFolder("Label_B"); 
JackN