コード例 #1
0
        internal static ReadOnlyCollection <AttachmentLink> MergeAttachmentLinks(IList <AttachmentLink> existingLinks, CoreAttachmentCollection attachments)
        {
            IList <AttachmentLink> list;

            if (attachments != null)
            {
                list = ((existingLinks == null) ? new List <AttachmentLink>(attachments.Count) : new List <AttachmentLink>(existingLinks));
                ICollection <PropertyDefinition> preloadProperties = new PropertyDefinition[]
                {
                    AttachmentSchema.AttachContentId
                };
                using (IEnumerator <AttachmentHandle> enumerator = attachments.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        AttachmentHandle handle = enumerator.Current;
                        using (CoreAttachment coreAttachment = attachments.Open(handle, preloadProperties))
                        {
                            using (Attachment attachment = AttachmentCollection.CreateTypedAttachment(coreAttachment, null))
                            {
                                if (AttachmentLink.Find(attachment.Id, list) == null)
                                {
                                    AttachmentLink item = new AttachmentLink(attachment);
                                    list.Add(item);
                                }
                            }
                        }
                    }
                    goto IL_C5;
                }
            }
            list = ((existingLinks == null) ? new List <AttachmentLink>(0) : new List <AttachmentLink>(existingLinks));
IL_C5:
            return(new ReadOnlyCollection <AttachmentLink>(list));
        }
コード例 #2
0
 internal void CopyAttachmentContentFrom(CoreAttachment sourceAttachment)
 {
     this.CheckDisposed(null);
     sourceAttachment.PropertyBag.Load(InternalSchema.ContentConversionProperties);
     foreach (NativeStorePropertyDefinition property in sourceAttachment.PropertyBag.AllNativeProperties)
     {
         if (CoreAttachment.ShouldPropertyBeCopied(property, sourceAttachment.AttachmentType, this.AttachmentType))
         {
             PersistablePropertyBag.CopyProperty(sourceAttachment.PropertyBag, property, this.PropertyBag);
         }
     }
     if (sourceAttachment.AttachmentType == AttachmentType.EmbeddedMessage && this.AttachmentType == AttachmentType.EmbeddedMessage)
     {
         bool noMessageDecoding  = sourceAttachment.ParentCollection.ContainerItem.CharsetDetector.NoMessageDecoding;
         bool noMessageDecoding2 = this.parentCollection.ContainerItem.CharsetDetector.NoMessageDecoding;
         using (ICoreItem coreItem = sourceAttachment.PropertyBag.OpenAttachedItem(PropertyOpenMode.ReadOnly, InternalSchema.ContentConversionProperties, noMessageDecoding))
         {
             using (ICoreItem coreItem2 = this.PropertyBag.OpenAttachedItem(PropertyOpenMode.Create, InternalSchema.ContentConversionProperties, noMessageDecoding2))
             {
                 CoreItem.CopyItemContent(coreItem, coreItem2);
                 using (Item item = Item.InternalBindCoreItem(coreItem2))
                 {
                     item.CharsetDetector.DetectionOptions.PreferredInternetCodePageForShiftJis = coreItem.PropertyBag.GetValueOrDefault <int>(ItemSchema.InternetCpid, 50222);
                     item.LocationIdentifierHelperInstance.SetLocationIdentifier(64373U);
                     item.SaveFlags = (((PersistablePropertyBag)coreItem.PropertyBag).SaveFlags | PropertyBagSaveFlags.IgnoreMapiComputedErrors | PropertyBagSaveFlags.IgnoreAccessDeniedErrors);
                     item.Save(SaveMode.NoConflictResolution);
                 }
             }
         }
     }
     this.PropertyBag.SaveFlags |= (PropertyBagSaveFlags.IgnoreMapiComputedErrors | PropertyBagSaveFlags.IgnoreUnresolvedHeaders);
 }
