public static function message_search_users($userid, $search, $limitfrom = 0, $limitnum = 0) {
        global $USER;

        $systemcontext = context_system::instance();

        $params = array(
            'userid' => $userid,
            'search' => $search,
            'limitfrom' => $limitfrom,
            'limitnum' => $limitnum
        );
        $params = self::validate_parameters(self::message_search_users_parameters(), $params);
        self::validate_context($systemcontext);

        if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
            throw new moodle_exception('You do not have permission to perform this action.');
        }

        list($contacts, $noncontacts) = \core_message\api::message_search_users(
            $params['userid'],
            $params['search'],
            $params['limitfrom'],
            $params['limitnum']);

        return array('contacts' => $contacts, 'noncontacts' => $noncontacts);
    }