解决方案:
(1) 将floder idle设置为true:folder.idle(true); 这样其实只是忽略异常而已;
(3) 或者干脆直接忽略这个异常(doge
具体代码见handleIdle:...// 忽略任何失败,直到必须中止...
/**
* Read a response from the server while we're in the IDLE state.
* We hold the messageCacheLock while processing the
* responses so that we can update the number of messages
* in the folder (for example).
*
* @param once only do one notification?
* @return true if we should look for more IDLE responses,
* false if IDLE is done
* @throws MessagingException for errors
* @since JavaMail 1.5.2
*/
boolean handleIdle(boolean once) throws MessagingException {
Response r = null;
do {
r = protocol.readIdleResponse();
try {
synchronized (messageCacheLock) {
if (r.isBYE() && r.isSynthetic() && idleState == IDLE) {
/*
* If it was a timeout and no bytes were transferred
* we ignore it and go back and read again.
* If the I/O was otherwise interrupted, and no
* bytes were transferred, we take it as a request
* to abort the IDLE.
*/
Exception ex = r.getException();
if (ex instanceof InterruptedIOException &&
((InterruptedIOException) ex).
bytesTransferred == 0) {
if (ex instanceof SocketTimeoutException) {
logger.finest(
"handleIdle: ignoring socket timeout");
r = null; // repeat do/while loop
} else {
logger.finest("handleIdle: interrupting IDLE");
IdleManager im = idleManager;
if (im != null) {
logger.finest(
"handleIdle: request IdleManager to abort");
im.requestAbort(this);
} else {
logger.finest("handleIdle: abort IDLE");
protocol.idleAbort();
idleState = ABORTING;
}
// normally will exit the do/while loop
}
continue;
}
}
boolean done = true;
try {
if (protocol == null ||
!protocol.processIdleResponse(r))
return false; // done
done = false;
} finally {
if (done) {
logger.finest("handleIdle: set to RUNNING");
idleState = RUNNING;
idleManager = null;
messageCacheLock.notifyAll();
}
}
if (once) {
if (idleState == IDLE) {
try {
protocol.idleAbort();
} catch (Exception ex) {
// ignore any failures, still have to abort.
// connection failures will be detected above
// in the call to readIdleResponse.
}
idleState = ABORTING;
}
}
}
} catch (ConnectionException cex) {
// Oops, the folder died on us.
throw new FolderClosedException(this, cex.getMessage());
} catch (ProtocolException pex) {
throw new MessagingException(pex.getMessage(), pex);
}
// keep processing responses already in our buffer
} while (r == null || protocol.hasResponse());
return true;
}