How can I interrupt IMAP's IDLE?
Performing any operation on that folder (from another thread) will cause idle()
method to return immediately. So if you want to forcefully interrupt it, just call close()
from a new thread.
If you read the documentation properly, and read the source code, you'll realise that you have to create a new thread for calling .idle()
.
Allocate that thread to a variable, and whenever you want call the interrupt()
on that thread, or just ignore notifications!
If you need to get idle()
going again, just rerun the thread!
I created something similar, so you might wanna check it out.
https://github.com/mofirouz/JavaPushMail/blob/master/src/main/java/com/mofirouz/javapushmail/JavaPushMailAccount.java
Good luck