TreeMap<Integer, Object> insertions = new TreeMap<Integer, Object>(); req.skipSpace();  String search = req.readSearch(insertions); checkEOF(tag, req); return doSEARCH(tag, search, insertions, byUID);
Integer options = null;  TreeMap<Integer, Object> insertions = new TreeMap<Integer, Object>(); req.skipSpace(); if ("RETURN".equals(req.peekAtom())) { options = 0; req.skipAtom("RETURN");  req.skipSpace();  req.skipChar('('); while (req.peekChar() != ')') { String option = req.readAtom(); if (option.equals("MIN"))         options |= RETURN_MIN; else if (option.equals("MAX"))    options |= RETURN_MAX; else if (option.equals("ALL"))    options |= RETURN_ALL; else if (option.equals("COUNT"))  options |= RETURN_COUNT; else throw new ImapParseException(tag, "unknown RETURN option \"" + option + '"'); if (req.peekChar() != ')') req.skipSpace(); } req.skipChar(')');  req.skipSpace(); if (options == 0) options = RETURN_ALL; } String search = req.readSearch(insertions); checkEOF(tag, req); return doSEARCH(tag, search, insertions, byUID, options);
    private boolean executeRequest(OzImapRequest req, ImapSession session) throws IOException, ImapParseException {        if (session != null && session.isIdle())            return doIDLE(null, IDLE_STOP, req.readAtom().equals("DONE") && req.eof());        String tag = req.readTag();        boolean byUID = false;        req.skipSpace();        String command = req.readAtom();        do {            switch (command.charAt(0)) {                case 'A':                    if (command.equals("AUTHENTICATE")) {                        req.skipSpace();  String mechanism = req.readAtom();                        byte[] response = null;                        if (req.peekChar() == ' ') {                            req.skipSpace();  response = req.readBase64(true);                        }                        checkEOF(tag, req);                        return doAUTHENTICATE(tag, mechanism, response);                    } else if (command.equals("APPEND")) {                        List<String> flags = null;  Date date = null;                        req.skipSpace();  String folder = req.readFolder();                        req.skipSpace();                        if (req.peekChar() == '(') {                            flags = req.readFlags();  req.skipSpace();                        }                        if (req.peekChar() == '"') {                            date = req.readDate(mTimeFormat);  req.skipSpace();                        }                        if (req.peekChar() == 'c' || req.peekChar() == 'C') {                            List<Object> parts = new LinkedList<Object>();                            req.skipAtom("CATENATE");  req.skipSpace();  req.skipChar('(');                            while (req.peekChar() != ')') {                                if (!parts.isEmpty())  req.skipSpace();                                String type = req.readAtom();  req.skipSpace();                                if (type.equals("TEXT"))      parts.add(req.readLiteral());                                else if (type.equals("URL"))  parts.add(new ImapURL(tag, mSession, req.readAstring()));                                else throw new ImapParseException(tag, "unknown CATENATE cat-part: " + type);                            }                            req.skipChar(')');  checkEOF(tag, req);                            return doCATENATE(tag, folder, flags, date, parts);                        } else {                            byte[] content = req.readLiteral8();                            checkEOF(tag, req);                            return doAPPEND(tag, folder, flags, date, content);                        }                    }                    break;                case 'C':                    if (command.equals("CAPABILITY")) {                        checkEOF(tag, req);                        return doCAPABILITY(tag);                    } else if (command.equals("COPY")) {                        req.skipSpace();  String sequence = req.readSequence();                        req.skipSpace();  String folder = req.readFolder();                        checkEOF(tag, req);                        return doCOPY(tag, sequence, folder, byUID);                    } else if (command.equals("CLOSE")) {                        checkEOF(tag, req);                        return doCLOSE(tag);                    } else if (command.equals("CREATE")) {                        req.skipSpace();  String folder = req.readFolder();                        checkEOF(tag, req);                        return doCREATE(tag, folder);                    } else if (command.equals("CHECK")) {                        checkEOF(tag, req);                        return doCHECK(tag);                    }                    break;                case 'D':                    if (command.equals("DELETE")) {                        req.skipSpace();  String folder = req.readFolder();                        checkEOF(tag, req);                        return doDELETE(tag, folder);                    }                    break;                case 'E':                    if (command.equals("EXPUNGE")) {                        String sequence = null;                        if (byUID) {                            req.skipSpace();  sequence = req.readSequence();                        }                        checkEOF(tag, req);                        return doEXPUNGE(tag, byUID, sequence);                    } else if (command.equals("EXAMINE")) {                        req.skipSpace();  String folder = req.readFolder();                        checkEOF(tag, req);                        return doEXAMINE(tag, folder);                    }                    break;                case 'F':                    if (command.equals("FETCH")) {                        List<ImapPartSpecifier> parts = new ArrayList<ImapPartSpecifier>();                        req.skipSpace();  String sequence = req.readSequence();                        req.skipSpace();  int attributes = req.readFetch(parts);                        checkEOF(tag, req);                        return doFETCH(tag, sequence, attributes, parts, byUID);                    }                    break;                case 'G':                    if (command.equals("GETQUOTA")) {                        req.skipSpace();  String qroot = req.readAstring();                        checkEOF(tag, req);                        return doGETQUOTA(tag, qroot);                    } else if (command.equals("GETQUOTAROOT")) {                        req.skipSpace();  String path = req.readFolder();                        checkEOF(tag, req);                        return doGETQUOTAROOT(tag, path);                    }                    break;                case 'I':                    if (command.equals("ID")) {                        req.skipSpace();  Map<String, String> params = req.readParameters(true);                        checkEOF(tag, req);                        return doID(tag, params);                    } else if (command.equals("IDLE")) {                        checkEOF(tag, req);                        return doIDLE(tag, IDLE_START, true);                    }                    break;                case 'L':                    if (command.equals("LOGIN")) {                        req.skipSpace();  String user = req.readAstring();                        req.skipSpace();  String pass = req.readAstring();                        checkEOF(tag, req);                        return doLOGIN(tag, user, pass);                    } else if (command.equals("LOGOUT")) {                        checkEOF(tag, req);                        return doLOGOUT(tag);                    } else if (command.equals("LIST")) {                        req.skipSpace();  String base = req.readEscapedFolder();                        req.skipSpace();  String pattern = req.readFolderPattern();                        checkEOF(tag, req);                        return doLIST(tag, base, pattern);                    } else if (command.equals("LSUB")) {                        req.skipSpace();  String base = req.readEscapedFolder();                        req.skipSpace();  String pattern = req.readFolderPattern();                        checkEOF(tag, req);                        return doLSUB(tag, base, pattern);                    }                    break;                case 'N':                    if (command.equals("NOOP")) {                        checkEOF(tag, req);                        return doNOOP(tag);                    } else if (command.equals("NAMESPACE")) {                        checkEOF(tag, req);                        return doNAMESPACE(tag);                    }                    break;                case 'R':                    if (command.equals("RENAME")) {                        req.skipSpace();  String folder = req.readFolder();                        req.skipSpace();  String name = req.readFolder();                        checkEOF(tag, req);                        return doRENAME(tag, folder, name);                    }                    break;                case 'S':                    if (command.equals("STORE")) {                        byte operation = STORE_REPLACE;  boolean silent = false;                        req.skipSpace();  String sequence = req.readSequence();                        req.skipSpace();                        switch (req.peekChar()) {                            case '+':  req.skipChar('+');  operation = STORE_ADD;     break;                            case '-':  req.skipChar('-');  operation = STORE_REMOVE;  break;                        }                        String cmd = req.readAtom();                        if (cmd.equals("FLAGS.SILENT"))  silent = true;                        else if (!cmd.equals("FLAGS"))   throw new ImapParseException(tag, "invalid store-att-flags");                        req.skipSpace();  List<String> flags = req.readFlags();                        checkEOF(tag, req);                        return doSTORE(tag, sequence, flags, operation, silent, byUID);                    } else if (command.equals("SEARCH")) {                        TreeMap<Integer, Object> insertions = new TreeMap<Integer, Object>();                        req.skipSpace();  String search = req.readSearch(insertions);                        checkEOF(tag, req);                        return doSEARCH(tag, search, insertions, byUID);                    } else if (command.equals("SELECT")) {                        req.skipSpace();  String folder = req.readFolder();                        checkEOF(tag, req);                        return doSELECT(tag, folder);                    } else if (command.equals("STARTTLS")) {                        checkEOF(tag, req);                        return doSTARTTLS(tag);                    } else if (command.equals("STATUS")) {                        int status = 0;                        req.skipSpace();  String folder = req.readFolder();                        req.skipSpace();  req.skipChar('(');                        while (req.peekChar() != ')') {                            String flag = req.readAtom();                            if (flag.equals("MESSAGES"))          status |= STATUS_MESSAGES;                            else if (flag.equals("RECENT"))       status |= STATUS_RECENT;                            else if (flag.equals("UIDNEXT"))      status |= STATUS_UIDNEXT;                            else if (flag.equals("UIDVALIDITY"))  status |= STATUS_UIDVALIDITY;                            else if (flag.equals("UNSEEN"))       status |= STATUS_UNSEEN;                            else                                throw new ImapParseException(tag, "unknown STATUS attribute \"" + flag + '"');                            if (req.peekChar() != ')')                                req.skipSpace();                        }                        req.skipChar(')');                        checkEOF(tag, req);                        return doSTATUS(tag, folder, status);                    } else if (command.equals("SUBSCRIBE")) {                        req.skipSpace();  String folder = req.readFolder();                        checkEOF(tag, req);                        return doSUBSCRIBE(tag, folder);                    } else if (command.equals("SETQUOTA")) {                        Map<String, String> limits = new HashMap<String, String>();                        req.skipSpace();  String qroot = req.readAstring();                        req.skipSpace();  req.skipChar('(');                        while (req.peekChar() != ')') {                            String resource = req.readAtom();  req.skipSpace();                            limits.put(resource, req.readNumber());                        }                        req.skipChar(')');                        checkEOF(tag, req);                        return doSETQUOTA(tag, qroot, limits);                    }                    break;                case 'U':                    if (command.equals("UID")) {                        req.skipSpace();  command = req.readAtom();                        if (!command.equals("FETCH") && !command.equals("SEARCH") && !command.equals("COPY") && !command.equals("STORE") && !command.equals("EXPUNGE"))                            throw new ImapParseException(tag, "command not permitted with UID");                        byUID = true;                        continue;                    } else if (command.equals("UNSUBSCRIBE")) {                        req.skipSpace();  String folder = req.readFolder();                        checkEOF(tag, req);                        return doUNSUBSCRIBE(tag, folder);                    } else if (command.equals("UNSELECT")) {                        checkEOF(tag, req);                        return doUNSELECT(tag);                    }                    break;            }        } while (byUID);        throw new ImapParseException(tag, "command not implemented");    }