How can I interrupt IMAP's IDLE?

前端 未结 3 818
慢半拍i
慢半拍i 2021-01-12 13:44

I am using the Javamail API connecting to my IMAP server. Everything is working great with the javax.mail.Folder.idle() method. My listener gets called when a new mail comes

3条回答
  •  难免孤独
    2021-01-12 14:25

    A proper way to abort IDLE command is the following snippet. Note that the Folder instance should be the same as the one used to start idling. I've tested the other solutions proposed on this thread but they didn't work in my case.

    IMAPFolder folder = store.getFolder("INBOX");
    try {
      folder.doOptionalCommand("Abort IDLE error mesage", new IMAPFolder.ProtocolCommand() {
      @Override
      public Object doCommand(IMAPProtocol p) throws ProtocolException {
        p.idleAbort();
        return Boolean.TRUE;
      }
    });
    } catch (MessagingException e) {
      e.printStackTrace();
    }
    

提交回复
热议问题