コード例 #3
0
        public static bool IsMessageOpaqueSigned(Item item)
        {
            Util.ThrowOnNullArgument(item, "item");
            ICoreItem coreItem       = item.CoreItem;
            string    valueOrDefault = coreItem.PropertyBag.GetValueOrDefault <string>(InternalSchema.ItemClass, string.Empty);

            if (!ObjectClass.IsSmime(valueOrDefault))
            {
                return(false);
            }
            if (coreItem.AttachmentCollection.Count != 1)
            {
                return(false);
            }
            IList <AttachmentHandle> allHandles = coreItem.AttachmentCollection.GetAllHandles();
            bool result;

            using (CoreAttachment coreAttachment = coreItem.AttachmentCollection.Open(allHandles[0]))
            {
                using (StreamAttachment streamAttachment = (StreamAttachment)AttachmentCollection.CreateTypedAttachment(coreAttachment, new AttachmentType?(AttachmentType.Stream)))
                {
                    if (streamAttachment == null)
                    {
                        result = false;
                    }
                    else
                    {
                        result = ConvertUtils.IsMessageOpaqueSigned(coreItem, streamAttachment);
                    }
                }
            }
            return(result);
        }
コード例 #4
0
 public PropertyError[] CopyProperties(CoreAttachment destinationAttachment, CopyPropertiesFlags copyPropertiesFlags, NativeStorePropertyDefinition[] includeProperties)
 {
     this.CheckDisposed(null);
     Util.ThrowOnNullArgument(destinationAttachment, "destinationAttachment");
     Util.ThrowOnNullArgument(includeProperties, "includeProperties");
     EnumValidator.ThrowIfInvalid <CopyPropertiesFlags>(copyPropertiesFlags, "copyPropertiesFlags");
     return(CoreObject.MapiCopyProps(this.PropertyBag.MapiProp, destinationAttachment.PropertyBag.MapiProp, this.Session, destinationAttachment.Session, copyPropertiesFlags, includeProperties));
 }
コード例 #5
0
 internal CoreAttachment CreateCopy(CoreAttachment attachmentToCopy)
 {
     this.CheckDisposed(null);
     Util.ThrowOnNullArgument(attachmentToCopy, "attachmentToCopy");
     ExTraceGlobals.StorageTracer.Information((long)this.GetHashCode(), "Storage.CoreAttachmentCollection.CreateCopy");
     this.InitCollection("CreateCopy", true);
     return(this.InternalCreateCopy(new AttachmentType?(attachmentToCopy.AttachmentType), attachmentToCopy));
 }
コード例 #6
0
 internal override void CoreObjectUpdate(CoreAttachment coreAttachment)
 {
     base.CoreObjectUpdate(coreAttachment);
     StreamAttachmentBase.CoreObjectUpdateStreamAttachmentName(coreAttachment);
     try
     {
         StreamAttachmentBase.CoreObjectUpdateImageThumbnail(coreAttachment);
     }
     catch (FileNotFoundException)
     {
     }
 }
コード例 #7
0
        public Attachment Open(AttachmentHandle handle, ICollection <PropertyDefinition> propertyDefinitions)
        {
            Util.ThrowOnNullArgument(handle, "handle");
            Attachment result = null;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                CoreAttachment coreAttachment = this.CoreAttachmentCollection.Open(handle, propertyDefinitions);
                disposeGuard.Add <CoreAttachment>(coreAttachment);
                result = AttachmentCollection.CreateTypedAttachment(coreAttachment, null);
                disposeGuard.Success();
            }
            return(result);
        }
コード例 #8
0
        public ItemAttachment AddExistingItem(IItem item)
        {
            Util.ThrowOnNullArgument(item, "item");
            ItemAttachment result = null;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                CoreAttachment coreAttachment = this.CoreAttachmentCollection.CreateFromExistingItem(item);
                disposeGuard.Add <CoreAttachment>(coreAttachment);
                result = (ItemAttachment)AttachmentCollection.CreateTypedAttachment(coreAttachment, new AttachmentType?(AttachmentType.EmbeddedMessage));
                disposeGuard.Success();
            }
            return(result);
        }
