Exemplo n.º 1
0
 internal BodyTextReader(ICoreItem coreItem, BodyReadConfiguration configuration, Stream inputStream)
 {
     using (DisposeGuard disposeGuard = this.Guard())
     {
         Stream     stream     = null;
         TextReader textReader = null;
         bool       flag       = false;
         this.disposeTracker = this.GetDisposeTracker();
         try
         {
             if (inputStream == null)
             {
                 stream      = BodyReadStream.OpenBodyStream(coreItem);
                 inputStream = stream;
             }
             if (inputStream == null)
             {
                 inputStream = Body.GetEmptyStream();
             }
             textReader = BodyReadDelegates.CreateReader(coreItem, configuration, inputStream, out this.conversionCallbacks);
             flag       = true;
         }
         finally
         {
             if (!flag && stream != null)
             {
                 stream.Dispose();
             }
         }
         this.reader     = textReader;
         this.bodyStream = stream;
         this.isDisposed = false;
         disposeGuard.Success();
     }
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private char[] LoadCachedBodyData(out MemoryStream htmlBody)
        {
            htmlBody = null;
            if (!this.coreItem.Body.IsBodyDefined)
            {
                return(null);
            }
            BodyReadConfiguration configuration = new BodyReadConfiguration(BodyFormat.TextPlain);

            if (this.coreItem.Body.RawFormat == BodyFormat.TextHtml)
            {
                htmlBody          = this.LoadHtmlBodyInMemory();
                htmlBody.Position = 0L;
                using (TextReader textReader = new BodyTextReader(this.coreItem, configuration, new StreamWrapper(htmlBody, false)))
                {
                    return(Util.StreamHandler.ReadCharBuffer(textReader, 16384));
                }
            }
            char[] result;
            using (TextReader textReader2 = new BodyTextReader(this.coreItem, configuration, null))
            {
                result = Util.StreamHandler.ReadCharBuffer(textReader2, 16384);
            }
            return(result);
        }
Exemplo n.º 4
0
        private static object FromRtfToRtf(ICoreItem coreItem, BodyReadConfiguration configuration, Stream bodyStream, bool createReader)
        {
            object obj    = null;
            Stream stream = null;

            try
            {
                stream = new ConverterStream(bodyStream, new RtfCompressedToRtf(), ConverterStreamAccess.Read);
                obj    = BodyReadDelegates.GetRtfStreamOrReader(stream, new RtfToRtf
                {
                    Header             = configuration.InjectPrefix,
                    Footer             = configuration.InjectSuffix,
                    HeaderFooterFormat = configuration.InjectionHeaderFooterFormat
                }, createReader);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    stream.Dispose();
                    stream = null;
                }
            }
            return(obj);
        }
Exemplo n.º 5
0
        internal static void CopyBodyWithPrefix(Body sourceBody, Body targetBody, ReplyForwardConfiguration configuration, BodyConversionCallbacks callbacks)
        {
            ReplyForwardCommon.CheckRtf(sourceBody.RawFormat, targetBody.RawFormat);
            BodyReadConfiguration  configuration2         = new BodyReadConfiguration(sourceBody.RawFormat, sourceBody.RawCharset.Name);
            BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(sourceBody.RawFormat, sourceBody.RawCharset.Name);

            bodyWriteConfiguration.SetTargetFormat(configuration.TargetFormat, sourceBody.Charset);
            if (!string.IsNullOrEmpty(configuration.BodyPrefix))
            {
                bodyWriteConfiguration.AddInjectedText(configuration.BodyPrefix, null, configuration.BodyPrefixFormat);
            }
            if (callbacks.HtmlCallback != null || callbacks.RtfCallback != null)
            {
                bodyWriteConfiguration.HtmlCallback = callbacks.HtmlCallback;
                bodyWriteConfiguration.RtfCallback  = callbacks.RtfCallback;
                if (!configuration.ShouldSkipFilterHtmlOnBodyWrite)
                {
                    bodyWriteConfiguration.HtmlFlags = HtmlStreamingFlags.FilterHtml;
                }
            }
            using (Stream stream = sourceBody.OpenReadStream(configuration2))
            {
                using (Stream stream2 = targetBody.OpenWriteStream(bodyWriteConfiguration))
                {
                    Util.StreamHandler.CopyStreamData(stream, stream2);
                }
            }
        }
