// Token: 0x06000128 RID: 296 RVA: 0x00004FB0 File Offset: 0x000031B0
        internal static Stream GetFilteredStream(ConfigurationContextBase configurationContext, Stream inputStream, Charset charset, BlockStatus blockStatus)
        {
            HtmlToHtml htmlToHtml = new HtmlToHtml();

            TextConvertersInternalHelpers.SetPreserveDisplayNoneStyle(htmlToHtml, true);
            WebBeaconFilterLevels filterWebBeaconsAndHtmlForms = configurationContext.FilterWebBeaconsAndHtmlForms;
            bool     flag     = filterWebBeaconsAndHtmlForms == WebBeaconFilterLevels.DisableFilter || blockStatus == BlockStatus.NoNeverAgain;
            Encoding encoding = null;

            if (charset != null && charset.TryGetEncoding(out encoding))
            {
                htmlToHtml.DetectEncodingFromMetaTag = false;
                htmlToHtml.InputEncoding             = encoding;
                htmlToHtml.OutputEncoding            = encoding;
            }
            else
            {
                htmlToHtml.DetectEncodingFromMetaTag = true;
                htmlToHtml.InputEncoding             = Encoding.ASCII;
                htmlToHtml.OutputEncoding            = null;
            }
            htmlToHtml.FilterHtml = true;
            if (!flag)
            {
                htmlToHtml.HtmlTagCallback = new HtmlTagCallback(AttachmentUtilities.webBeaconFilter.ProcessTag);
            }
            return(new ConverterStream(inputStream, htmlToHtml, ConverterStreamAccess.Read));
        }
예제 #2
0
 private void ChooseBestBody()
 {
     if (this.bodyFormat != -1)
     {
         return;
     }
     this.CalculateRawFormat();
     this.bodyFormat          = this.rawBodyFormat;
     this.isEmbeddedPlainText = false;
     if (this.bodyFormat == 3)
     {
         ConvertUtils.CallCts(ExTraceGlobals.CcBodyTracer, "Body.ChooseBestBody", ServerStrings.ConversionBodyConversionFailed, delegate
         {
             using (Stream stream = this.coreItem.PropertyBag.OpenPropertyStream(InternalSchema.RtfBody, PropertyOpenMode.ReadOnly))
             {
                 using (Stream stream2 = new ConverterStream(stream, new RtfCompressedToRtf(), ConverterStreamAccess.Read))
                 {
                     using (Stream stream3 = TextConvertersInternalHelpers.CreateRtfPreviewStream(stream2, 4096))
                     {
                         if (TextConvertersInternalHelpers.RtfHasEncapsulatedText(stream3))
                         {
                             this.bodyFormat          = 1;
                             this.isEmbeddedPlainText = true;
                             this.bodyFormatDecision  = 31;
                             ExTraceGlobals.CcBodyTracer.TraceDebug <BodyFormat, bool, int>((long)this.GetHashCode(), "Body.ChooseBestBody: BodyFormat={0}, missing={1}, decision point={2}", BodyFormat.TextPlain, false, this.bodyFormatDecision);
                         }
                     }
                 }
             }
         });
     }
 }
예제 #3
0
        private static object FromRtfToHtml(ICoreItem coreItem, BodyReadConfiguration configuration, Stream bodyStream, bool createReader)
        {
            object obj    = null;
            Stream stream = null;

            try
            {
                stream = new ConverterStream(bodyStream, new RtfCompressedToRtf(), ConverterStreamAccess.Read);
                RtfToHtml rtfToHtml = new RtfToHtml();
                rtfToHtml.OutputEncoding     = configuration.Encoding;
                rtfToHtml.Header             = configuration.InjectPrefix;
                rtfToHtml.Footer             = configuration.InjectSuffix;
                rtfToHtml.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat;
                rtfToHtml.FilterHtml         = configuration.FilterHtml;
                rtfToHtml.HtmlTagCallback    = configuration.InternalHtmlTagCallback;
                rtfToHtml.OutputHtmlFragment = configuration.IsHtmlFragment;
                if (configuration.StyleSheetLimit != null)
                {
                    TextConvertersInternalHelpers.SetSmallCssBlockThreshold(rtfToHtml, configuration.StyleSheetLimit.Value);
                }
                obj = BodyReadDelegates.GetTextStreamOrReader(stream, rtfToHtml, createReader);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    stream.Dispose();
                    stream = null;
                }
            }
            return(obj);
        }
