示例#1
0
        public override MimePartHeaders GetHeaders()
        {
            StorageGlobals.ContextTraceInformation(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetHeaders.1");
            this.CheckDisposed(null);
            MimePartHeaders headers;

            using (StorageGlobals.SetTraceContext(this.options))
            {
                using (StorageGlobals.SetTraceContext(this.itemIn))
                {
                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Starting item (ImapItemConverter.GetHeaders.1)");
                    MimePartInfo mimeSkeleton = this.GetMimeSkeleton();
                    if (mimeSkeleton.Headers == null || mimeSkeleton.Headers.Count == 0)
                    {
                        using (MimeStreamWriter mimeStreamWriter = new MimeStreamWriter((MimeStreamWriter.Flags) 6, this.itemEncodingOptions))
                        {
                            this.WriteMimePart(this.mimeProvider, mimeStreamWriter, this.options, mimeSkeleton, ItemToMimeConverter.MimeFlags.WriteMessageHeaders | ItemToMimeConverter.MimeFlags.SkipContent);
                        }
                    }
                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetHeaders.1)");
                    headers = mimeSkeleton.Headers;
                }
            }
            return(headers);
        }
示例#2
0
        public override MimePartInfo GetMimeStructure()
        {
            StorageGlobals.ContextTraceInformation(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetMimeStructure.");
            this.CheckDisposed(null);
            MimePartInfo result;

            using (StorageGlobals.SetTraceContext(this.options))
            {
                using (StorageGlobals.SetTraceContext(this.itemIn))
                {
                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Starting item (ImapItemConverter.GetMimeStructure)");
                    MimePartInfo mimeSkeleton = this.GetMimeSkeleton();
                    if (mimeSkeleton.IsBodySizeComputed)
                    {
                        this.GetHeaders();
                    }
                    else
                    {
                        using (MimeStreamWriter mimeStreamWriter = new MimeStreamWriter((MimeStreamWriter.Flags) 6, this.itemEncodingOptions))
                        {
                            this.WriteMimePart(this.mimeProvider, mimeStreamWriter, this.options, mimeSkeleton, ItemToMimeConverter.MimeFlags.WriteMessageHeaders);
                        }
                    }
                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetMimeStructure)");
                    result = mimeSkeleton;
                }
            }
            return(result);
        }
示例#3
0
 private bool GetText(Stream outStream, bool isSinglePartOnly)
 {
     StorageGlobals.ContextTraceInformation(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetText.1");
     this.CheckDisposed(null);
     if (outStream == null)
     {
         throw new ArgumentNullException("outStream");
     }
     using (StorageGlobals.SetTraceContext(this.options))
     {
         using (StorageGlobals.SetTraceContext(this.itemIn))
         {
             StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Starting item (ImapItemConverter.GetText.1)");
             MimePartInfo mimeSkeleton = this.GetMimeSkeleton();
             if (isSinglePartOnly && mimeSkeleton.IsMultipart)
             {
                 return(false);
             }
             using (Stream stream = new StreamWrapper(outStream, false))
             {
                 using (MimeStreamWriter mimeStreamWriter = new MimeStreamWriter(stream, this.itemEncodingOptions, (MimeStreamWriter.Flags) 3))
                 {
                     this.WriteMimePart(this.mimeProvider, mimeStreamWriter, this.options, mimeSkeleton, ItemToMimeConverter.MimeFlags.SkipMessageHeaders);
                 }
             }
             StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetText.1)");
         }
     }
     return(true);
 }
示例#4
0
 public override void GetBody(Stream outStream)
 {
     StorageGlobals.ContextTraceInformation(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetBody.1");
     this.CheckDisposed(null);
     if (outStream == null)
     {
         throw new ArgumentNullException("outStream");
     }
     using (StorageGlobals.SetTraceContext(this.options))
     {
         using (StorageGlobals.SetTraceContext(this.itemIn))
         {
             StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Starting item (ImapItemConverter.GetBody.1)");
             MimePartInfo mimeSkeleton = this.GetMimeSkeleton();
             using (Stream stream = new StreamWrapper(outStream, false))
             {
                 using (MimeStreamWriter mimeStreamWriter = new MimeStreamWriter(stream, this.itemEncodingOptions, (MimeStreamWriter.Flags) 6))
                 {
                     this.WriteMimePart(this.mimeProvider, mimeStreamWriter, this.options, mimeSkeleton, ItemToMimeConverter.MimeFlags.WriteMessageHeaders);
                 }
             }
             StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetBody.1)");
         }
     }
 }
