public function link_callback($matches)
    {
        $i = -1;
        $scheme = strtolower($matches[1]);

        if (preg_match('!^(http|ftp|file)s?://!i', $scheme)) {
            $url = $matches[1] . $matches[2];
        }
        else if (preg_match("/^({$this->noword}*)(www\.)$/i", $matches[1], $m)) {
            $url        = $m[2] . $matches[2];
            $url_prefix = 'http://';
            $prefix     = $m[1];
        }

        if ($url) {
            $suffix = $this->parse_url_brackets($url);
            $attrib = (array)$this->options['link_attribs'];
            $attrib['href'] = $url_prefix . $url;

            $i = $this->add(html::a($attrib, rcube::Q($url)) . $suffix);
            $this->urls[$i] = $attrib['href'];
        }

        // Return valid link for recognized schemes, otherwise
        // return the unmodified string for unrecognized schemes.
        return $i >= 0 ? $prefix . $this->get_replacement($i) : $matches[0];
    }