Exemplo n.º 6
0
        public byte[] GetPartialRtfCompressedBody(int nBytes)
        {
            BodyReadConfiguration configuration = new BodyReadConfiguration(BodyFormat.ApplicationRtf);

            byte[] result;
            using (Stream stream = this.OpenReadStream(configuration))
            {
                byte[] array = new byte[nBytes];
                int    num;
                int    num2;
                for (num = 0; num != nBytes; num += num2)
                {
                    num2 = stream.Read(array, num, nBytes - num);
                    if (num2 == 0)
                    {
                        break;
                    }
                }
                if (num == nBytes)
                {
                    result = array;
                }
                else
                {
                    byte[] array2 = new byte[num];
                    Array.Copy(array, array2, num);
                    result = array2;
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        private static void InternalCopyBody(Body source, Body target, CultureInfo cultureInfo, bool removeMungageData, string prefix, BodyInjectionFormat prefixFormat, bool disableCharsetDetection = false)
        {
            BodyReadConfiguration  bodyReadConfiguration  = new BodyReadConfiguration(source.RawFormat, source.RawCharset.Name);
            BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(source.RawFormat, source.RawCharset.Name);

            if (disableCharsetDetection)
            {
                bodyWriteConfiguration.SetTargetFormat(source.RawFormat, source.Charset, BodyCharsetFlags.DisableCharsetDetection);
            }
            else
            {
                bodyWriteConfiguration.SetTargetFormat(source.RawFormat, source.Charset);
            }
            if (!string.IsNullOrEmpty(prefix))
            {
                bodyWriteConfiguration.AddInjectedText(prefix, null, prefixFormat);
            }
            bool flag = false;

            if (removeMungageData)
            {
                flag = Body.CopyBodyWithoutMungage(source, target, cultureInfo, bodyReadConfiguration, bodyWriteConfiguration);
            }
            if (!flag)
            {
                using (Stream stream = source.OpenReadStream(bodyReadConfiguration))
                {
                    using (Stream stream2 = target.OpenWriteStream(bodyWriteConfiguration))
                    {
                        Util.StreamHandler.CopyStreamData(stream, stream2, null, 0, 16384);
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void BuildMeetingMessageBody(BodyConversionCallbacks callbacks)
        {
            BodyReadConfiguration  configuration          = new BodyReadConfiguration(this.originalItem.Body.RawFormat);
            BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(this.originalItem.Body.RawFormat);

            bodyWriteConfiguration.SetTargetFormat(this.parameters.TargetFormat, this.originalItem.Body.Charset);
            if (!string.IsNullOrEmpty(this.parameters.BodyPrefix))
            {
                bodyWriteConfiguration.AddInjectedText(this.parameters.BodyPrefix, null, this.parameters.BodyPrefixFormat);
            }
            if (callbacks.HtmlCallback != null)
            {
                bodyWriteConfiguration.HtmlCallback = callbacks.HtmlCallback;
                bodyWriteConfiguration.HtmlFlags    = HtmlStreamingFlags.FilterHtml;
            }
            if (callbacks.RtfCallback != null)
            {
                bodyWriteConfiguration.RtfCallback = callbacks.RtfCallback;
            }
            using (TextReader textReader = this.originalItem.Body.OpenTextReader(configuration))
            {
                using (TextWriter textWriter = this.newItem.Body.OpenTextWriter(bodyWriteConfiguration))
                {
                    Util.StreamHandler.CopyText(textReader, textWriter);
                }
            }
        }
Exemplo n.º 9
0
 private static object FromTextToRtf(ICoreItem coreItem, BodyReadConfiguration configuration, Stream bodyStream, bool createReader)
 {
     return(BodyReadDelegates.GetRtfStreamOrReader(bodyStream, new TextToRtf
     {
         InputEncoding = ConvertUtils.UnicodeEncoding,
         Header = configuration.InjectPrefix,
         Footer = configuration.InjectSuffix,
         HeaderFooterFormat = configuration.InjectionHeaderFooterFormat
     }, createReader));
 }
Exemplo n.º 10
0
        internal static TextReader CreateReader(ICoreItem coreItem, BodyReadConfiguration configuration, Stream bodyStream, out ConversionCallbackBase provider)
        {
            BodyReadConfiguration readerConfiguration = new BodyReadConfiguration(configuration);

            readerConfiguration.Charset = ConvertUtils.UnicodeCharset;
            provider = BodyReadDelegates.CreateConversionDelegateProvider(coreItem, readerConfiguration);
            return(ConvertUtils.CallCtsWithReturnValue <TextReader>(ExTraceGlobals.CcBodyTracer, "BodyReadDelegates::CreateReader", ServerStrings.ConversionBodyConversionFailed, delegate
            {
                BodyReadDelegates.ConversionCreator conversionMethod = BodyReadDelegates.GetConversionMethod(coreItem, configuration);
                return (TextReader)conversionMethod(coreItem, readerConfiguration, bodyStream, true);
            }));
        }
Exemplo n.º 11
0
        internal static BodyReadStream TryCreateBodyReadStream(ICoreItem coreItem, BodyReadConfiguration configuration, bool createEmtpyStreamIfNotFound)
        {
            BodyReadStream bodyReadStream = BodyReadStream.InternalTryCreateBodyStream(coreItem, configuration, createEmtpyStreamIfNotFound, null);

            if (configuration.ShouldCalculateLength)
            {
                long streamLength = BodyReadStream.GetStreamLength(bodyReadStream);
                bodyReadStream.Dispose();
                bodyReadStream = BodyReadStream.InternalTryCreateBodyStream(coreItem, configuration, createEmtpyStreamIfNotFound, new long?(streamLength));
            }
            return(bodyReadStream);
        }
Exemplo n.º 12
0
 public override void Export(ContactWriter writer, Contact contact, OutboundVCardConverter.PropertyExporter.Context context)
 {
     if (contact.Body.IsBodyDefined)
     {
         BodyReadConfiguration configuration = new BodyReadConfiguration(BodyFormat.TextPlain, context.Encoding.WebName);
         using (Stream stream = contact.Body.OpenReadStream(configuration))
         {
             writer.StartProperty(PropertyId.Note);
             writer.WritePropertyValue(stream);
         }
     }
 }
Exemplo n.º 13
0
        public string GetPartialTextBody(int length)
        {
            BodyReadConfiguration configuration = new BodyReadConfiguration(BodyFormat.TextPlain);
            string result;

            using (TextReader textReader = this.OpenTextReader(configuration))
            {
                char[] array   = new char[length];
                int    length2 = Body.ReadChars(textReader, array, length);
                result = new string(array, 0, length2);
            }
            return(result);
        }
Exemplo n.º 14
0
        protected override void BuildBody(BodyConversionCallbacks callbacks)
        {
            BodyReadConfiguration  configuration          = new BodyReadConfiguration(this.template.Body.RawFormat, this.template.Body.RawCharset.Name);
            BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(this.template.Body.RawFormat, this.template.Body.RawCharset.Name);

            bodyWriteConfiguration.SetTargetFormat(this.template.Body.Format, this.template.Body.Charset);
            using (Stream stream = this.template.Body.OpenReadStream(configuration))
            {
                using (Stream stream2 = this.newItem.Body.OpenWriteStream(bodyWriteConfiguration))
                {
                    Util.StreamHandler.CopyStreamData(stream, stream2);
                }
            }
        }
Exemplo n.º 15
0
 private static object FromTextToHtml(ICoreItem coreItem, BodyReadConfiguration configuration, Stream bodyStream, bool createReader)
 {
     return(BodyReadDelegates.GetTextStreamOrReader(bodyStream, new TextToHtml
     {
         InputEncoding = ConvertUtils.UnicodeEncoding,
         OutputEncoding = configuration.Encoding,
         Header = configuration.InjectPrefix,
         Footer = configuration.InjectSuffix,
         HeaderFooterFormat = configuration.InjectionHeaderFooterFormat,
         HtmlTagCallback = configuration.InternalHtmlTagCallback,
         FilterHtml = configuration.FilterHtml,
         OutputHtmlFragment = configuration.IsHtmlFragment
     }, createReader));
 }
Exemplo n.º 16
0
        private Stream InternalOpenReadStream(BodyReadConfiguration configuration, bool createEmptyStreamIfNotFound)
        {
            Body.CheckNull(configuration, "configuration");
            this.CheckStreamingExceptions();
            Stream result;

            lock (this.bodyStreamsLock)
            {
                this.CheckOpenBodyStreamForRead();
                BodyReadStream bodyReadStream = BodyReadStream.TryCreateBodyReadStream(this.coreItem, configuration, createEmptyStreamIfNotFound);
                this.bodyReadStreams.Add(bodyReadStream);
                result = bodyReadStream;
            }
            return(result);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        internal ConversationBodyTextReader OpenConversationTextReader(BodyReadConfiguration configuration, long bytesLoadedForConversation, long maxBytesForConversation)
        {
            Body.CheckNull(configuration, "configuration");
            this.CheckStreamingExceptions();
            ConversationBodyTextReader result;

            lock (this.bodyStreamsLock)
            {
                this.CheckOpenBodyStreamForRead();
                ConversationBodyTextReader conversationBodyTextReader = new ConversationBodyTextReader(this.coreItem, configuration, null, bytesLoadedForConversation, maxBytesForConversation);
                this.bodyReadStreams.Add(conversationBodyTextReader);
                result = conversationBodyTextReader;
            }
            return(result);
        }
Exemplo n.º 19
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));
        }
Exemplo n.º 20
0
        public TextReader OpenTextReader(BodyReadConfiguration configuration)
        {
            Body.CheckNull(configuration, "configuration");
            this.CheckStreamingExceptions();
            TextReader result;

            lock (this.bodyStreamsLock)
            {
                this.CheckOpenBodyStreamForRead();
                BodyTextReader bodyTextReader = new BodyTextReader(this.coreItem, configuration, null);
                this.bodyReadStreams.Add(bodyTextReader);
                result = bodyTextReader;
            }
            return(result);
        }
Exemplo n.º 21
0
 internal BodyReadConfiguration(BodyReadConfiguration configuration)
 {
     this.format                = configuration.format;
     this.charset               = configuration.charset;
     this.injectPrefix          = configuration.injectPrefix;
     this.injectSuffix          = configuration.injectSuffix;
     this.injectFormat          = configuration.injectFormat;
     this.conversionCallback    = configuration.conversionCallback;
     this.htmlFlags             = configuration.htmlFlags;
     this.styleSheetLimit       = configuration.styleSheetLimit;
     this.shouldCalculateLength = configuration.shouldCalculateLength;
     this.ShouldUseNarrowGapForPTagHtmlToTextConversion = configuration.ShouldUseNarrowGapForPTagHtmlToTextConversion;
     this.ShouldOutputAnchorLinks = configuration.ShouldOutputAnchorLinks;
     this.ShouldOutputImageLinks  = configuration.ShouldOutputImageLinks;
 }
Exemplo n.º 22
0
        private void AddBodyPrefix(string prefix)
        {
            byte[] array = null;
            BodyReadConfiguration configuration = new BodyReadConfiguration(base.Body.RawFormat, base.Body.RawCharset.Name);

            using (Stream stream = base.Body.OpenReadStream(configuration))
            {
                array = Util.StreamHandler.ReadBytesFromStream(stream);
            }
            BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(base.Body.RawFormat, base.Body.RawCharset.Name);

            bodyWriteConfiguration.SetTargetFormat(base.Body.Format, base.Body.Charset);
            bodyWriteConfiguration.AddInjectedText(prefix, null, BodyInjectionFormat.Text);
            using (Stream stream2 = base.Body.OpenWriteStream(bodyWriteConfiguration))
            {
                stream2.Write(array, 0, array.Length);
            }
        }
Exemplo n.º 23
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));
        }
Exemplo n.º 24
0
        internal static Stream CreateStream(ICoreItem coreItem, BodyReadConfiguration configuration, Stream bodyStream, out ConversionCallbackBase provider)
        {
            BodyReadConfiguration readConfiguration = new BodyReadConfiguration(configuration);

            provider = BodyReadDelegates.CreateConversionDelegateProvider(coreItem, readConfiguration);
            if (readConfiguration.Charset == null)
            {
                readConfiguration.Charset = ConvertUtils.GetItemMimeCharset(coreItem.PropertyBag);
            }
            if (!readConfiguration.IsBodyTransformationNeeded(coreItem.Body))
            {
                return(bodyStream);
            }
            return(ConvertUtils.CallCtsWithReturnValue <Stream>(ExTraceGlobals.CcBodyTracer, "BodyReadDelegates::CreateStream", ServerStrings.ConversionBodyConversionFailed, delegate
            {
                BodyReadDelegates.ConversionCreator conversionMethod = BodyReadDelegates.GetConversionMethod(coreItem, configuration);
                return (Stream)conversionMethod(coreItem, readConfiguration, bodyStream, false);
            }));
        }
Exemplo n.º 25
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));
        }