예제 #4
0
        internal static bool IsSafeUrl(string urlString, HttpRequest httpRequest)
        {
            if (string.IsNullOrEmpty(urlString))
            {
                return(false);
            }
            Uri uri;

            if (null == (uri = Utilities.TryParseUri(urlString)))
            {
                return(false);
            }
            string scheme = uri.Scheme;

            if (string.IsNullOrEmpty(scheme))
            {
                return(false);
            }
            if (!Uri.CheckSchemeName(scheme) || !TextConvertersInternalHelpers.IsUrlSchemaSafe(scheme))
            {
                return(false);
            }
            if (Redir.IsHttpOrHttps(scheme))
            {
                string text = httpRequest.ServerVariables["HTTP_HOST"];
                return(!string.IsNullOrEmpty(text) && Redir.CheckHostNameWithHttpHost(urlString, uri, text));
            }
            return(true);
        }
예제 #5
0
        private static object FromHtmlToRtf(ICoreItem coreItem, BodyReadConfiguration configuration, Stream bodyStream, bool createReader)
        {
            HtmlToRtf htmlToRtf = new HtmlToRtf();

            htmlToRtf.InputEncoding             = ConvertUtils.GetItemMimeCharset(coreItem.PropertyBag).GetEncoding();
            htmlToRtf.DetectEncodingFromMetaTag = false;
            htmlToRtf.Header             = configuration.InjectPrefix;
            htmlToRtf.Footer             = configuration.InjectSuffix;
            htmlToRtf.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat;
            if (configuration.ImageRenderingCallback != null)
            {
                TextConvertersInternalHelpers.SetImageRenderingCallback(htmlToRtf, configuration.ImageRenderingCallback);
            }
            return(BodyReadDelegates.GetRtfStreamOrReader(bodyStream, htmlToRtf, createReader));
        }
예제 #6
0
        internal static bool IsSafeUrl(string urlString)
        {
            if (string.IsNullOrEmpty(urlString))
            {
                return(false);
            }
            Uri uri;

            if (null == (uri = UrlUtilities.TryParseUri(urlString)))
            {
                return(false);
            }
            string scheme = uri.Scheme;

            return(!string.IsNullOrEmpty(scheme) && Uri.CheckSchemeName(scheme) && TextConvertersInternalHelpers.IsUrlSchemaSafe(scheme));
        }
