javax.mail.FolderClosedException: * BYE JavaMail Exception: java.io.IOException: Connection dropped

解决方案:

(1) 将floder idle设置为true:folder.idle(true); 这样其实只是忽略异常而已;

(2) 解决方案二:ReadMail operator need to handle FolderClosedException · Issue #5 · IBMStreams/streamsx.mail · GitHub

(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;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值