IMAPChangedListener () message not starting

I am implementing an IMAP client using the java mail API. I want to be notified of the number of letters and changes (Read / Unread, etc.) Performed for mail. For this, I wrote two listeners for an open IMAP folder as follows:

IMAPStore imapStore = (IMAPStore) session.getStore("imaps"); imapStore.connect(); final IMAPFolder folder = (IMAPFolder) imapStore.getFolder("Inbox"); folder.open(IMAPFolder.READ_WRITE); folder.addMessageCountListener(new MessageCountListener() { public void messagesAdded(MessageCountEvent e) { System.out.println("Message Count Event Fired"); } public void messagesRemoved(MessageCountEvent e) { System.out.println("Message Removed Event fired"); } }); folder.addMessageChangedListener(new MessageChangedListener() { public void messageChanged(MessageChangedEvent e) { System.out.println("Message Changed Event fired"); } }); 

And I send the IMAP IDLE command to the server in a separate thread as follows.

 Thread t = new Thread(new Runnable() { public void run() { try { while (true) { folder.idle(); } } catch (MessagingException ex) { //Handling exception goes here } } }); t.start(); 

But the problem is that the "MessageCountListener" is launched every time new mail arrives or mail is deleted. But when the mail change occurred, the "MessageChangedListener" does not start.

+4
source share
3 answers

JavaMail is server dependent for sending notifications. The IMAP specification provides sufficient flexibility when sending notifications to servers or if they are sent. Not to mention the fact that some servers do not fully comply with the IMAP specification. You can enable session debugging and check the protocol trace to see if the server is sending any notifications.

Which server are you using?

+6
source

Finally, I got a solution.

For a Gmail account. You need to set "New email notifications to " on the Gmail settings page.

+2
source

This page may be useful for understanding the problem: https://bugzilla.mozilla.org/show_bug.cgi?id=544439

+1
source

Source: https://habr.com/ru/post/1445685/


All Articles