Example #1
0
 internal void GetStorage(InternalBodyFormat format, Charset charset, out DataStorage outStorage, out long outStart, out long outEnd)
 {
     if (format == this.internalFormat && (format == InternalBodyFormat.RtfCompressed || charset == null || charset == this.charset))
     {
         this.storage.AddRef();
         outStorage = this.storage;
         outStart   = this.start;
         outEnd     = this.end;
         return;
     }
     outStorage = new BodyFormatConversionStorage(this.storage, this.start, this.end, this.internalFormat, this.charset, format, charset);
     outStart   = 0L;
     outEnd     = long.MaxValue;
 }
        public override Stream OpenReadStream(long start, long end)
        {
            base.ThrowIfDisposed();
            BodyFormatConversionStorage.BodyFormatConversion conversion = BodyFormatConversionStorage.GetConversion(this.originalFormat, this.targetFormat);
            TextConverter converter     = null;
            Encoding      inputEncoding = null;

            if (this.originalCharset != null)
            {
                inputEncoding = this.originalCharset.GetEncoding();
            }
            Encoding outputEncoding = null;

            if (this.targetCharset != null)
            {
                outputEncoding = this.targetCharset.GetEncoding();
            }
            Stream stream = this.originalStorage.OpenReadStream(this.originalStart, this.originalEnd);

            switch (conversion)
            {
            case BodyFormatConversionStorage.BodyFormatConversion.HtmlToText:
                converter = new HtmlToText
                {
                    InputEncoding  = inputEncoding,
                    OutputEncoding = outputEncoding
                };
                break;

            case BodyFormatConversionStorage.BodyFormatConversion.HtmlToEnriched:
                converter = new HtmlToEnriched
                {
                    InputEncoding  = inputEncoding,
                    OutputEncoding = outputEncoding
                };
                break;

            case BodyFormatConversionStorage.BodyFormatConversion.RtfCompressedToText:
                stream    = new ConverterStream(stream, new RtfCompressedToRtf(), ConverterStreamAccess.Read);
                converter = new RtfToText
                {
                    OutputEncoding = outputEncoding
                };
                break;

            case BodyFormatConversionStorage.BodyFormatConversion.TextToText:
                converter = new TextToText
                {
                    InputEncoding  = inputEncoding,
                    OutputEncoding = outputEncoding
                };
                break;

            case BodyFormatConversionStorage.BodyFormatConversion.HtmlToHtml:
                converter = new HtmlToHtml
                {
                    InputEncoding  = inputEncoding,
                    OutputEncoding = outputEncoding
                };
                break;

            case BodyFormatConversionStorage.BodyFormatConversion.EnrichedToText:
                converter = new EnrichedToText
                {
                    InputEncoding  = inputEncoding,
                    OutputEncoding = outputEncoding
                };
                break;
            }
            return(new ConverterStream(stream, converter, ConverterStreamAccess.Read));
        }