mInitialMaxUID = (mLastSize == 0 ? -1 : mSequence.get(mLastSize - 1).imapUid);
    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, session))            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, session);        mUIDValidityValue = getUIDValidity(folder);        mInitialUIDNEXT = folder.getImapUIDNEXT();        // fetch visible items from database        List<ImapMessage> i4list;        if (isVirtual())            i4list = loadVirtualFolder(octxt, (SearchFolder) folder);        else            i4list = mbox.openImapFolder(octxt, folder.getId());        Collections.sort(i4list);        // check messages for imapUid <= 0 and assign new IMAP IDs if necessary        List<ImapMessage> unnumbered = new ArrayList<ImapMessage>();        List<Integer> renumber = new ArrayList<Integer>();        while (!i4list.isEmpty() && i4list.get(0).imapUid <= 0) {            ImapMessage i4msg = i4list.remove(0);            unnumbered.add(i4msg);  renumber.add(i4msg.msgId);        }        if (!renumber.isEmpty()) {            List<Integer> newIds = mbox.resetImapUid(octxt, renumber);            for (int i = 0; i < newIds.size(); i++)                unnumbered.get(i).imapUid = newIds.get(i);            i4list.addAll(unnumbered);        }        // and create our lists and hashes of items        StringBuilder added = debug ? new StringBuilder("  ** added: ") : null;        for (ImapMessage i4msg : i4list) {            cache(i4msg);            if (mFirstUnread == -1 && (i4msg.flags & Flag.BITMASK_UNREAD) != 0)                mFirstUnread = i4msg.sequence;            if (debug)  added.append(' ').append(i4msg.msgId);        }        if (debug)  ZimbraLog.imap.debug(added);        mLastSize = mSequence.size();        mSession = session;    }