In Google Mail, I would like to receive messages that have been assigned several labels. For example, if there are three letters in your inbox:
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 simultaneously select those that have Label_A and Label_B, which are Email_1 and Email_2. The following codes currently work for a single label situation, but is there a way to do this with multiple labels? Thanks.
Properties props = System.getProperties(); Session session = Session.getInstance(props, null); Store store = session.getStore("imaps"); store.connect("imap.gmail.com", -1, " abc@def.com ", "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);
source share