protected function _scanStream($fp)
    {
        rewind($fp);

        stream_filter_register(
            'horde_mime_scan_stream',
            'Horde_Mime_Filter_Encoding'
        );
        $filter_params = new stdClass;
        $filter = stream_filter_append(
            $fp,
            'horde_mime_scan_stream',
            STREAM_FILTER_READ,
            $filter_params
        );

        while (!feof($fp)) {
            fread($fp, 8192);
        }

        stream_filter_remove($filter);

        return $filter_params->body;
    }