Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        internal void StartPart(MimePartInfo part, bool outputToSkeleton)
        {
            this.FlushCachedHeader();
            if (this.currentPart != null)
            {
                this.StartWriting();
                if ((this.flags & MimeStreamWriter.Flags.ProduceMimeStructure) == MimeStreamWriter.Flags.ProduceMimeStructure && this.currentPart.IsMultipart)
                {
                    this.currentPart.ChildrenWrittenOut();
                }
            }
            MimePartHeaders mimePartHeaders = (part == null) ? null : part.Headers;

            this.currentPart   = part;
            this.hasAllHeaders = (mimePartHeaders != null);
            if (this.mimeWriter != null)
            {
                this.mimeWriter.StartPart();
                if (this.hasAllHeaders)
                {
                    this.CopyHeadersToWriter(mimePartHeaders, this.mimeWriter);
                }
            }
            if (this.mimeSkeletonWriter != null && outputToSkeleton)
            {
                this.mimeSkeletonWriter.StartPart();
                if (mimePartHeaders != null)
                {
                    this.CopyHeadersToWriter(mimePartHeaders, this.mimeSkeletonWriter);
                }
            }
            this.assembleHeaders = false;
            if (this.currentPart != null && (this.flags & MimeStreamWriter.Flags.ProduceMimeStructure) == MimeStreamWriter.Flags.ProduceMimeStructure)
            {
                if (mimePartHeaders == null)
                {
                    this.assembleHeaders = true;
                    if ((this.flags & MimeStreamWriter.Flags.ForceMime) == MimeStreamWriter.Flags.ForceMime)
                    {
                        Header header = Header.Create(HeaderId.MimeVersion);
                        header.Value = "1.0";
                        this.currentPart.AddHeader(header);
                    }
                }
                this.flags &= (MimeStreamWriter.Flags)(-5);
            }
        }
Exemplo n.º 3
0
        private void CopyHeadersToWriter(MimePartHeaders headers, MimeWriter writer)
        {
            Header header = null;

            foreach (Header header2 in headers)
            {
                if (header2.HeaderId == HeaderId.MimeVersion)
                {
                    header = header2;
                }
                else
                {
                    header2.WriteTo(writer);
                }
            }
            if (header != null)
            {
                header.WriteTo(writer);
            }
        }