Esempio 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();
     }
 }
Esempio n. 2
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);
        }