private static StreamAttachment GetSharingMessageAttachment(MessageItem item)
        {
            bool flag = true;

            foreach (AttachmentHandle handle in item.AttachmentCollection)
            {
                Attachment attachment = item.AttachmentCollection.Open(handle, null);
                try
                {
                    string valueOrDefault  = attachment.GetValueOrDefault <string>(AttachmentSchema.AttachMimeTag, string.Empty);
                    string valueOrDefault2 = attachment.GetValueOrDefault <string>(AttachmentSchema.AttachLongFileName, string.Empty);
                    if (StringComparer.InvariantCultureIgnoreCase.Equals(valueOrDefault, "application/x-sharing-metadata-xml") && StringComparer.InvariantCultureIgnoreCase.Equals(valueOrDefault2, "sharing_metadata.xml") && attachment is StreamAttachment)
                    {
                        flag = false;
                        return((StreamAttachment)attachment);
                    }
                }
                finally
                {
                    if (flag)
                    {
                        attachment.Dispose();
                    }
                }
            }
            return(null);
        }
예제 #2
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);
        }