示例#5
0
        public override bool GetBody(Stream outStream, uint[] indices)
        {
            StorageGlobals.ContextTraceInformation(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetBody.2");
            this.CheckDisposed(null);
            bool result;

            using (StorageGlobals.SetTraceContext(this.options))
            {
                using (StorageGlobals.SetTraceContext(this.itemIn))
                {
                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Starting item (ImapItemConverter.GetBody.2)");
                    bool flag = false;
                    if (indices == null || indices.Length == 0)
                    {
                        this.GetBody(outStream);
                        flag = true;
                    }
                    else
                    {
                        List <IDisposable> disposeList = null;
                        MimePartInfo       partInfo    = null;
                        Item item = null;
                        try
                        {
                            EncodingOptions   encodingOptions;
                            IImapMimeProvider subpartConverter = this.GetSubpartConverter(indices, out partInfo, out item, out encodingOptions, out disposeList);
                            if (subpartConverter != null)
                            {
                                using (Stream stream = new StreamWrapper(outStream, false))
                                {
                                    using (MimeStreamWriter mimeStreamWriter = new MimeStreamWriter(stream, encodingOptions, (MimeStreamWriter.Flags) 3))
                                    {
                                        this.WriteMimePart(subpartConverter, mimeStreamWriter, this.options, partInfo, ItemToMimeConverter.MimeFlags.SkipMessageHeaders);
                                    }
                                }
                                flag = true;
                            }
                        }
                        finally
                        {
                            this.DisposeAll(disposeList);
                        }
                    }
                    if (!flag)
                    {
                        int num = indices.Length - 1;
                        if (indices[num] == 1U)
                        {
                            uint[] array = new uint[num];
                            Array.Copy(indices, array, num);
                            flag = this.GetText(outStream, array, true);
                        }
                    }
                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetBody.2)");
                    result = flag;
                }
            }
            return(result);
        }
示例#6
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();
     }
 }
示例#7
0
        private bool GetText(Stream outStream, uint[] indices, bool isSinglePartOnly)
        {
            StorageGlobals.ContextTraceInformation(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetText.2");
            this.CheckDisposed(null);
            bool result;

            using (StorageGlobals.SetTraceContext(this.options))
            {
                using (StorageGlobals.SetTraceContext(this.itemIn))
                {
                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Starting item (ImapItemConverter.GetText.2)");
                    bool flag = false;
                    if (indices == null || indices.Length == 0)
                    {
                        flag = this.GetText(outStream, isSinglePartOnly);
                    }
                    else
                    {
                        List <IDisposable> disposeList  = null;
                        MimePartInfo       mimePartInfo = null;
                        Item            item            = null;
                        EncodingOptions encodingOptions = null;
                        try
                        {
                            IImapMimeProvider imapMimeProvider = this.GetSubpartConverter(indices, out mimePartInfo, out item, out encodingOptions, out disposeList);
                            if (imapMimeProvider != null)
                            {
                                imapMimeProvider = this.GetAttachedItemConverter(ref mimePartInfo, ref item, ref encodingOptions, disposeList);
                                if (imapMimeProvider != null && (!mimePartInfo.IsMultipart || !isSinglePartOnly))
                                {
                                    using (Stream stream = new StreamWrapper(outStream, false))
                                    {
                                        using (MimeStreamWriter mimeStreamWriter = new MimeStreamWriter(stream, encodingOptions, MimeStreamWriter.Flags.SkipHeaders))
                                        {
                                            this.WriteMimePart(imapMimeProvider, mimeStreamWriter, this.options, mimePartInfo, ItemToMimeConverter.MimeFlags.SkipMessageHeaders);
                                        }
                                    }
                                    flag = true;
                                }
                            }
                        }
                        finally
                        {
                            this.DisposeAll(disposeList);
                        }
                    }
                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetText.2)");
                    result = flag;
                }
            }
            return(result);
        }
