" WHERE " + (DebugConfig.enableMailboxGroup ? "mailbox_id = ? AND " : "") + "unread > 0 AND " + relation + " AND type NOT IN " + NON_SEARCHABLE_TYPES);
" WHERE " + IN_THIS_MAILBOX_AND + "unread > 0 AND " + relation + " AND type NOT IN " + NON_SEARCHABLE_TYPES);
    public static List<UnderlyingData> getUnreadMessages(MailItem relativeTo) throws ServiceException {        Mailbox mbox = relativeTo.getMailbox();        Connection conn = mbox.getOperationConnection();        ArrayList<UnderlyingData> result = new ArrayList<UnderlyingData>();        PreparedStatement stmt = null;        ResultSet rs = null;        try {            String relation;            if (relativeTo instanceof VirtualConversation)  relation = " id = ?";            else if (relativeTo instanceof Conversation)    relation = " parent_id = ?";            else if (relativeTo instanceof Folder)          relation = " folder_id = ?";            else if (relativeTo instanceof Flag)            relation = " flags & ?";            else if (relativeTo instanceof Tag)             relation = " tags & ?";            else                                            relation = " id = ?";            stmt = conn.prepareStatement("SELECT " + DB_FIELDS +                    " FROM " + getMailItemTableName(relativeTo.getMailboxId(), " mi") +                    " WHERE " +                    (DebugConfig.enableMailboxGroup ? "mailbox_id = ? AND " : "") +                    "unread > 0 AND " + relation + " AND type NOT IN " + NON_SEARCHABLE_TYPES);            int pos = 1;            if (DebugConfig.enableMailboxGroup)                stmt.setInt(pos++, mbox.getId());            if (relativeTo instanceof Tag)                stmt.setLong(pos++, ((Tag) relativeTo).getBitmask());            else if (relativeTo instanceof VirtualConversation)                stmt.setInt(pos++, ((VirtualConversation) relativeTo).getMessageId());            else                stmt.setInt(pos++, relativeTo.getId());            rs = stmt.executeQuery();            while (rs.next()) {                UnderlyingData data = constructItem(rs);                if (Mailbox.isCachedType(data.type))                    throw ServiceException.INVALID_REQUEST("folders and tags must be retrieved from cache", null);                result.add(data);            }            return result;        } catch (SQLException e) {            throw ServiceException.FAILURE("fetching unread messages for item " + relativeTo.getId(), e);        } finally {            DbPool.closeResults(rs);            DbPool.closeStatement(stmt);        }    }