Exemplo n.º 26
0
        private static object FromTextToText(ICoreItem coreItem, BodyReadConfiguration configuration, Stream bodyStream, bool createReader)
        {
            TextToText textToText;

            if (string.IsNullOrEmpty(configuration.InjectPrefix) && string.IsNullOrEmpty(configuration.InjectSuffix))
            {
                textToText = new TextToText(TextToTextConversionMode.ConvertCodePageOnly);
            }
            else
            {
                textToText = new TextToText();
            }
            textToText.InputEncoding  = ConvertUtils.UnicodeEncoding;
            textToText.OutputEncoding = configuration.Encoding;
            if (!string.IsNullOrEmpty(configuration.InjectPrefix) || !string.IsNullOrEmpty(configuration.InjectSuffix))
            {
                textToText.Header             = configuration.InjectPrefix;
                textToText.Footer             = configuration.InjectSuffix;
                textToText.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat;
            }
            return(BodyReadDelegates.GetTextStreamOrReader(bodyStream, textToText, createReader));
        }
Exemplo n.º 27
0
        private void WriteMessageBody()
        {
            if (this.options.FilterBodyHandler != null && !this.options.FilterBodyHandler(this.item))
            {
                return;
            }
            this.limitsTracker.CountMessageBody();
            BodyFormat rawFormat = this.item.Body.RawFormat;

            if (rawFormat == BodyFormat.TextHtml)
            {
                this.WriteProperty(InternalSchema.HtmlBody, this.item.PropertyBag);
                return;
            }
            this.WriteProperty(InternalSchema.RtfSyncBodyCrc, this.item.PropertyBag);
            this.WriteProperty(InternalSchema.RtfSyncBodyCount, this.item.PropertyBag);
            this.WriteProperty(InternalSchema.RtfSyncBodyTag, this.item.PropertyBag);
            this.WriteProperty(InternalSchema.RtfInSync, this.item.PropertyBag);
            this.WriteProperty(InternalSchema.RtfSyncPrefixCount, this.item.PropertyBag);
            this.WriteProperty(InternalSchema.RtfSyncTrailingCount, this.item.PropertyBag);
            if (!this.item.Body.IsBodyDefined)
            {
                return;
            }
            if (rawFormat == BodyFormat.TextPlain)
            {
                this.WriteProperty(InternalSchema.TextBody, this.item.PropertyBag);
            }
            BodyReadConfiguration configuration = new BodyReadConfiguration(BodyFormat.ApplicationRtf);

            using (Stream stream = this.item.Body.OpenReadStream(configuration))
            {
                using (Stream stream2 = this.PropertyWriter.OpenPropertyStream(TnefPropertyTag.RtfCompressed))
                {
                    Util.StreamHandler.CopyStreamData(stream, stream2);
                }
            }
        }