コード例 #9
0
        public ItemAttachment Create(StoreObjectType type)
        {
            EnumValidator.ThrowIfInvalid <StoreObjectType>(type, "type");
            ItemAttachment result = null;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                CoreAttachment coreAttachment = this.CoreAttachmentCollection.CreateItemAttachment(type);
                disposeGuard.Add <CoreAttachment>(coreAttachment);
                result = (ItemAttachment)AttachmentCollection.CreateTypedAttachment(coreAttachment, new AttachmentType?(AttachmentType.EmbeddedMessage));
                disposeGuard.Success();
            }
            return(result);
        }
コード例 #10
0
        private CoreAttachment InternalOpen(AttachmentHandle handle, ICollection <PropertyDefinition> preloadProperties)
        {
            PropertyBag propertyBag = handle.GetAndRemoveCachedPropertyBag();

            if (propertyBag == null)
            {
                PropertyBag[] array = this.attachmentProvider.QueryAttachmentTable(this.fetchProperties.ToArray <NativeStorePropertyDefinition>());
                if (array == null || array.Length == 0)
                {
                    throw new InvalidOperationException("Attachment table is empty.");
                }
                foreach (PropertyBag propertyBag2 in array)
                {
                    int num = (int)propertyBag2[InternalSchema.AttachNum];
                    if (handle.AttachNumber == num)
                    {
                        propertyBag = propertyBag2;
                    }
                    else
                    {
                        AttachmentHandle attachmentHandle = null;
                        if (this.savedAttachmentNumberMap.TryGetValue(num, out attachmentHandle))
                        {
                            attachmentHandle.SetCachedPropertyBag(propertyBag2);
                        }
                    }
                }
            }
            if (propertyBag == null)
            {
                throw new InvalidOperationException("Attachment instance doesn't exist.");
            }
            CoreAttachment result = null;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                AttachmentPropertyBag attachmentPropertyBag = new AttachmentPropertyBag(this.attachmentProvider, handle.AttachNumber, propertyBag, this.fetchProperties, false);
                disposeGuard.Add <AttachmentPropertyBag>(attachmentPropertyBag);
                attachmentPropertyBag.ExTimeZone = this.ExTimeZone;
                if (preloadProperties == (ICollection <PropertyDefinition>)InternalSchema.ContentConversionProperties || (preloadProperties != null && preloadProperties.Count != 0))
                {
                    attachmentPropertyBag.Load(preloadProperties);
                }
                this.UpdateAttachmentId(attachmentPropertyBag.AttachmentId, handle.AttachNumber);
                result = new CoreAttachment(this, attachmentPropertyBag, Origin.Existing);
                disposeGuard.Success();
            }
            return(result);
        }
コード例 #11
0
        private CoreAttachment InternalCreate(AttachmentType?type, string itemClass, CoreAttachment attachmentToClone, IItem itemToAttach)
        {
            this.InitCollection("InternalCreate", true);
            AttachmentPropertyBag attachmentPropertyBag = null;
            CoreAttachment        coreAttachment        = null;
            bool flag = false;

            try
            {
                bool flag2 = false;
                if (attachmentToClone != null)
                {
                    flag2 = this.attachmentProvider.SupportsCreateClone(attachmentToClone.PropertyBag);
                }
                attachmentPropertyBag = this.InternalCreateAttachmentPropertyBag(type, flag2 ? attachmentToClone : null, itemToAttach);
                if (itemClass != null)
                {
                    ((IDirectPropertyBag)attachmentPropertyBag).SetValue(InternalSchema.ItemClass, itemClass);
                }
                AttachmentHandle attachmentHandle = new AttachmentHandle(attachmentPropertyBag.AttachmentNumber);
                coreAttachment        = new CoreAttachment(this, attachmentPropertyBag, Origin.New);
                attachmentPropertyBag = null;
                if (attachmentToClone != null && !flag2)
                {
                    coreAttachment.CopyAttachmentContentFrom(attachmentToClone);
                }
                this.newAttachmentNumberMap.Add(attachmentHandle.AttachNumber, attachmentHandle);
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    if (coreAttachment != null)
                    {
                        coreAttachment.Dispose();
                        coreAttachment = null;
                    }
                    if (attachmentPropertyBag != null)
                    {
                        attachmentPropertyBag.Dispose();
                        attachmentPropertyBag = null;
                    }
                }
            }
            return(coreAttachment);
        }
