    void readFolderList () throws IOException {
        String tag = writeCommand(mWriter, "list \"\" *");
        String line;
        char dchar = '/';
        userLog("Loading folder list...");
        ArrayList<String> parentList = new ArrayList<String>();
        ArrayList<Mailbox> mailboxList = new ArrayList<Mailbox>();
        while (true) {
            line = mReader.readLine();
            userLog(line);
            if (line.startsWith(tag)) {
                break;
            } else {
                Parser p = new Parser(line, 2);
                String cmd = p.parseAtom();
                if (cmd.equalsIgnoreCase("list")) {
                    @SuppressWarnings("unused")
                    String props = p.parseListOrNil();
                    String delim = p.parseString();
                    if (delim == null)
                        delim = "~";
                    if (delim.length() == 1)
                        dchar = delim.charAt(0);
                    String serverId = p.parseStringOrAtom();
                    int lastDelim = serverId.lastIndexOf(delim);
                    String displayName;
                    String parentName;
                    if (lastDelim > 0) {
                        displayName = serverId.substring(lastDelim + 1);
                        parentName = serverId.substring(0, lastDelim);
                    } else {
                        displayName = serverId;
                        parentName = null;
                    }
                    Mailbox m = new Mailbox();
                    m.mDisplayName = displayName;
                    m.mAccountKey = mAccountId;
                    m.mServerId = serverId;
                    if (parentName != null && !parentList.contains(parentName)) {
                        parentList.add(parentName);
                    }
                    m.mFlagVisible = true;
                    m.mParentServerId = parentName;
                    m.mDelimiter = dchar;
                    m.mSyncInterval = Mailbox.CHECK_INTERVAL_NEVER;
                    mailboxList.add(m);
                } else {
                }
            }
        }
        Cursor c = mResolver.query(Mailbox.CONTENT_URI, Mailbox.CONTENT_PROJECTION,
                Mailbox.ACCOUNT_KEY + "=?", new String[] {Long.toString(mAccountId)},
                MailboxColumns.SERVER_ID + " asc");
        if (c == null) return;
        int cnt = c.getCount();
        String[] serverIds = new String[cnt];
        long[] uidvals = new long[cnt];
        long[] ids = new long[cnt];
        int i = 0;
        try {
            if (c.moveToFirst()) {
                do {
                    serverIds[i] = c.getString(Mailbox.CONTENT_SERVER_ID_COLUMN);
                    uidvals[i] = c.getLong(Mailbox.CONTENT_SYNC_KEY_COLUMN);
                    ids[i] = c.getLong(Mailbox.CONTENT_ID_COLUMN);
                    i++;
                } while (c.moveToNext());
            }
        } finally {
            c.close();
        }
        ArrayList<Mailbox> addList = new ArrayList<Mailbox>();
        for (Mailbox m: mailboxList) {
            int loc = Arrays.binarySearch(serverIds, m.mServerId);
            if (loc >= 0) {
                if (uidvals[loc] == 0) {
                    uidvals[loc] = -1;
                } else {
                    uidvals[loc] = -1;
                }
            } else {
                addList.add(m);
            }
        }
        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
        try {
            for (i = 0; i < cnt; i++) {
                String name = serverIds[i];
                long uidval = uidvals[i];
                if (uidval == 0 && !name.equals("Outbox") &&
                        !name.equalsIgnoreCase(INBOX_SERVER_NAME)) {
                    ops.add(ContentProviderOperation.newDelete(ContentUris.withAppendedId(
                            Mailbox.CONTENT_URI, ids[i])).build());
                    userLog("Deleting unseen mailbox; no match: " + name);
                } else if (uidval > 0 && !name.equalsIgnoreCase(INBOX_SERVER_NAME)) {
                    boolean found = false;
                    for (Mailbox m : addList) {
                        tag = writeCommand(mWriter, "status \"" + m.mServerId + "\" (UIDVALIDITY)");
                        if (readResponse(mReader, tag, "STATUS").equals(IMAP_OK)) {
                            String str = mImapResponse.get(0).toLowerCase();
                            int idx = str.indexOf("uidvalidity");
                            long num = readLong(str, idx + 12);
                            if (uidval == num) {
                                found = true;
                                break;
                            }
                        }
                    }
                    if (!found) {
                        ops.add(ContentProviderOperation.newDelete(ContentUris.withAppendedId(
                                Mailbox.CONTENT_URI, ids[i])).build());
                        userLog("Deleting uidval mailbox; no match: " + name);
                    }
                }
            }
            for (Mailbox m : addList) {
                String serverId = m.mServerId;
                if (serverId == null)
                    continue;
                if (!serverId.equalsIgnoreCase(INBOX_SERVER_NAME)
                        && !serverId.equalsIgnoreCase("Outbox")) {
                    m.mHierarchicalName = m.mServerId;
                    m.mType = Mailbox.TYPE_MAIL;
                    ops.add(ContentProviderOperation.newInsert(
                            Mailbox.CONTENT_URI).withValues(m.toContentValues()).build());
                    userLog("Adding new mailbox: " + m.mServerId);
                }
            }
            applyBatch(ops);
            MailboxUtilities.fixupUninitializedParentKeys(mContext,
                    Mailbox.ACCOUNT_KEY + "=" + mAccountId);
        } finally {
            SyncManager.kick("folder list");
        }
    }

    void readFolderList () throws IOException {
        String tag = writeCommand(mWriter, "list \"\" *");
        String line;
        char dchar = '/';
        userLog("Loading folder list...");
        ArrayList<String> parentList = new ArrayList<String>();
        ArrayList<Mailbox> mailboxList = new ArrayList<Mailbox>();
        while (true) {
            line = mReader.readLine();
            userLog(line);
            if (line.startsWith(tag)) {
                break;
            } else {
                Parser p = new Parser(line, 2);
                String cmd = p.parseAtom();
                if (cmd.equalsIgnoreCase("list")) {
                    @SuppressWarnings("unused")
                    String props = p.parseListOrNil();
                    String delim = p.parseString();
                    if (delim == null)
                        delim = "~";
                    if (delim.length() == 1)
                        dchar = delim.charAt(0);
                    String serverId = p.parseStringOrAtom();
                    int lastDelim = serverId.lastIndexOf(delim);
                    String displayName;
                    String parentName;
                    if (lastDelim > 0) {
                        displayName = serverId.substring(lastDelim + 1);
                        parentName = serverId.substring(0, lastDelim);
                    } else {
                        displayName = serverId;
                        parentName = null;
                    }
                    Mailbox m = new Mailbox();
                    m.mDisplayName = decodeFolderName(displayName, null);
                    m.mAccountKey = mAccountId;
                    m.mServerId = decodeFolderName(serverId, null);
                    if (parentName != null && !parentList.contains(parentName)) {
                        parentList.add(parentName);
                    }
                    m.mFlagVisible = true;
                    m.mParentServerId = parentName;
                    m.mDelimiter = dchar;
                    m.mSyncInterval = Mailbox.CHECK_INTERVAL_NEVER;
                    mailboxList.add(m);
                } else {
                }
            }
        }
        Cursor c = mResolver.query(Mailbox.CONTENT_URI, Mailbox.CONTENT_PROJECTION,
                Mailbox.ACCOUNT_KEY + "=?", new String[] {Long.toString(mAccountId)},
                MailboxColumns.SERVER_ID + " asc");
        if (c == null) return;
        int cnt = c.getCount();
        String[] serverIds = new String[cnt];
        long[] uidvals = new long[cnt];
        long[] ids = new long[cnt];
        int i = 0;
        try {
            if (c.moveToFirst()) {
                do {
                    serverIds[i] = c.getString(Mailbox.CONTENT_SERVER_ID_COLUMN);
                    uidvals[i] = c.getLong(Mailbox.CONTENT_SYNC_KEY_COLUMN);
                    ids[i] = c.getLong(Mailbox.CONTENT_ID_COLUMN);
                    i++;
                } while (c.moveToNext());
            }
        } finally {
            c.close();
        }
        ArrayList<Mailbox> addList = new ArrayList<Mailbox>();
        for (Mailbox m: mailboxList) {
            int loc = Arrays.binarySearch(serverIds, m.mServerId);
            if (loc >= 0) {
                if (uidvals[loc] == 0) {
                    uidvals[loc] = -1;
                } else {
                    uidvals[loc] = -1;
                }
            } else {
                addList.add(m);
            }
        }
        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
        try {
            for (i = 0; i < cnt; i++) {
                String name = serverIds[i];
                long uidval = uidvals[i];
                if (uidval == 0 && !name.equals("Outbox") &&
                        !name.equalsIgnoreCase(INBOX_SERVER_NAME)) {
                    ops.add(ContentProviderOperation.newDelete(ContentUris.withAppendedId(
                            Mailbox.CONTENT_URI, ids[i])).build());
                    userLog("Deleting unseen mailbox; no match: " + name);
                } else if (uidval > 0 && !name.equalsIgnoreCase(INBOX_SERVER_NAME)) {
                    boolean found = false;
                    for (Mailbox m : addList) {
                        tag = writeCommand(mWriter, "status \"" + m.mServerId + "\" (UIDVALIDITY)");
                        if (readResponse(mReader, tag, "STATUS").equals(IMAP_OK)) {
                            String str = mImapResponse.get(0).toLowerCase();
                            int idx = str.indexOf("uidvalidity");
                            long num = readLong(str, idx + 12);
                            if (uidval == num) {
                                found = true;
                                break;
                            }
                        }
                    }
                    if (!found) {
                        ops.add(ContentProviderOperation.newDelete(ContentUris.withAppendedId(
                                Mailbox.CONTENT_URI, ids[i])).build());
                        userLog("Deleting uidval mailbox; no match: " + name);
                    }
                }
            }
            for (Mailbox m : addList) {
                String serverId = m.mServerId;
                if (serverId == null)
                    continue;
                if (!serverId.equalsIgnoreCase(INBOX_SERVER_NAME)
                        && !serverId.equalsIgnoreCase("Outbox")) {
                    m.mHierarchicalName = m.mServerId;
                    m.mType = Mailbox.TYPE_MAIL;
                    ops.add(ContentProviderOperation.newInsert(
                            Mailbox.CONTENT_URI).withValues(m.toContentValues()).build());
                    userLog("Adding new mailbox: " + m.mServerId);
                }
            }
            applyBatch(ops);
            MailboxUtilities.fixupUninitializedParentKeys(mContext,
                    Mailbox.ACCOUNT_KEY + "=" + mAccountId);
        } finally {
            SyncManager.kick("folder list");
        }
    }
