Jingshao Chen
Jingshao Chen

Reputation: 3485

javamail getNewMessageCount in gmail imap always return 0

I am using javamail api to read gmail. Everything works fine however, a call to a folder's getNewMessageCount() always returns 0.

part of the code:

        folder = folder.getFolder("Inbox");

        // try to open read/write and if that fails try read-only
        try {
            folder.open(Folder.READ_WRITE);
        } catch (MessagingException ex) {
            folder.open(Folder.READ_ONLY);
        }
        int totalMessages = folder.getMessageCount();

        if (totalMessages == 0) {
            System.out.println("Empty folder");
            folder.close(false);
            store.close();
        }
        int newMessages = folder.getNewMessageCount();
        System.out.println("Total messages = " + totalMessages);
        System.out.println("New messages = " + newMessages);
        System.out.println("-------------------------------");

Have anyone ran into similar issue?

UPDATE

I tried another IMAP server, it gave the correct number. It seems like a unique problem with gmail server.

Thanks!

Upvotes: 1

Views: 1473

Answers (1)

Justmaker
Justmaker

Reputation: 1371

As shown in: https://mail.google.com/support/bin/answer.py?answer=78761

"the following features are currently unsupported: \Recent flags on messages."

And since the NewMessageCount() method counts messages with the RECENT flags, it will not (yet) find any such messages on Gmail servers (hence always returning value 0).

Upvotes: 1

Related Questions