コード例 #1
0
        private IImapMimeProvider GetAttachedItemConverter(ref MimePartInfo part, ref Item item, ref EncodingOptions itemEncodingOptions, List <IDisposable> disposeList)
        {
            if (part.ContentType != MimePartContentType.ItemAttachment)
            {
                return(null);
            }
            IImapMimeProvider imapMimeProvider;

            if (part.SmimePart == null)
            {
                Attachment attachment = item.AttachmentCollection.Open(part.AttachmentId, InternalSchema.ContentConversionProperties);
                disposeList.Add(attachment);
                ItemAttachment itemAttachment = attachment as ItemAttachment;
                if (itemAttachment == null)
                {
                    StorageGlobals.ContextTraceError(ExTraceGlobals.CcOutboundMimeTracer, "ImapItemConverter::GetAttachedItemConverter: attachment is not an item.");
                    ExAssert.RetailAssert(false, "ImapItemConverter::GetAttachedItemConverter: attachment is not an item.");
                    return(null);
                }
                item = ConvertUtils.OpenAttachedItem(itemAttachment);
                if (item == null)
                {
                    return(null);
                }
                disposeList.Add(item);
                ItemToMimeConverter itemToMimeConverter = new ItemToMimeConverter(item, this.options, ConverterFlags.IsEmbeddedMessage);
                imapMimeProvider = IImapMimeProvider.CreateInstance(itemToMimeConverter);
                disposeList.Add(imapMimeProvider);
                itemEncodingOptions = itemToMimeConverter.GetItemMimeEncodingOptions(this.options);
                if (part.AttachedItemStructure != null)
                {
                    itemToMimeConverter.SetSkeletonAndSmimeDoc(part.AttachedItemStructure.Skeleton, part.AttachedItemStructure.SmimeDocument);
                }
            }
            else
            {
                imapMimeProvider = IImapMimeProvider.CreateInstance((MimePart)part.SmimePart.FirstChild, part.SmimeDocument);
                disposeList.Add(imapMimeProvider);
                itemEncodingOptions = this.itemEncodingOptions;
            }
            if (part.AttachedItemStructure == null)
            {
                part.AttachedItemStructure = imapMimeProvider.CalculateMimeStructure(Charset.GetCharset(itemEncodingOptions.CharsetName));
            }
            part = part.AttachedItemStructure;
            return(imapMimeProvider);
        }
コード例 #2
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);
        }