コード例 #1
0
 public void SetHtmlOptions(HtmlStreamingFlags flags, HtmlCallbackBase callback)
 {
     EnumValidator.ThrowIfInvalid <HtmlStreamingFlags>(flags, "flags");
     if (this.targetFormat != BodyFormat.TextHtml && this.sourceFormat != BodyFormat.TextHtml)
     {
         throw new InvalidOperationException("BodyReadConfiguration.SetHtmlOptions - neither source not target format is HTML");
     }
     this.htmlFlags = flags;
     this.conversionCallbacks.HtmlCallback = callback;
 }
コード例 #2
0
 public void SetHtmlOptions(HtmlStreamingFlags flags, HtmlCallbackBase callback, int?styleSheetLimit)
 {
     EnumValidator.ThrowIfInvalid <HtmlStreamingFlags>(flags, "flags");
     if (this.Format != BodyFormat.TextHtml)
     {
         throw new InvalidOperationException("BodyReadConfiguration.SetHtmlOptions - target format is not HTML");
     }
     this.htmlFlags          = flags;
     this.conversionCallback = callback;
     this.styleSheetLimit    = styleSheetLimit;
 }
コード例 #3
0
        public string GetPartialHtmlBody(int length, HtmlCallbackBase htmlCallbacks, bool filterHtml, int styleSheetLimit)
        {
            BodyReadConfiguration bodyReadConfiguration = new BodyReadConfiguration(BodyFormat.TextHtml);

            bodyReadConfiguration.SetHtmlOptions(filterHtml ? HtmlStreamingFlags.FilterHtml : HtmlStreamingFlags.None, htmlCallbacks, new int?(styleSheetLimit));
            string result;

            using (TextReader textReader = this.OpenTextReader(bodyReadConfiguration))
            {
                char[] array   = new char[length];
                int    length2 = Body.ReadChars(textReader, array, length);
                result = new string(array, 0, length2);
            }
            return(result);
        }
コード例 #4
0
        public ConversationBodyScanner GetConversationBodyScanner(HtmlCallbackBase callback, long maxBytes, long bytesLoaded, bool fixCharset, bool filterHtml, out long bytesRead)
        {
            ConversationBodyScanner conversationBodyScanner = null;
            StorePropertyDefinition bodyProperty            = null;
            BodyFormat bodyFormat;

            if (fixCharset)
            {
                bodyFormat = this.RawFormat;
            }
            else
            {
                bodyFormat = this.Format;
            }
            switch (bodyFormat)
            {
            case BodyFormat.TextPlain:
            {
                TextConversationBodyScanner textConversationBodyScanner = new TextConversationBodyScanner();
                conversationBodyScanner = textConversationBodyScanner;
                if (fixCharset)
                {
                    textConversationBodyScanner.InputEncoding = ConvertUtils.UnicodeEncoding;
                }
                else
                {
                    textConversationBodyScanner.InputEncoding = this.GetBodyEncoding();
                }
                if (this.IsRtfEmbeddedBody)
                {
                    bodyProperty = ItemSchema.RtfBody;
                }
                else
                {
                    bodyProperty = ItemSchema.TextBody;
                }
                break;
            }

            case BodyFormat.TextHtml:
            {
                HtmlConversationBodyScanner htmlConversationBodyScanner = new HtmlConversationBodyScanner();
                conversationBodyScanner = htmlConversationBodyScanner;
                htmlConversationBodyScanner.InputEncoding             = this.GetBodyEncoding();
                htmlConversationBodyScanner.DetectEncodingFromMetaTag = false;
                bodyProperty = ItemSchema.HtmlBody;
                break;
            }

            case BodyFormat.ApplicationRtf:
                conversationBodyScanner = new RtfConversationBodyScanner();
                bodyProperty            = ItemSchema.RtfBody;
                break;
            }
            conversationBodyScanner.FilterHtml = filterHtml;
            if (callback != null)
            {
                conversationBodyScanner.HtmlCallback = new HtmlTagCallback(callback.ProcessTag);
            }
            if (this.IsBodyDefined)
            {
                using (Stream stream = this.InternalOpenBodyStream(bodyProperty, PropertyOpenMode.ReadOnly))
                {
                    bytesRead = stream.Length;
                    if (maxBytes > -1L && bytesRead + bytesLoaded > maxBytes)
                    {
                        throw new MessageLoadFailedInConversationException(new LocalizedString("Message body size exceeded the conversation threshold for loading"));
                    }
                    if (this.RawFormat == BodyFormat.ApplicationRtf)
                    {
                        using (Stream stream2 = new ConverterStream(stream, new RtfCompressedToRtf(), ConverterStreamAccess.Read))
                        {
                            conversationBodyScanner.Load(stream2);
                            goto IL_12F;
                        }
                    }
                    conversationBodyScanner.Load(stream);
IL_12F:
                    return(conversationBodyScanner);
                }
            }
            bytesRead = 0L;
            MemoryStream sourceStream = new MemoryStream(0);

            conversationBodyScanner.Load(sourceStream);
            return(conversationBodyScanner);
        }
コード例 #5
0
 public void SetHtmlOptions(HtmlStreamingFlags flags, HtmlCallbackBase callback)
 {
     EnumValidator.ThrowIfInvalid <HtmlStreamingFlags>(flags, "flags");
     this.SetHtmlOptions(flags, callback, null);
 }