コード例 #12
0
        internal static bool IsSmimeMessage(ICoreItem coreItem, out bool isMultipartSigned, out bool isOpaqueSigned, out StreamAttachment attachment)
        {
            isMultipartSigned = false;
            isOpaqueSigned    = false;
            attachment        = null;
            string valueOrDefault = coreItem.PropertyBag.GetValueOrDefault <string>(InternalSchema.ItemClass, string.Empty);

            if (!ObjectClass.IsSmime(valueOrDefault))
            {
                return(false);
            }
            IList <AttachmentHandle> allHandles = coreItem.AttachmentCollection.GetAllHandles();

            if (allHandles.Count != 1)
            {
                return(false);
            }
            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                CoreAttachment coreAttachment = coreItem.AttachmentCollection.Open(allHandles[0]);
                disposeGuard.Add <CoreAttachment>(coreAttachment);
                StreamAttachment streamAttachment = (StreamAttachment)AttachmentCollection.CreateTypedAttachment(coreAttachment, new AttachmentType?(AttachmentType.Stream));
                if (streamAttachment == null)
                {
                    return(false);
                }
                disposeGuard.Add <StreamAttachment>(streamAttachment);
                if (ObjectClass.IsSmimeClearSigned(valueOrDefault))
                {
                    isMultipartSigned = ConvertUtils.IsMessageMultipartSigned(coreItem, streamAttachment);
                    if (isMultipartSigned)
                    {
                        attachment = streamAttachment;
                        disposeGuard.Success();
                        return(true);
                    }
                }
                isOpaqueSigned = ConvertUtils.IsMessageOpaqueSigned(coreItem, streamAttachment);
                if (isOpaqueSigned)
                {
                    attachment = streamAttachment;
                    disposeGuard.Success();
                    return(true);
                }
            }
            return(false);
        }
コード例 #13
0
        internal static Uri GetUriProperty(CoreAttachment coreAttachment, StorePropertyDefinition property)
        {
            string text = ((IDirectPropertyBag)coreAttachment.PropertyBag).GetValue(property) as string;

            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }
            Uri result;

            if (!Uri.TryCreate(text, UriKind.RelativeOrAbsolute, out result))
            {
                ExTraceGlobals.StorageTracer.TraceError <StorePropertyDefinition, string>((long)coreAttachment.GetHashCode(), "CoreAttachment.GetUriProperty: {0} is not a valid URI\r\n'{1}'", property, text);
                return(null);
            }
            return(result);
        }
コード例 #14
0
        internal static void CoreObjectUpdateReferenceAttachmentName(CoreAttachment coreAttachment)
        {
            ICorePropertyBag propertyBag = coreAttachment.PropertyBag;
            string           text        = propertyBag.TryGetProperty(InternalSchema.DisplayName) as string;
            string           text2       = propertyBag.TryGetProperty(InternalSchema.AttachExtension) as string;

            if (!string.IsNullOrEmpty(text))
            {
                text = Attachment.TrimFilename(text);
                propertyBag[InternalSchema.DisplayName] = text;
            }
            if (!string.IsNullOrEmpty(text2))
            {
                text2 = '.' + Attachment.TrimFilename(text2);
                propertyBag[InternalSchema.AttachExtension] = (text2 ?? string.Empty);
            }
        }
