" WHERE " + (DebugConfig.enableMailboxGroup ? "mailbox_id = ? AND " : "") + "folder_id = ? AND type IN " + typeConstraint(type) +
" WHERE " + IN_THIS_MAILBOX_AND + "folder_id = ? AND type IN " + typeConstraint(type) +
    public static List<UnderlyingData> getByFolder(Folder folder, byte type, byte sort) throws ServiceException {        if (Mailbox.isCachedType(type))            throw ServiceException.INVALID_REQUEST("folders and tags must be retrieved from cache", null);        Mailbox mbox = folder.getMailbox();        Connection conn = mbox.getOperationConnection();        ArrayList<UnderlyingData> result = new ArrayList<UnderlyingData>();        PreparedStatement stmt = null;        ResultSet rs = null;        try {            stmt = conn.prepareStatement("SELECT " + DB_FIELDS +                    " FROM " + getMailItemTableName(folder.getMailboxId(), " mi") +                    " WHERE " +                    (DebugConfig.enableMailboxGroup ? "mailbox_id = ? AND " : "") +                    "folder_id = ? AND type IN " + typeConstraint(type) +                    sortQuery(sort));            int pos = 1;            if (DebugConfig.enableMailboxGroup)                stmt.setInt(pos++, mbox.getId());            stmt.setInt(pos++, folder.getId());            rs = stmt.executeQuery();            while (rs.next())                result.add(constructItem(rs));            return result;        } catch (SQLException e) {			throw ServiceException.FAILURE("fetching items in folder " + folder.getId(), e);        } finally {            DbPool.closeResults(rs);            DbPool.closeStatement(stmt);        }    }