Ejemplo n.º 1
0
 public ImapItemConverter(Item itemIn, OutboundConversionOptions options)
 {
     StorageGlobals.ContextTraceInformation(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::ctor.");
     using (DisposeGuard disposeGuard = this.Guard())
     {
         Util.ThrowOnNullArgument(itemIn, "itemIn");
         Util.ThrowOnNullArgument(options, "options");
         Util.ThrowOnNullOrEmptyArgument(options.ImceaEncapsulationDomain, "options.ImceaEncapsulationDomain");
         if (!ItemConversion.IsItemClassConvertibleToMime(itemIn.ClassName))
         {
             StorageGlobals.ContextTraceError <string>(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::CheckItemType: wrong item type, {0}", itemIn.ClassName);
             throw new WrongObjectTypeException(ServerStrings.ConversionInvalidItemType(itemIn.ClassName));
         }
         this.itemIn  = itemIn;
         this.options = options;
         using (StorageGlobals.SetTraceContext(this.options))
         {
             using (StorageGlobals.SetTraceContext(this.itemIn))
             {
                 if (this.options.GenerateMimeSkeleton)
                 {
                     PropertyError propertyError = this.itemIn.TryGetProperty(InternalSchema.MimeSkeleton) as PropertyError;
                     if (propertyError != null && propertyError.PropertyErrorCode == PropertyErrorCode.NotFound)
                     {
                         if (this.itemIn.IsReadOnly)
                         {
                             this.itemIn.OpenAsReadWrite();
                         }
                         this.itemNeedsSave = true;
                         using (Stream stream = this.itemIn.OpenPropertyStream(InternalSchema.MimeSkeleton, PropertyOpenMode.Create))
                         {
                             using (Stream stream2 = new MimeStreamWriter.MimeTextStream(null))
                             {
                                 using (ItemToMimeConverter itemToMimeConverter = new ItemToMimeConverter(itemIn, options, ConverterFlags.GenerateSkeleton))
                                 {
                                     using (MimeStreamWriter mimeStreamWriter = new MimeStreamWriter(stream2, stream, itemToMimeConverter.GetItemMimeEncodingOptions(this.options), MimeStreamWriter.Flags.ForceMime))
                                     {
                                         ConversionLimitsTracker limits = new ConversionLimitsTracker(this.options.Limits);
                                         itemToMimeConverter.ConvertItemToMime(mimeStreamWriter, limits);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 ItemToMimeConverter itemToMimeConverter2 = new ItemToMimeConverter(itemIn, options, ConverterFlags.None);
                 this.mimeProvider        = IImapMimeProvider.CreateInstance(itemToMimeConverter2);
                 this.itemEncodingOptions = itemToMimeConverter2.GetItemMimeEncodingOptions(this.options);
             }
         }
         disposeGuard.Success();
     }
 }
Ejemplo n.º 2
0
        internal Stream GetContentStream(bool writeToSkeleton)
        {
            this.StartWriting();
            this.Flush();
            Stream stream = null;
            bool   flag   = false;

            try
            {
                if (this.mimeWriter != null)
                {
                    stream = this.mimeWriter.GetRawContentWriteStream();
                }
                if (writeToSkeleton && this.mimeSkeletonWriter != null)
                {
                    Stream rawContentWriteStream = this.mimeSkeletonWriter.GetRawContentWriteStream();
                    stream = ((stream == null) ? rawContentWriteStream : new MimeStreamWriter.SplitterWriteStream(stream, rawContentWriteStream));
                }
                if (this.currentPart != null && (this.flags & MimeStreamWriter.Flags.ProduceMimeStructure) == MimeStreamWriter.Flags.ProduceMimeStructure && !this.currentPart.IsBodySizeComputed)
                {
                    stream = new MimeStreamWriter.MimeBodySizeCounter(stream, this.currentPart);
                }
                if (stream == null)
                {
                    stream = new MimeStreamWriter.MimeTextStream(null);
                }
                flag = true;
            }
            finally
            {
                if (!flag && stream != null)
                {
                    stream.Dispose();
                }
            }
            return(stream);
        }