コード例 #15
0
        internal CoreAttachment InternalCreateCopy(AttachmentType?type, CoreAttachment attachmentToClone)
        {
            this.CheckDisposed(null);
            this.InitCollection("InternalCreateCopy", true);
            CoreAttachment result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                CoreAttachment coreAttachment = this.InternalCreate(type, null, attachmentToClone, null);
                disposeGuard.Add <CoreAttachment>(coreAttachment);
                int valueOrDefault = attachmentToClone.PropertyBag.GetValueOrDefault <int>(InternalSchema.RenderingPosition, -1);
                coreAttachment.PropertyBag.SetOrDeleteProperty(InternalSchema.RenderingPosition, valueOrDefault);
                disposeGuard.Success();
                result = coreAttachment;
            }
            return(result);
        }
コード例 #16
0
ファイル: Attachment.cs プロジェクト: YHZX2013/exchange_diff
        private static CoreAttachment CopyAttachment(CoreAttachment sourceAttachment, ICollection <NativeStorePropertyDefinition> excludeProperties)
        {
            CoreAttachment coreAttachment = null;

            if (sourceAttachment != null)
            {
                coreAttachment = sourceAttachment.ParentCollection.Create(AttachmentType.Stream);
                sourceAttachment.PropertyBag.Load(InternalSchema.ContentConversionProperties);
                foreach (NativeStorePropertyDefinition nativeStorePropertyDefinition in sourceAttachment.PropertyBag.AllNativeProperties)
                {
                    if (excludeProperties == null || !excludeProperties.Contains(nativeStorePropertyDefinition))
                    {
                        PersistablePropertyBag.CopyProperty(sourceAttachment.PropertyBag, nativeStorePropertyDefinition, coreAttachment.PropertyBag);
                    }
                }
            }
            return(coreAttachment);
        }
コード例 #17
0
 internal static void CloneAttachmentCollection(ICoreItem sourceItem, ICoreItem destinationItem)
 {
     foreach (AttachmentHandle handle in sourceItem.AttachmentCollection)
     {
         using (CoreAttachment coreAttachment = sourceItem.AttachmentCollection.Open(handle, CoreObjectSchema.AllPropertiesOnStore))
         {
             using (CoreAttachment coreAttachment2 = destinationItem.AttachmentCollection.CreateCopy(coreAttachment))
             {
                 using (Attachment attachment = AttachmentCollection.CreateTypedAttachment(coreAttachment2, new AttachmentType?(coreAttachment2.AttachmentType)))
                 {
                     attachment.SaveFlags |= (coreAttachment.PropertyBag.SaveFlags | PropertyBagSaveFlags.IgnoreMapiComputedErrors);
                     attachment.Save();
                 }
             }
         }
     }
     destinationItem.AttachmentCollection.IsClonedFromAnExistingAttachmentCollection = (sourceItem.AttachmentCollection.Count > 0 && !sourceItem.AttachmentCollection.IsDirty && sourceItem.AttachmentCollection.Count == destinationItem.AttachmentCollection.Count);
 }
コード例 #18
0
        public Attachment Create(AttachmentType?type, Attachment clone)
        {
            if (type != null)
            {
                EnumValidator.ThrowIfInvalid <AttachmentType>(type.Value, "type");
            }
            Util.ThrowOnNullArgument(clone, "clone");
            Attachment result = null;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                CoreAttachment coreAttachment = this.CoreAttachmentCollection.InternalCreateCopy(type, clone.CoreAttachment);
                disposeGuard.Add <CoreAttachment>(coreAttachment);
                result = AttachmentCollection.CreateTypedAttachment(coreAttachment, type);
                disposeGuard.Success();
            }
            return(result);
        }
