예제 #1
0
        private void DecorateRumBody(MessageItem message, string textToInject, string description, List <KeyValuePair <string, List <string> > > details)
        {
            string arg  = string.Format("<p><font color='#000000' size='2' face='Tahoma'>{0}</font></p>", description);
            string arg2 = string.Empty;

            if (details != null && details.Count != 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (KeyValuePair <string, List <string> > keyValuePair in details)
                {
                    StringBuilder stringBuilder2 = new StringBuilder();
                    foreach (string arg3 in keyValuePair.Value)
                    {
                        stringBuilder2.AppendFormat("<tr><td width='29'>&nbsp;</td><td><font color='#000000' size='2' face='Tahoma'>{0}</font></td></tr>", arg3);
                    }
                    stringBuilder.AppendFormat("<table border='0' cellpadding='2'><tr><td width='29'>&nbsp;</td><td><b><font color='#808080' size='2' face='Tahoma'>{0}</font></b></td></tr>{1}</table><br />", keyValuePair.Key, stringBuilder2);
                }
                arg2 = stringBuilder.ToString();
            }
            string arg4 = string.Format("<hr/><font color='#808080' size='1' face='Arial'>{0}</font>", this.GetLocalizedString(ClientStrings.RumFooter("2013"), message));
            BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(BodyFormat.TextHtml);

            if (!string.IsNullOrEmpty(textToInject))
            {
                bodyWriteConfiguration.AddInjectedText(textToInject, null, BodyInjectionFormat.Text);
            }
            using (TextWriter textWriter = message.Body.OpenTextWriter(bodyWriteConfiguration))
            {
                textWriter.Write(string.Format("<html><body>{0}{1}{2}</body></html>", arg, arg2, arg4));
            }
        }
예제 #2
0
        private static BodyWriteDelegates.ConversionCreator GetConversionMethod(BodyWriteConfiguration configuration)
        {
            int formatIndex  = BodyWriteDelegates.GetFormatIndex(configuration.SourceFormat);
            int formatIndex2 = BodyWriteDelegates.GetFormatIndex(configuration.TargetFormat);

            return(BodyWriteDelegates.conversionCreatorsTable[formatIndex][formatIndex2]);
        }
예제 #3
0
        private static object FromRtfToText(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                stream = new BodyCharsetDetectionStream(bodyStream, null, coreItem, BodyStreamFormat.Text, ConvertUtils.UnicodeCharset, configuration.TargetCharset, configuration.TargetCharsetFlags, null, false);
                stream = new ConverterStream(stream, new RtfToText
                {
                    OutputEncoding     = ConvertUtils.UnicodeEncoding,
                    Header             = configuration.InjectPrefix,
                    Footer             = configuration.InjectSuffix,
                    HeaderFooterFormat = configuration.InjectionHeaderFooterFormat
                }, ConverterStreamAccess.Write);
                obj = BodyWriteDelegates.GetRtfDecompressorOrUnicodeWriter(stream, createWriter);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
예제 #4
0
        private static object FromTextToRtf(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 ConverterStream(stream, new TextToRtf
                {
                    InputEncoding      = configuration.SourceEncoding,
                    Header             = configuration.InjectPrefix,
                    Footer             = configuration.InjectSuffix,
                    HeaderFooterFormat = configuration.InjectionHeaderFooterFormat
                }, ConverterStreamAccess.Write);
                stream = new BodyCharsetDetectionStream(stream, null, coreItem, BodyStreamFormat.Text, configuration.SourceCharset, configuration.TargetCharset, configuration.TargetCharsetFlags, BodyWriteDelegates.GetExtraData(configuration), false);
                obj    = BodyWriteDelegates.GetStreamOrUnicodeWriter(stream, createWriter);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
예제 #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);
                }
            }
        }
예제 #6
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);
                    }
                }
            }
        }
예제 #7
0
        private static object FromTextToHtml(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                HtmlWriteConverterStream htmlWriteConverterStream = new HtmlWriteConverterStream(bodyStream, new TextToHtml
                {
                    InputEncoding      = configuration.SourceEncoding,
                    Header             = configuration.InjectPrefix,
                    Footer             = configuration.InjectSuffix,
                    HeaderFooterFormat = configuration.InjectionHeaderFooterFormat,
                    HtmlTagCallback    = configuration.InternalHtmlTagCallback,
                    FilterHtml         = configuration.FilterHtml
                });
                stream = htmlWriteConverterStream;
                stream = new BodyCharsetDetectionStream(stream, new BodyCharsetDetectionStream.DetectCharsetCallback(htmlWriteConverterStream.SetCharset), coreItem, BodyStreamFormat.Text, configuration.SourceCharset, configuration.TargetCharset, configuration.TargetCharsetFlags, BodyWriteDelegates.GetExtraData(configuration), false);
                obj    = BodyWriteDelegates.GetStreamOrUnicodeWriter(stream, createWriter);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
예제 #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);
                }
            }
        }
