Exemplo 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();
     }
 }
        // Token: 0x06001988 RID: 6536 RVA: 0x000953D4 File Offset: 0x000935D4
        internal Stream GetItemAttachmentStream(Attachment attachment, HttpContext httpContext)
        {
            OwaContext  owaContext  = OwaContext.Get(httpContext);
            UserContext userContext = owaContext.UserContext;
            OutboundConversionOptions outboundConversionOptions = Utilities.CreateOutboundConversionOptions(userContext);
            Stream         stream         = Streams.CreateTemporaryStorageStream();
            string         text           = null;
            ItemAttachment itemAttachment = attachment as ItemAttachment;

            using (Item item = itemAttachment.GetItem(StoreObjectSchema.ContentConversionProperties))
            {
                try
                {
                    if (ItemConversion.IsItemClassConvertibleToMime(item.ClassName))
                    {
                        ItemConversion.ConvertItemToMime(item, stream, outboundConversionOptions);
                        text = ".eml";
                    }
                    else if (ObjectClass.IsCalendarItemCalendarItemOccurrenceOrRecurrenceException(item.ClassName))
                    {
                        (item as CalendarItemBase).ExportAsICAL(stream, "UTF-8", outboundConversionOptions);
                        text = ".ics";
                    }
                    else if (ObjectClass.IsContact(item.ClassName))
                    {
                        Contact.ExportVCard(item as Contact, stream, outboundConversionOptions);
                        text = ".vcf";
                    }
                    else
                    {
                        ItemConversion.ConvertItemToMsgStorage(item, stream, outboundConversionOptions);
                    }
                }
                catch (Exception)
                {
                    stream = this.GetContentsReplacementStream(-1706159495);
                    text   = ".txt";
                }
            }
            if (text != null)
            {
                this.fileName             = this.GetConvertedItemFileName(this.fileName, text);
                this.encodedfileNameBytes = this.GetEncodedString(this.fileName);
            }
            stream.Position = 0L;
            return(stream);
        }