コード例 #19
0
        public StreamAttachment ConvertToImageAttachment(CoreAttachmentCollection collection, ImageFormat format)
        {
            base.CheckDisposed("ConvertToImageAttachment");
            Util.ThrowOnNullArgument(collection, "collection");
            EnumValidator.ThrowIfInvalid <ImageFormat>(format);
            StreamAttachment result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                CoreAttachment coreAttachment = collection.InternalCreateCopy(new AttachmentType?(AttachmentType.Stream), base.CoreAttachment);
                disposeGuard.Add <CoreAttachment>(coreAttachment);
                StreamAttachment streamAttachment = (StreamAttachment)AttachmentCollection.CreateTypedAttachment(coreAttachment, new AttachmentType?(AttachmentType.Stream));
                disposeGuard.Add <StreamAttachment>(streamAttachment);
                string text = streamAttachment.FileName;
                if (string.IsNullOrEmpty(text))
                {
                    text = Attachment.GenerateFilename();
                }
                string str = null;
                switch (format)
                {
                case ImageFormat.Jpeg:
                    str = ".jpg";
                    break;

                case ImageFormat.Png:
                    str = ".png";
                    break;
                }
                streamAttachment.FileName    = text + str;
                streamAttachment.ContentType = "image/jpeg";
                streamAttachment.IsInline    = true;
                using (Stream contentStream = streamAttachment.GetContentStream(PropertyOpenMode.Create))
                {
                    if (!this.TryConvertToImage(contentStream, ImageFormat.Jpeg))
                    {
                        ConvertUtils.SaveDefaultImage(contentStream);
                    }
                }
                disposeGuard.Success();
                result = streamAttachment;
            }
            return(result);
        }
コード例 #20
0
        private AttachmentPropertyBag InternalCreateAttachmentPropertyBag(AttachmentType?type, CoreAttachment attachmentToClone, IItem itemToAttach)
        {
            this.InitCollection("InternalCreateAttachmentPropertyBag", true);
            bool flag             = false;
            int  attachmentNumber = -1;
            PersistablePropertyBag persistablePropertyBag = null;
            AttachmentPropertyBag  attachmentPropertyBag  = null;

            try
            {
                Schema attachmentSchema = CoreAttachmentCollection.GetAttachmentSchema(type);
                ICollection <PropertyDefinition> prefetchProperties = InternalSchema.Combine <PropertyDefinition>(attachmentSchema.AutoloadProperties, (ICollection <PropertyDefinition>) this.fetchProperties);
                persistablePropertyBag           = this.attachmentProvider.CreateAttachment(prefetchProperties, attachmentToClone, itemToAttach, out attachmentNumber);
                attachmentPropertyBag            = new AttachmentPropertyBag(this.attachmentProvider, attachmentNumber, persistablePropertyBag, true);
                attachmentPropertyBag.ExTimeZone = this.ExTimeZone;
                if (type != null)
                {
                    int num = CoreAttachment.AttachmentTypeToAttachMethod(type.Value);
                    ((IDirectPropertyBag)attachmentPropertyBag).SetValue(InternalSchema.AttachMethod, num);
                }
                this.isDirty = true;
                this.IsClonedFromAnExistingAttachmentCollection = false;
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    if (attachmentPropertyBag != null)
                    {
                        attachmentPropertyBag.Dispose();
                        attachmentPropertyBag = null;
                    }
                    if (persistablePropertyBag != null)
                    {
                        persistablePropertyBag.Dispose();
                        persistablePropertyBag = null;
                    }
                }
            }
            return(attachmentPropertyBag);
        }
コード例 #21
0
        public Attachment Create(AttachmentType type)
        {
            EnumValidator.ThrowIfInvalid <AttachmentType>(type, new AttachmentType[]
            {
                AttachmentType.Stream,
                AttachmentType.EmbeddedMessage,
                AttachmentType.Ole,
                AttachmentType.Reference
            });
            Attachment result = null;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                CoreAttachment coreAttachment = this.CoreAttachmentCollection.Create(type);
                disposeGuard.Add <CoreAttachment>(coreAttachment);
                result = AttachmentCollection.CreateTypedAttachment(coreAttachment, new AttachmentType?(type));
                disposeGuard.Success();
            }
            return(result);
        }