예제 #9
0
 public Stream OpenWriteStream(BodyWriteConfiguration configuration)
 {
     Body.CheckNull(configuration, "configuration");
     if ((configuration.SourceFormat == BodyFormat.TextPlain || configuration.SourceFormat == BodyFormat.TextHtml) && configuration.SourceCharset == null)
     {
         throw new InvalidOperationException("Body.OpenWriteStream - source charset is undefined");
     }
     return(this.InternalOpenWriteStream(configuration, null));
 }
예제 #10
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();
                }
            }
        }
예제 #11
0
        internal static Stream CreateStream(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, out ConversionCallbackBase provider)
        {
            BodyWriteConfiguration writerConfiguration = new BodyWriteConfiguration(configuration);

            provider = BodyWriteDelegates.CreateConversionDelegateProvider(coreItem, writerConfiguration);
            return(ConvertUtils.CallCtsWithReturnValue <Stream>(ExTraceGlobals.CcBodyTracer, "BodyWriteDelegates::CreateStream", ServerStrings.ConversionBodyConversionFailed, delegate
            {
                BodyWriteDelegates.ConversionCreator conversionMethod = BodyWriteDelegates.GetConversionMethod(configuration);
                return (Stream)conversionMethod(coreItem, writerConfiguration, bodyStream, false);
            }));
        }
예제 #12
0
        internal static TextWriter CreateWriter(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, out ConversionCallbackBase provider)
        {
            BodyWriteConfiguration writerConfiguration = new BodyWriteConfiguration(configuration);

            writerConfiguration.SourceCharset = ConvertUtils.UnicodeCharset;
            provider = BodyWriteDelegates.CreateConversionDelegateProvider(coreItem, writerConfiguration);
            return(ConvertUtils.CallCtsWithReturnValue <TextWriter>(ExTraceGlobals.CcBodyTracer, "BodyWriteDelegates::CreateWriter", ServerStrings.ConversionBodyConversionFailed, delegate
            {
                BodyWriteDelegates.ConversionCreator conversionMethod = BodyWriteDelegates.GetConversionMethod(writerConfiguration);
                return (TextWriter)conversionMethod(coreItem, writerConfiguration, bodyStream, true);
            }));
        }
예제 #13
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))
            {
            }
        }
 internal BodyWriteConfiguration(BodyWriteConfiguration configuration)
 {
     this.sourceFormat        = configuration.sourceFormat;
     this.sourceCharset       = configuration.sourceCharset;
     this.targetFormat        = configuration.targetFormat;
     this.targetCharset       = configuration.targetCharset;
     this.targetCharsetFlags  = configuration.targetCharsetFlags;
     this.injectPrefix        = configuration.injectPrefix;
     this.injectSuffix        = configuration.injectSuffix;
     this.injectFormat        = configuration.injectFormat;
     this.conversionCallbacks = configuration.conversionCallbacks;
     this.htmlFlags           = configuration.htmlFlags;
     this.trustHtmlMetaTag    = configuration.trustHtmlMetaTag;
 }
예제 #15
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);
                }
            }
        }
예제 #16
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);
        }
예제 #17
0
        public TextWriter OpenTextWriter(BodyWriteConfiguration configuration)
        {
            Body.CheckNull(configuration, "configuration");
            BodyTextWriter result;

            lock (this.bodyStreamsLock)
            {
                this.CheckOpenBodyStreamForWrite();
                result = new BodyTextWriter(this.coreItem, configuration, null);
                this.bodyWriteStream = result;
            }
            this.BodyChanged(configuration);
            this.bodyStreamingException = null;
            this.isBodyChanged          = true;
            this.cachedPreviewText      = null;
            return(result);
        }