示例#8
0
        public override MimePartHeaders GetMime(uint[] indices)
        {
            StorageGlobals.ContextTraceInformation(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetMime.");
            this.CheckDisposed(null);
            if (indices == null || indices.Length == 0)
            {
                return(null);
            }
            MimePartHeaders result;

            using (StorageGlobals.SetTraceContext(this.options))
            {
                using (StorageGlobals.SetTraceContext(this.itemIn))
                {
                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Starting item (ImapItemConverter.GetMime)");
                    MimePartHeaders mimePartHeaders = null;
                    MimePartInfo    mimePartInfo    = this.FindMimePart(indices);
                    if (mimePartInfo != null && mimePartInfo.Headers != null && mimePartInfo.Headers.Count != 0)
                    {
                        mimePartHeaders = mimePartInfo.Headers;
                    }
                    else
                    {
                        mimePartInfo = this.GetMimeSkeleton();
                        List <IDisposable> disposeList  = null;
                        Item            item            = null;
                        EncodingOptions encodingOptions = null;
                        try
                        {
                            IImapMimeProvider subpartConverter = this.GetSubpartConverter(indices, out mimePartInfo, out item, out encodingOptions, out disposeList);
                            if (subpartConverter != null)
                            {
                                using (MimeStreamWriter mimeStreamWriter = new MimeStreamWriter(MimeStreamWriter.Flags.ProduceMimeStructure, encodingOptions))
                                {
                                    this.WriteMimePart(subpartConverter, mimeStreamWriter, this.options, mimePartInfo, ItemToMimeConverter.MimeFlags.SkipContent);
                                }
                                mimePartHeaders = mimePartInfo.Headers;
                            }
                        }
                        finally
                        {
                            this.DisposeAll(disposeList);
                        }
                    }
                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetMime)");
                    result = mimePartHeaders;
                }
            }
            return(result);
        }
示例#9
0
        public override MimePartHeaders GetHeaders(uint[] indices)
        {
            StorageGlobals.ContextTraceInformation(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetHeaders.2");
            this.CheckDisposed(null);
            MimePartHeaders result;

            using (StorageGlobals.SetTraceContext(this.options))
            {
                using (StorageGlobals.SetTraceContext(this.itemIn))
                {
                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Starting item (ImapItemConverter.GetHeaders.2)");
                    if (indices == null || indices.Length == 0)
                    {
                        StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetHeaders.2)");
                        result = this.GetHeaders();
                    }
                    else
                    {
                        MimePartInfo mimePartInfo = this.FindMimePart(indices);
                        if (mimePartInfo != null)
                        {
                            if (mimePartInfo.ContentType != MimePartContentType.ItemAttachment)
                            {
                                StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetHeaders.2)");
                                return(null);
                            }
                            mimePartInfo = mimePartInfo.AttachedItemStructure;
                            if (mimePartInfo != null && mimePartInfo.Headers != null && mimePartInfo.Headers.Count != 0)
                            {
                                StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetHeaders.2)");
                                return(mimePartInfo.Headers);
                            }
                        }
                        mimePartInfo = this.GetMimeSkeleton();
                        List <IDisposable> disposeList = null;
                        Item item = null;
                        try
                        {
                            EncodingOptions encodingOptions;
                            if (this.GetSubpartConverter(indices, out mimePartInfo, out item, out encodingOptions, out disposeList) == null)
                            {
                                StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetHeaders.2)");
                                result = null;
                            }
                            else
                            {
                                IImapMimeProvider attachedItemConverter = this.GetAttachedItemConverter(ref mimePartInfo, ref item, ref encodingOptions, disposeList);
                                if (attachedItemConverter == null)
                                {
                                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetHeaders.2)");
                                    result = null;
                                }
                                else
                                {
                                    using (MimeStreamWriter mimeStreamWriter = new MimeStreamWriter((MimeStreamWriter.Flags) 6, encodingOptions))
                                    {
                                        this.WriteMimePart(attachedItemConverter, mimeStreamWriter, this.options, mimePartInfo, ItemToMimeConverter.MimeFlags.WriteMessageHeaders | ItemToMimeConverter.MimeFlags.SkipContent);
                                    }
                                    StorageGlobals.ContextTracePfd(ExTraceGlobals.CcPFDTracer, "Finishing item (ImapItemConverter.GetHeaders.2)");
                                    result = mimePartInfo.Headers;
                                }
                            }
                        }
                        finally
                        {
                            this.DisposeAll(disposeList);
                        }
                    }
                }
            }
            return(result);
        }