コード例 #22
0
        internal static Attachment CreateTypedAttachment(CoreAttachment attachment, AttachmentType?type)
        {
            int?num = ((IDirectPropertyBag)attachment.PropertyBag).GetValue(InternalSchema.AttachMethod) as int?;

            if (num != null)
            {
                switch (num.Value)
                {
                case 2:
                case 3:
                case 4:
                case 7:
                    if (type != null && !(type == AttachmentType.Reference))
                    {
                        return(null);
                    }
                    return(new ReferenceAttachment(attachment));

                case 5:
                    if (type != null && !(type == AttachmentType.EmbeddedMessage))
                    {
                        return(null);
                    }
                    return(new ItemAttachment(attachment));

                case 6:
                    if (type != null && !(type == AttachmentType.Ole))
                    {
                        return(null);
                    }
                    return(new OleAttachment(attachment));
                }
            }
            if (type != null && !(type == AttachmentType.Stream))
            {
                return(null);
            }
            return(new StreamAttachment(attachment));
        }
コード例 #23
0
        internal Attachment Open(AttachmentHandle handle, AttachmentType?type, ICollection <PropertyDefinition> propertyDefinitions)
        {
            Util.ThrowOnNullArgument(handle, "handle");
            if (type != null)
            {
                EnumValidator.ThrowIfInvalid <AttachmentType>(type.Value, "type");
            }
            Attachment     attachment     = null;
            CoreAttachment coreAttachment = null;

            try
            {
                coreAttachment = this.CoreAttachmentCollection.Open(handle, propertyDefinitions);
                attachment     = AttachmentCollection.CreateTypedAttachment(coreAttachment, type);
            }
            finally
            {
                if (attachment == null && coreAttachment != null)
                {
                    coreAttachment.Dispose();
                }
            }
            return(attachment);
        }
コード例 #24
0
ファイル: Attachment.cs プロジェクト: YHZX2013/exchange_diff
 internal Attachment(CoreAttachment coreAttachment)
 {
     StorageGlobals.TraceConstructIDisposable(this);
     this.disposeTracker = this.GetDisposeTracker();
     this.coreAttachment = coreAttachment;
 }
コード例 #25
0
 internal static void CoreObjectUpdateImageThumbnail(CoreAttachment coreAttachment)
 {
 }
コード例 #26
0
 internal ReferenceAttachment(CoreAttachment coreAttachment) : base(coreAttachment)
 {
 }
コード例 #27
0
        public PersistablePropertyBag CreateAttachment(ICollection <PropertyDefinition> propertiesToLoad, CoreAttachment attachmentToClone, IItem itemToAttach, out int attachmentNumber)
        {
            this.CheckDisposed(null);
            InMemoryPersistablePropertyBag inMemoryPersistablePropertyBag = new InMemoryPersistablePropertyBag(propertiesToLoad);

            inMemoryPersistablePropertyBag.ExTimeZone = this.ExTimeZone;
            if (attachmentToClone != null)
            {
                throw new NotSupportedException("CreateAttachment for copied attachments is not supported");
            }
            attachmentNumber = this.attachmentCounter++;
            inMemoryPersistablePropertyBag[InternalSchema.AttachNum] = attachmentNumber;
            this.newAttachmentList.Add(attachmentNumber, inMemoryPersistablePropertyBag);
            if (itemToAttach != null)
            {
                string text   = itemToAttach.TryGetProperty(InternalSchema.ItemClass) as string;
                Schema schema = (text != null) ? ObjectClass.GetSchema(text) : ItemSchema.Instance;
                propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema.AutoloadProperties, propertiesToLoad);
                using (DisposeGuard disposeGuard = default(DisposeGuard))
                {
                    PersistablePropertyBag persistablePropertyBag = new InMemoryPersistablePropertyBag(propertiesToLoad);
                    disposeGuard.Add <PersistablePropertyBag>(persistablePropertyBag);
                    persistablePropertyBag.ExTimeZone = this.ExTimeZone;
                    CoreItem coreItem = new CoreItem(null, persistablePropertyBag, null, null, Origin.New, ItemLevel.Attached, propertiesToLoad, ItemBindOption.LoadRequiredPropertiesOnly);
                    disposeGuard.Add <CoreItem>(coreItem);
                    CoreItem.CopyItemContent(itemToAttach.CoreItem, coreItem);
                    this.attachedItems.Add(attachmentNumber, coreItem);
                    disposeGuard.Success();
                }
            }
            return(inMemoryPersistablePropertyBag);
        }
