using this logic i am able to get all unread messages in my gmail account, but the same logic i tried with yahoo account. it is giving all mails in my inbox.
how to get unread mails in yahoo using javamail API???
Just because a flag exists doesn't mean the flag is supported by all mail servers/providers. For instance, besides deleting messages, the POP protocol supports none of them. Checking for new mail is not a POP task but one built into mail clients. To find out what flags are supported, ask the folder with getPermanentFlags().