" WHERE " + (DebugConfig.enableMailboxGroup ? "mailbox_id = ? AND " : "") + "type IN " + typeConstraint(type) + sortQuery(sort));
" WHERE " + IN_THIS_MAILBOX_AND + "type IN " + typeConstraint(type) + sortQuery(sort));
    public static List<UnderlyingData> getByType(Mailbox mbox, byte type, byte sort) throws ServiceException {        if (Mailbox.isCachedType(type))            throw ServiceException.INVALID_REQUEST("folders and tags must be retrieved from cache", null);        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(mbox.getId(), " mi") +                    " WHERE " +                    (DebugConfig.enableMailboxGroup ? "mailbox_id = ? AND " : "") +                    "type IN " + typeConstraint(type) + sortQuery(sort));            if (DebugConfig.enableMailboxGroup)                stmt.setInt(1, mbox.getId());            rs = stmt.executeQuery();            while (rs.next())                result.add(constructItem(rs));            if (type == MailItem.TYPE_CONVERSATION)                completeConversations(mbox, result);            return result;        } catch (SQLException e) {        	throw ServiceException.FAILURE("fetching items of type " + type, e);        } finally {        	DbPool.closeResults(rs);            DbPool.closeStatement(stmt);        }    }