예제 #7
0
        private static object FromHtmlToRtf(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                stream = new ConverterStream(bodyStream, new RtfToRtfCompressed(), ConverterStreamAccess.Write);
                stream = new BodyCharsetDetectionStream(stream, null, coreItem, BodyStreamFormat.RtfUncompressed, null, configuration.TargetCharset, configuration.TargetCharsetFlags, null, false);
                HtmlToRtf htmlToRtf = new HtmlToRtf();
                htmlToRtf.InputEncoding             = configuration.SourceEncoding;
                htmlToRtf.DetectEncodingFromMetaTag = false;
                htmlToRtf.Header             = configuration.InjectPrefix;
                htmlToRtf.Footer             = configuration.InjectSuffix;
                htmlToRtf.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat;
                if (configuration.ImageRenderingCallback != null)
                {
                    TextConvertersInternalHelpers.SetImageRenderingCallback(htmlToRtf, configuration.ImageRenderingCallback);
                }
                TextConverter converter = htmlToRtf;
                if (configuration.FilterHtml || configuration.InternalHtmlTagCallback != null)
                {
                    stream    = new ConverterStream(stream, htmlToRtf, ConverterStreamAccess.Write);
                    converter = new HtmlToHtml
                    {
                        InputEncoding             = configuration.SourceEncoding,
                        OutputEncoding            = configuration.SourceEncoding,
                        DetectEncodingFromMetaTag = false,
                        FilterHtml      = configuration.FilterHtml,
                        HtmlTagCallback = configuration.InternalHtmlTagCallback
                    };
                }
                obj = BodyWriteDelegates.GetConverterStreamOrWriter(stream, converter, createWriter);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
예제 #8
0
        private static object FromHtmlToText(ICoreItem coreItem, BodyReadConfiguration configuration, Stream bodyStream, bool createReader)
        {
            HtmlToText htmlToText = new HtmlToText();

            htmlToText.InputEncoding             = ConvertUtils.GetItemMimeCharset(coreItem.PropertyBag).GetEncoding();
            htmlToText.OutputEncoding            = configuration.Encoding;
            htmlToText.DetectEncodingFromMetaTag = false;
            htmlToText.Header             = configuration.InjectPrefix;
            htmlToText.Footer             = configuration.InjectSuffix;
            htmlToText.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat;
            htmlToText.ShouldUseNarrowGapForPTagHtmlToTextConversion = configuration.ShouldUseNarrowGapForPTagHtmlToTextConversion;
            htmlToText.OutputAnchorLinks = configuration.ShouldOutputAnchorLinks;
            htmlToText.OutputImageLinks  = configuration.ShouldOutputImageLinks;
            if (configuration.ImageRenderingCallback != null)
            {
                TextConvertersInternalHelpers.SetImageRenderingCallback(htmlToText, configuration.ImageRenderingCallback);
            }
            return(BodyReadDelegates.GetTextStreamOrReader(bodyStream, htmlToText, createReader));
        }
예제 #9
0
        private static object FromHtmlToHtml(ICoreItem coreItem, BodyReadConfiguration configuration, Stream bodyStream, bool createReader)
        {
            Charset    itemMimeCharset = ConvertUtils.GetItemMimeCharset(coreItem.PropertyBag);
            Charset    charset         = configuration.Charset;
            HtmlToHtml htmlToHtml      = new HtmlToHtml();

            htmlToHtml.InputEncoding             = itemMimeCharset.GetEncoding();
            htmlToHtml.OutputEncoding            = charset.GetEncoding();
            htmlToHtml.Header                    = configuration.InjectPrefix;
            htmlToHtml.Footer                    = configuration.InjectSuffix;
            htmlToHtml.HeaderFooterFormat        = configuration.InjectionHeaderFooterFormat;
            htmlToHtml.DetectEncodingFromMetaTag = false;
            htmlToHtml.FilterHtml                = configuration.FilterHtml;
            htmlToHtml.HtmlTagCallback           = configuration.InternalHtmlTagCallback;
            htmlToHtml.OutputHtmlFragment        = configuration.IsHtmlFragment;
            if (configuration.StyleSheetLimit != null)
            {
                TextConvertersInternalHelpers.SetSmallCssBlockThreshold(htmlToHtml, configuration.StyleSheetLimit.Value);
            }
            return(BodyReadDelegates.GetTextStreamOrReader(bodyStream, htmlToHtml, createReader));
        }
예제 #10
0
        public static string SanitizeHtml(string unsafeHtml)
        {
            if (string.IsNullOrEmpty(unsafeHtml))
            {
                return(unsafeHtml);
            }
            string result;

            using (StringReader stringReader = new StringReader(unsafeHtml))
            {
                using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
                {
                    HtmlToHtml htmlToHtml = new HtmlToHtml();
                    TextConvertersInternalHelpers.SetPreserveDisplayNoneStyle(htmlToHtml, true);
                    htmlToHtml.InputEncoding  = Encoding.UTF8;
                    htmlToHtml.OutputEncoding = Encoding.UTF8;
                    htmlToHtml.FilterHtml     = true;
                    htmlToHtml.Convert(stringReader, stringWriter);
                    result = stringWriter.ToString();
                }
            }
            return(result);
        }
예제 #11
0
        public static string HtmlToText(string html, bool shouldUseNarrowGapForPTagHtmlToTextConversion)
        {
            if (string.IsNullOrEmpty(html))
            {
                return(html);
            }
            html = TextConverterHelper.RemoveHtmlLink(html);
            string result;

            using (StringReader stringReader = new StringReader(html))
            {
                using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
                {
                    HtmlToText htmlToText = new HtmlToText();
                    htmlToText.InputEncoding  = Encoding.UTF8;
                    htmlToText.OutputEncoding = Encoding.UTF8;
                    htmlToText.ShouldUseNarrowGapForPTagHtmlToTextConversion = shouldUseNarrowGapForPTagHtmlToTextConversion;
                    TextConvertersInternalHelpers.SetImageRenderingCallback(htmlToText, new ImageRenderingCallback(TextConverterHelper.RemoveImageCallback));
                    htmlToText.Convert(stringReader, stringWriter);
                    result = stringWriter.ToString();
                }
            }
            return(result);
        }