Exemplo n.º 28
0
        private static bool CopyBodyWithoutMungage(Body source, Body target, CultureInfo cultureInfo, BodyReadConfiguration readConfiguration, BodyWriteConfiguration writeConfiguration)
        {
            bool result = false;

            switch (source.RawFormat)
            {
            case BodyFormat.TextPlain:
            {
                bool flag = true;
                goto IL_2B;
            }

            case BodyFormat.ApplicationRtf:
            {
                bool flag = false;
                goto IL_2B;
            }
            }
            return(false);

IL_2B:
            using (Stream stream = source.OpenReadStream(readConfiguration))
            {
                Stream stream2 = null;
                try
                {
                    bool flag;
                    stream2 = (flag ? stream : new ConverterStream(stream, new RtfCompressedToRtf(), ConverterStreamAccess.Read));
                    byte[] array = new byte[16384];
                    int    num   = stream2.Read(array, 0, array.Length);
                    if (num > 0)
                    {
                        string @string = readConfiguration.Encoding.GetString(array, 0, num);
                        string pattern = string.Format("{0}[\\s\\S]+(^.*{1}[\\s\\S]+)?^.*\\*~\\*~\\*~\\*~\\*~\\*~\\*~\\*~\\*~\\*(\\\\line)?\\r\\n", Regex.Escape(ClientStrings.WhenPart.ToString(cultureInfo)), Regex.Escape(ClientStrings.WherePart.ToString(cultureInfo)));
                        Match  match   = Regex.Match(@string, pattern, RegexOptions.Multiline);
                        if (match.Success)
                        {
                            string s     = @string.Remove(match.Index, match.Length);
                            byte[] bytes = writeConfiguration.SourceEncoding.GetBytes(s);
                            using (Stream stream3 = target.OpenWriteStream(writeConfiguration))
                            {
                                Stream stream4 = null;
                                try
                                {
                                    stream4 = (flag ? stream3 : new ConverterStream(stream3, new RtfToRtfCompressed(), ConverterStreamAccess.Write));
                                    stream4.Write(bytes, 0, bytes.Length);
                                    if (num == array.Length)
                                    {
                                        Util.StreamHandler.CopyStreamData(stream2, stream4, null, 0, 16384);
                                    }
                                    result = true;
                                }
                                finally
                                {
                                    if (!flag && stream4 != null)
                                    {
                                        stream4.Dispose();
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    bool flag;
                    if (!flag && stream2 != null)
                    {
                        stream2.Dispose();
                    }
                }
            }
            return(result);
        }
Exemplo n.º 29
0
 internal Stream TryOpenReadStream(BodyReadConfiguration configuration)
 {
     return(this.InternalOpenReadStream(configuration, false));
 }
Exemplo n.º 30
0
        public TextReader OpenTextReader(BodyFormat bodyFormat)
        {
            BodyReadConfiguration configuration = new BodyReadConfiguration(bodyFormat);

            return(this.OpenTextReader(configuration));
        }