/** * Reads the next token of the response. The token can be one of: String - * for NIL, QUOTED, NUMBER, ATOM. Object - for LITERAL. * ImapList - for PARENTHESIZED LIST. Can contain any of the above * elements including List. * * @return The next token in the response or null if there are no more * tokens. */ private Object readToken(ImapResponse response) throws IOException { while (true) { Object token = parseToken(response); if (token == null || !(token.equals(")") || token.equals("]"))) { return token; } } }
private ImapList parseList(ImapList parent, char start, char end) throws IOException { expect(start); ImapList list = new ImapList(); parent.add(list); String endString = String.valueOf(end); Object token; while (true) { token = parseToken(list); if (token == null) { return null; } else if (token.equals(endString)) { break; } else if (!(token instanceof ImapList)) { list.add(token); } } return list; }