예제 #18
0
        public static MessageItem CreateNotReadNotification(MessageItem originalItem)
        {
            ExDateTime  utcNow      = ExDateTime.UtcNow;
            MessageItem messageItem = MessageItem.CreateInMemory(StoreObjectSchema.ContentConversionProperties);

            messageItem.ClassName = ObjectClass.MakeReportClassName(originalItem.ClassName, "IPNNRN");
            messageItem.SafeSetProperty(InternalSchema.ReportTime, utcNow);
            Participant participant = originalItem.ReadReceiptAddressee;

            if (null == participant)
            {
                if (null != originalItem.Sender)
                {
                    participant = originalItem.Sender;
                }
                else
                {
                    participant = originalItem.From;
                }
            }
            messageItem.Recipients.Add(participant, RecipientItemType.To);
            foreach (KeyValuePair <PropertyDefinition, PropertyDefinition> keyValuePair in RuleMessageUtils.NrnPropertyMap)
            {
                messageItem.SafeSetProperty(keyValuePair.Key, originalItem.TryGetProperty(keyValuePair.Value));
            }
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextHtml, originalItem.Body.RawCharset.Name);
            CultureInfo            formatProvider;

            using (Stream stream = messageItem.Body.OpenWriteStream(configuration))
            {
                Charset charset;
                ReportMessage.GenerateReportBody(messageItem, stream, out formatProvider, out charset);
            }
            messageItem.SafeSetProperty(InternalSchema.Subject, ServerStrings.NotRead.ToString(formatProvider) + originalItem.TryGetProperty(InternalSchema.Subject));
            byte[] parentBytes = originalItem.TryGetProperty(InternalSchema.ConversationIndex) as byte[];
            messageItem.SafeSetProperty(InternalSchema.ConversationIndex, ConversationIndex.CreateFromParent(parentBytes).ToByteArray());
            messageItem.SafeSetProperty(InternalSchema.ConversationTopic, StoreObject.SafePropertyValue(originalItem.TryGetProperty(InternalSchema.ConversationTopic), typeof(string), StoreObject.SafePropertyValue(originalItem.TryGetProperty(InternalSchema.NormalizedSubjectInternal), typeof(string), null)));
            messageItem.SafeSetProperty(InternalSchema.IsReadReceiptRequested, false);
            messageItem.SafeSetProperty(InternalSchema.IsDeliveryReceiptRequested, false);
            messageItem.SafeSetProperty(InternalSchema.IsNonDeliveryReceiptRequested, false);
            messageItem.SafeSetProperty(InternalSchema.NonReceiptReason, 0);
            messageItem.SafeSetProperty(InternalSchema.DiscardReason, 1);
            messageItem.SafeSetProperty(InternalSchema.OriginalDeliveryTime, utcNow);
            return(messageItem);
        }
예제 #19
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);
            }
        }
예제 #20
0
 internal BodyWriteStream(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream outputStream) : base(StreamBase.Capabilities.Writable)
 {
     this.coreItem = coreItem;
     using (DisposeGuard disposeGuard = default(DisposeGuard))
     {
         Stream stream = null;
         if (outputStream == null)
         {
             stream = BodyWriteStream.OpenBodyStream(coreItem, configuration);
             disposeGuard.Add <Stream>(stream);
             outputStream = stream;
         }
         Stream disposable = BodyWriteDelegates.CreateStream(coreItem, configuration, outputStream, out this.conversionCallback);
         disposeGuard.Add <Stream>(disposable);
         disposeGuard.Success();
         this.writeStream = disposable;
         this.bodyStream  = stream;
     }
 }
예제 #21
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);
        }
예제 #22
0
        private static object FromTextToText(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                stream = new BodyCharsetDetectionStream(bodyStream, null, coreItem, BodyStreamFormat.Text, ConvertUtils.UnicodeCharset, configuration.TargetCharset, configuration.TargetCharsetFlags, null, false);
                if (!createWriter && !configuration.IsContentTransformationNeeded(coreItem))
                {
                    obj = stream;
                }
                else
                {
                    TextToText textToText;
                    if (string.IsNullOrEmpty(configuration.InjectPrefix) && string.IsNullOrEmpty(configuration.InjectSuffix))
                    {
                        textToText = new TextToText(TextToTextConversionMode.ConvertCodePageOnly);
                    }
                    else
                    {
                        textToText = new TextToText();
                    }
                    textToText.InputEncoding  = configuration.SourceEncoding;
                    textToText.OutputEncoding = ConvertUtils.UnicodeEncoding;
                    if (!string.IsNullOrEmpty(configuration.InjectPrefix) || !string.IsNullOrEmpty(configuration.InjectSuffix))
                    {
                        textToText.Header             = configuration.InjectPrefix;
                        textToText.Footer             = configuration.InjectSuffix;
                        textToText.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat;
                    }
                    obj = BodyWriteDelegates.GetConverterStreamOrWriter(stream, textToText, createWriter);
                }
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
예제 #23
0
 internal BodyTextWriter(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream outputStream)
 {
     this.coreItem       = coreItem;
     this.disposeTracker = this.GetDisposeTracker();
     using (DisposeGuard disposeGuard = default(DisposeGuard))
     {
         Stream stream = null;
         if (outputStream == null)
         {
             stream = new StreamWrapper(BodyWriteStream.OpenBodyStream(coreItem, configuration), true);
             disposeGuard.Add <Stream>(stream);
             outputStream = stream;
         }
         TextWriter disposable = BodyWriteDelegates.CreateWriter(coreItem, configuration, outputStream, out this.conversionCallback);
         disposeGuard.Add <TextWriter>(disposable);
         disposeGuard.Success();
         this.writer     = disposable;
         this.bodyStream = stream;
     }
 }
예제 #24
0
 private void BodyChanged(BodyWriteConfiguration configuration)
 {
     if (this.coreItem.Schema is CalendarItemBaseSchema)
     {
         this.coreItem.LocationIdentifierHelperInstance.SetLocationIdentifier(65525U, LastChangeAction.SetBody);
     }
     if (configuration.TargetFormat == BodyFormat.ApplicationRtf && configuration.SourceFormat == BodyFormat.TextPlain && string.IsNullOrEmpty(configuration.InjectPrefix) && string.IsNullOrEmpty(configuration.InjectSuffix))
     {
         this.bodyFormat          = 1;
         this.rawBodyFormat       = 3;
         this.isEmbeddedPlainText = true;
     }
     else
     {
         this.bodyFormat          = (int)configuration.TargetFormat;
         this.rawBodyFormat       = (int)configuration.TargetFormat;
         this.isEmbeddedPlainText = false;
     }
     this.noBody = false;
 }
예제 #25
0
        internal Stream InternalOpenWriteStream(BodyWriteConfiguration configuration, Stream outputStream)
        {
            Stream result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                BodyWriteStream bodyWriteStream;
                lock (this.bodyStreamsLock)
                {
                    this.CheckOpenBodyStreamForWrite();
                    bodyWriteStream = new BodyWriteStream(this.coreItem, configuration, outputStream);
                    disposeGuard.Add <BodyWriteStream>(bodyWriteStream);
                    this.bodyWriteStream = bodyWriteStream;
                }
                this.BodyChanged(configuration);
                this.bodyStreamingException = null;
                this.isBodyChanged          = true;
                this.cachedPreviewText      = null;
                disposeGuard.Success();
                result = bodyWriteStream;
            }
            return(result);
        }
