JavaMail: Keeping IMAPFolder.idle() alive

后端 未结 4 571
盖世英雄少女心
盖世英雄少女心 2020-12-13 11:07

I am making a program that needs to monitor a Gmail account for new messages, and in order to get them ASAP I am using JavaMail\'s idle feature. Here is a code snippet from

4条回答
  •  萌比男神i
    2020-12-13 11:21

    The suggestion by @user888307 is a dirty hack and eventually fail miserably. There is really only one proper way of doing this.

    Call the idle(false) method on the folder that's currently selected. Ideally Inbox because that will receive all messages.

    Calling idle(false) will basically hang the runtime of the thread, so better to put idle(false) on a new thread. Then once you receive a new email/notification using messageCountChange, you have to rerun this thread.

    This is the only true way of achieving this. I have written a wrapper for your explicit problem as I am writing a program called JavaPushMail. You can find more info on my website (http://www.mofirouz.com/wordpress) or you can grab the application (which is currently in development) on GitHub https://github.com/mofirouz/JavaPushMail

提交回复
热议问题