private static bool TryProcessUnprotectedAttachment(IExchangePrincipal exchangePrincipal, Item item, StreamAttachment streamAttachment, PropertyOpenMode openMode, WacUtilities.AttachmentProcessor attachmentProcessor) { if (openMode == PropertyOpenMode.Modify) { item.OpenAsReadWrite(); } bool result; using (Stream contentStream = streamAttachment.GetContentStream(openMode)) { bool flag = WacUtilities.IsContentProtected(streamAttachment.FileName, contentStream); if (flag) { result = false; } else { attachmentProcessor(exchangePrincipal, streamAttachment, contentStream, false); if (openMode == PropertyOpenMode.Modify) { item.Save(SaveMode.NoConflictResolution); } result = true; } } return(result); }
public static void ProcessAttachment(IStoreSession session, string ewsAttachmentId, IExchangePrincipal exchangePrincipal, PropertyOpenMode openMode, WacUtilities.AttachmentProcessor attachmentProcessor) { IdConverterDependencies converterDependencies = new IdConverterDependencies.FromRawData(false, false, null, null, exchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), session as MailboxSession, session as MailboxSession, session as PublicFolderSession); using (AttachmentHandler.IAttachmentRetriever attachmentRetriever = AttachmentRetriever.CreateInstance(ewsAttachmentId, converterDependencies)) { bool flag = WacUtilities.IsIrmRestricted(attachmentRetriever.RootItem); if (openMode == PropertyOpenMode.Modify) { attachmentRetriever.RootItem.OpenAsReadWrite(); } StreamAttachment streamAttachment = attachmentRetriever.Attachment as StreamAttachment; if (streamAttachment == null) { attachmentProcessor(exchangePrincipal, attachmentRetriever.Attachment, null, flag); } else { using (Stream contentStream = streamAttachment.GetContentStream(openMode)) { bool flag2 = WacUtilities.IsContentProtected(attachmentRetriever.Attachment.FileName, contentStream); attachmentProcessor(exchangePrincipal, streamAttachment, contentStream, flag || flag2); if (openMode == PropertyOpenMode.Modify) { attachmentRetriever.RootItem.Save(SaveMode.NoConflictResolution); } } } } }