mWritable = select && isFolderWritable(folder);
mWritable = select && isFolderWritable(folder, session);
    ImapFolder(String name, boolean select, Mailbox mbox, ImapSession session) throws ServiceException {        name = importPath(name, session);        boolean debug = ZimbraLog.imap.isDebugEnabled();        if (debug)  ZimbraLog.imap.debug("  ** loading folder: " + name);        OperationContext octxt = session.getContext();        Folder folder = mbox.getFolderByPath(octxt, name);        if (!isFolderSelectable(folder))            throw ServiceException.PERM_DENIED("cannot select folder: /" + name);        mPath = name;        mFolderId = folder.getId();        if (folder instanceof SearchFolder) {            String types = ((SearchFolder) folder).getReturnTypes().toLowerCase();            if (types.indexOf("conversation") != -1 || types.indexOf("message") != -1)                mQuery = ((SearchFolder) folder).getQuery();            else                mQuery = "item:none";        }        mWritable = select && isFolderWritable(folder);        mUIDValidityValue = getUIDValidity(folder);        List msgs;        if (!isVirtual())            msgs = mbox.getItemList(octxt, MailItem.TYPE_MESSAGE, folder.getId());        else            msgs = loadVirtualFolder((SearchFolder) folder, mbox, octxt);        // FIXME: need to check messages for flag "IMAP dirty" and assign new IMAP IDs if necessary        Collections.sort(msgs, new Message.SortImapUID());        StringBuffer added = debug ? new StringBuffer("  ** added: ") : null;        for (Message msg : (List<Message>) msgs) {            ImapMessage i4msg = cache(msg);            if (mFirstUnread == -1 && (msg).isUnread())                mFirstUnread = i4msg.seq;            if (debug)  added.append(' ').append(i4msg.id);        }        if (debug)  ZimbraLog.imap.debug(added);        mLastSize = mSequence.size();    }