예제 #26
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);
                }
            }
        }
예제 #27
0
        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);
                }
            }
        }
예제 #28
0
        private static object FromHtmlToHtml(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                if (!createWriter && configuration.SourceCharset == null)
                {
                    obj = bodyStream;
                }
                else
                {
                    HtmlToHtml htmlToHtml = new HtmlToHtml();
                    htmlToHtml.InputEncoding             = configuration.SourceEncoding;
                    htmlToHtml.DetectEncodingFromMetaTag = configuration.TrustHtmlMetaTag;
                    htmlToHtml.FilterHtml         = configuration.FilterHtml;
                    htmlToHtml.HtmlTagCallback    = configuration.InternalHtmlTagCallback;
                    htmlToHtml.Header             = configuration.InjectPrefix;
                    htmlToHtml.Footer             = configuration.InjectSuffix;
                    htmlToHtml.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat;
                    bool canSkipConversionOnMatchingCharset           = !configuration.IsContentTransformationNeeded(coreItem);
                    HtmlWriteConverterStream htmlWriteConverterStream = new HtmlWriteConverterStream(bodyStream, htmlToHtml, canSkipConversionOnMatchingCharset);
                    stream = htmlWriteConverterStream;
                    stream = new BodyCharsetDetectionStream(htmlWriteConverterStream, new BodyCharsetDetectionStream.DetectCharsetCallback(htmlWriteConverterStream.SetCharset), coreItem, BodyStreamFormat.Html, configuration.SourceCharset, configuration.TargetCharset, configuration.TargetCharsetFlags, BodyWriteDelegates.GetExtraData(configuration), configuration.TrustHtmlMetaTag);
                    obj    = BodyWriteDelegates.GetStreamOrUnicodeWriter(stream, createWriter);
                }
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
예제 #29
0
        private static object FromRtfToRtf(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                if (!createWriter && !configuration.IsContentTransformationNeeded(coreItem))
                {
                    obj = new BodyCharsetDetectionStream(bodyStream, null, coreItem, BodyStreamFormat.RtfCompressed, null, configuration.TargetCharset, configuration.TargetCharsetFlags, null, false);
                }
                else
                {
                    stream = new ConverterStream(bodyStream, new RtfToRtfCompressed(), ConverterStreamAccess.Write);
                    stream = new BodyCharsetDetectionStream(stream, null, coreItem, BodyStreamFormat.RtfUncompressed, null, configuration.TargetCharset, configuration.TargetCharsetFlags, null, false);
                    if (configuration.InjectPrefix != null || configuration.InjectSuffix != null)
                    {
                        stream = new ConverterStream(stream, new RtfToRtf
                        {
                            Header             = configuration.InjectPrefix,
                            Footer             = configuration.InjectSuffix,
                            HeaderFooterFormat = configuration.InjectionHeaderFooterFormat
                        }, ConverterStreamAccess.Write);
                    }
                    obj = BodyWriteDelegates.GetRtfDecompressorOrUnicodeWriter(stream, createWriter);
                }
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
예제 #30
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);
        }