Beispiel #1
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);
                    }
                }
            }
        }
Beispiel #2
0
        private void SetBody()
        {
            Stream stream = null;

            try
            {
                Charset charset = null;
                Charset.TryGetCharset(this.internetCpid, out charset);
                string targetCharsetName = (charset != null) ? charset.Name : null;
                BodyWriteConfiguration bodyWriteConfiguration;
                if (this.isRtfBodyFound && (!this.isHtmlBodyFound || this.isRtfInSync))
                {
                    stream = this.InternalGetValueReadStream(TnefPropertyTag.RtfCompressed);
                    bodyWriteConfiguration = new BodyWriteConfiguration(BodyFormat.ApplicationRtf);
                    bodyWriteConfiguration.SetTargetFormat(BodyFormat.ApplicationRtf, targetCharsetName, BodyCharsetFlags.PreserveUnicode);
                }
                else if (this.isHtmlBodyFound)
                {
                    if (charset == null)
                    {
                        charset = Charset.DefaultWebCharset;
                    }
                    stream = this.InternalGetValueReadStream(TnefPropertyTag.BodyHtmlB);
                    bodyWriteConfiguration = new BodyWriteConfiguration(BodyFormat.TextHtml, charset.Name);
                    bodyWriteConfiguration.SetTargetFormat(BodyFormat.TextHtml, charset.Name, BodyCharsetFlags.PreserveUnicode);
                }
                else
                {
                    if (this.isTextBodyFound)
                    {
                        stream = this.InternalGetValueReadStream(TnefPropertyTag.BodyW);
                    }
                    bodyWriteConfiguration = new BodyWriteConfiguration(BodyFormat.TextPlain, ConvertUtils.UnicodeCharset.Name);
                    if (charset != null)
                    {
                        bodyWriteConfiguration.SetTargetFormat(BodyFormat.TextPlain, charset.Name);
                    }
                    bodyWriteConfiguration.SetTargetFormat(BodyFormat.TextPlain, targetCharsetName, BodyCharsetFlags.PreserveUnicode);
                }
                base.CoreItem.CharsetDetector.DetectionOptions = base.MessageWriter.ConversionOptions.DetectionOptions;
                using (Stream stream2 = base.CoreItem.Body.OpenWriteStream(bodyWriteConfiguration))
                {
                    if (stream != null)
                    {
                        Util.StreamHandler.CopyStreamData(stream, stream2);
                    }
                }
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }
        }
        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);
                }
            }
        }
        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);
                }
            }
        }
Beispiel #5
0
        protected override void BuildBody(BodyConversionCallbacks callbacks)
        {
            BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(base.Format);

            bodyWriteConfiguration.SetTargetFormat(this.parameters.TargetFormat, this.newItem.Body.Charset);
            if (!string.IsNullOrEmpty(this.parameters.BodyPrefix))
            {
                bodyWriteConfiguration.AddInjectedText(this.parameters.BodyPrefix, null, this.parameters.BodyPrefixFormat);
            }
            using (this.newItem.Body.OpenTextWriter(bodyWriteConfiguration))
            {
            }
        }
        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);
                }
            }
        }
Beispiel #7
0
        protected virtual bool PromoteComplexProperties()
        {
            this.SetProperty(InternalSchema.Importance, (this.importance == -1) ? 1 : this.importance);
            string text = this.xAltDesc ?? this.body;

            if (!string.IsNullOrEmpty(text) && (base.InboundContext.MaxBodyLength == null || (ulong)base.InboundContext.MaxBodyLength.Value >= (ulong)((long)text.Length)))
            {
                BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(this.bodyFormat);
                bodyWriteConfiguration.SetTargetFormat(BodyFormat.ApplicationRtf, base.InboundContext.Charset.Name);
                using (TextWriter textWriter = this.item.Body.OpenTextWriter(bodyWriteConfiguration))
                {
                    textWriter.Write(text);
                }
            }
            return(true);
        }
        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);
            }
        }
Beispiel #9
0
        public void CopyBodyInjectingText(IBody targetBody, BodyInjectionFormat injectionFormat, string prefixInjectionText, string suffixInjectionText)
        {
            if (string.IsNullOrEmpty(prefixInjectionText) && string.IsNullOrEmpty(suffixInjectionText))
            {
                return;
            }
            BodyFormat bodyFormat = this.Format;

            if (bodyFormat == BodyFormat.ApplicationRtf)
            {
                bodyFormat = BodyFormat.TextHtml;
            }
            using (Stream stream = this.OpenReadStream(new BodyReadConfiguration(bodyFormat, this.Charset)))
            {
                BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(bodyFormat, this.Charset);
                bodyWriteConfiguration.SetTargetFormat(this.Format, this.Charset);
                bodyWriteConfiguration.AddInjectedText(prefixInjectionText, suffixInjectionText, injectionFormat);
                using (Stream stream2 = targetBody.OpenWriteStream(bodyWriteConfiguration))
                {
                    Util.StreamHandler.CopyStreamData(stream, stream2, null, 0, 65536);
                }
            }
        }
        private void StreamBody(StorePropertyDefinition property, TnefPropertyReader reader)
        {
            Charset charset = null;

            if (this.internetCpid != 0)
            {
                ConvertUtils.TryGetValidCharset(this.internetCpid, out charset);
            }
            string text = (charset != null) ? charset.Name : null;
            BodyWriteConfiguration bodyWriteConfiguration = null;

            if (property == InternalSchema.TextBody)
            {
                bodyWriteConfiguration = new BodyWriteConfiguration(BodyFormat.TextPlain, ConvertUtils.UnicodeCharset.Name);
                bodyWriteConfiguration.SetTargetFormat(BodyFormat.TextPlain, text);
            }
            else if (property == InternalSchema.HtmlBody)
            {
                bodyWriteConfiguration = new BodyWriteConfiguration(BodyFormat.TextHtml, text);
                bodyWriteConfiguration.SetTargetFormat(BodyFormat.TextHtml, text);
            }
            else if (property == InternalSchema.RtfBody)
            {
                bodyWriteConfiguration = new BodyWriteConfiguration(BodyFormat.ApplicationRtf);
                bodyWriteConfiguration.SetTargetFormat(BodyFormat.ApplicationRtf, text);
            }
            int trailingNulls;

            using (Stream stream = this.OpenValueReadStream(out trailingNulls))
            {
                base.CoreItem.CharsetDetector.DetectionOptions = base.ConversionOptions.DetectionOptions;
                using (Stream stream2 = base.CoreItem.Body.InternalOpenWriteStream(bodyWriteConfiguration, null))
                {
                    Util.StreamHandler.CopyStreamData(stream, stream2, null, trailingNulls, 65536);
                }
            }
        }