private void WriteMessageBody() { this.limitsTracker.CountMessageBody(); BodyFormat rawFormat = this.item.Body.RawFormat; long bodySize = 0L; if (rawFormat == BodyFormat.TextHtml) { this.WriteMessageProperty(InternalSchema.HtmlBody, out bodySize); this.conversionResult.BodySize = bodySize; return; } this.WriteMessageProperty(InternalSchema.RtfSyncBodyCrc); this.WriteMessageProperty(InternalSchema.RtfSyncBodyCount); this.WriteMessageProperty(InternalSchema.RtfSyncBodyTag); this.WriteMessageProperty(InternalSchema.RtfInSync); this.WriteMessageProperty(InternalSchema.RtfSyncPrefixCount); this.WriteMessageProperty(InternalSchema.RtfSyncTrailingCount); if (rawFormat == BodyFormat.ApplicationRtf) { this.WriteMessageProperty(InternalSchema.RtfBody, out bodySize); this.conversionResult.BodySize = bodySize; return; } if (rawFormat == BodyFormat.TextPlain) { if (!this.item.Body.IsBodyDefined) { return; } using (Stream textStream = this.item.OpenPropertyStream(InternalSchema.TextBody, PropertyOpenMode.ReadOnly)) { if (this.tnefType == TnefType.SummaryTnef) { using (Stream stream = this.tnefWriter.StartStreamProperty(InternalSchema.TextBody)) { this.conversionResult.BodySize = Util.StreamHandler.CopyStreamData(textStream, stream); } textStream.Position = 0L; } using (Stream tnefStream = this.tnefWriter.StartStreamProperty(InternalSchema.RtfBody)) { int inCodePage = this.item.Body.RawCharset.CodePage; ConvertUtils.CallCts(ExTraceGlobals.CcOutboundTnefTracer, "ItemToTnefConverter::WriteMessageBody", ServerStrings.ConversionBodyConversionFailed, delegate { TextToRtf textToRtf = new TextToRtf(); textToRtf.InputEncoding = Charset.GetEncoding(inCodePage); using (Stream stream2 = new ConverterStream(textStream, textToRtf, ConverterStreamAccess.Read)) { using (ConverterStream converterStream = new ConverterStream(stream2, new RtfToRtfCompressed(), ConverterStreamAccess.Read)) { Util.StreamHandler.CopyStreamData(converterStream, tnefStream); } } }); } } } }
internal Stream ConvertWriteStreamFormat(Stream stream, Charset writeStreamCharset) { if (this.internalFormat == (InternalBodyFormat)this.format && (writeStreamCharset == null || this.charset == writeStreamCharset)) { return(stream); } Charset charset = writeStreamCharset ?? this.charset; TextConverter converter; if (this.internalFormat == InternalBodyFormat.RtfCompressed) { stream = new ConverterStream(stream, new RtfToRtfCompressed(), ConverterStreamAccess.Write); if (BodyFormat.Rtf == this.format) { return(stream); } converter = new TextToRtf { InputEncoding = charset.GetEncoding() }; } else if (this.internalFormat == InternalBodyFormat.Enriched) { converter = new HtmlToEnriched { InputEncoding = charset.GetEncoding(), OutputEncoding = this.Encoding }; } else if (this.internalFormat == InternalBodyFormat.Html) { converter = new HtmlToHtml { InputEncoding = charset.GetEncoding(), OutputEncoding = this.Encoding }; } else { converter = new TextToText { InputEncoding = charset.GetEncoding(), OutputEncoding = this.Encoding }; } return(new ConverterStream(stream, converter, ConverterStreamAccess.Write)); }