コード例 #28
0
 internal ItemAttachment(CoreAttachment coreAttachment) : base(coreAttachment)
 {
 }
コード例 #29
0
        public virtual bool SaveChanges()
        {
            if (this.AttachmentCollection == null)
            {
                throw new InvalidOperationException("Target item not specified; callback cannot invoke attachment-specific methods");
            }
            bool result = false;

            if (this.attachmentLinks != null)
            {
                using (IEnumerator <AttachmentLink> enumerator = this.attachmentLinks.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        AttachmentLink attachmentLink = enumerator.Current;
                        using (CoreAttachment coreAttachment = this.AttachmentCollection.Open(attachmentLink.AttachmentId))
                        {
                            using (Attachment attachment = Microsoft.Exchange.Data.Storage.AttachmentCollection.CreateTypedAttachment(coreAttachment, null))
                            {
                                if (this.removeUnlinkedAttachments && !attachmentLink.IsInline(this.requireMarkInline) && attachment.IsInline)
                                {
                                    attachment.Dispose();
                                    this.AttachmentCollection.Remove(attachmentLink.AttachmentId);
                                }
                                else
                                {
                                    if (attachmentLink.NeedsConversionToImage && attachment.AttachmentType == AttachmentType.Ole)
                                    {
                                        OleAttachment oleAttachment = attachment as OleAttachment;
                                        if (oleAttachment == null)
                                        {
                                            continue;
                                        }
                                        using (Attachment attachment2 = oleAttachment.ConvertToImageAttachment(this.AttachmentCollection, ImageFormat.Jpeg))
                                        {
                                            result = true;
                                            attachmentLink.MakeAttachmentChanges(attachment2, this.requireMarkInline);
                                            attachment2.Save();
                                            continue;
                                        }
                                    }
                                    if (attachmentLink.MakeAttachmentChanges(attachment, this.requireMarkInline))
                                    {
                                        result = true;
                                        attachment.Save();
                                    }
                                }
                            }
                        }
                    }
                    return(result);
                }
            }
            if (this.requireMarkInline)
            {
                List <AttachmentId> list = null;
                foreach (AttachmentHandle handle in this.AttachmentCollection)
                {
                    using (CoreAttachment coreAttachment2 = this.AttachmentCollection.Open(handle))
                    {
                        if (coreAttachment2.IsInline)
                        {
                            if (this.removeUnlinkedAttachments)
                            {
                                if (list == null)
                                {
                                    list = new List <AttachmentId>();
                                }
                                list.Add(coreAttachment2.Id);
                            }
                            else
                            {
                                coreAttachment2.IsInline = false;
                                result = true;
                                coreAttachment2.Save();
                            }
                        }
                    }
                }
                if (list != null)
                {
                    foreach (AttachmentId id in list)
                    {
                        this.AttachmentCollection.Remove(id);
                    }
                }
            }
            return(result);
        }
コード例 #30
0
 internal override void CoreObjectUpdate(CoreAttachment coreAttachment)
 {
     base.CoreObjectUpdate(coreAttachment);
     ReferenceAttachment.CoreObjectUpdateReferenceAttachmentName(coreAttachment);
 }