private void getReply()

in src/main/java/org/apache/commons/net/imap/IMAP.java [247:292]


    private void getReply(final boolean wantTag) throws IOException {
        replyLines.clear();
        String line = _reader.readLine();

        if (line == null) {
            throw new EOFException("Connection closed without indication.");
        }

        replyLines.add(line);

        if (wantTag) {
            while (IMAPReply.isUntagged(line)) {
                int literalCount = IMAPReply.literalCount(line);
                final boolean isMultiLine = literalCount >= 0;
                while (literalCount >= 0) {
                    line = _reader.readLine();
                    if (line == null) {
                        throw new EOFException("Connection closed without indication.");
                    }
                    replyLines.add(line);
                    literalCount -= line.length() + 2; // Allow for CRLF
                }
                if (isMultiLine) {
                    final IMAPChunkListener il = chunkListener;
                    if (il != null) {
                        final boolean clear = il.chunkReceived(this);
                        if (clear) {
                            fireReplyReceived(IMAPReply.PARTIAL, getReplyString());
                            replyLines.clear();
                        }
                    }
                }
                line = _reader.readLine(); // get next chunk or final tag
                if (line == null) {
                    throw new EOFException("Connection closed without indication.");
                }
                replyLines.add(line);
            }
            // check the response code on the last line
            replyCode = IMAPReply.getReplyCode(line);
        } else {
            replyCode = IMAPReply.getUntaggedReplyCode(line);
        }

        fireReplyReceived(replyCode, getReplyString());
    }