Esempio n. 1
0
        private long WriteAttachDataObj(Attachment attachment)
        {
            OleAttachment oleAttachment = attachment as OleAttachment;
            long          result        = 0L;

            if (oleAttachment != null)
            {
                byte[] array = MimeConstants.IID_IStorage.ToByteArray();
                using (Stream stream = this.tnefWriter.StartStreamProperty(InternalSchema.AttachDataObj))
                {
                    this.tnefWriter.StreamPropertyData(array, 0, array.Length);
                    using (Stream contentStream = oleAttachment.GetContentStream(PropertyOpenMode.ReadOnly))
                    {
                        result = Util.StreamHandler.CopyStreamData(contentStream, stream);
                    }
                }
            }
            return(result);
        }
Esempio n. 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);
        }