private Stream InternalOpenOleAttachmentStream() { if (this.subStorageType != MsgSubStorageType.Attachment || this.attachMethod != 6) { throw new InvalidOperationException(MsgStorageStrings.NotAnOleAttachment); } ComStorage comStorage = null; ComStorage comStorage2 = null; Stream stream = Streams.CreateTemporaryStorageStream(); try { string storageName = Util.PropertyStreamName(TnefPropertyTag.AttachDataObj); comStorage = this.propertiesStorage.OpenStorage(storageName, ComStorage.OpenMode.Read); comStorage2 = ComStorage.CreateStorageOnStream(stream, ComStorage.OpenMode.CreateWrite); ComStorage.CopyStorageContent(comStorage, comStorage2); comStorage2.Flush(); } finally { if (comStorage != null) { comStorage.Dispose(); } if (comStorage2 != null) { comStorage2.Dispose(); } } stream.Position = 0L; return(stream); }
private static uint[] CompressAndWriteOutputStream(Stream outputStream, Stream inputStream, bool doComputeCrc) { if (outputStream == null) { throw new ArgumentNullException("outputStream"); } if (inputStream == null) { throw new ArgumentNullException("inputStream"); } uint num = 0U; int num2 = 0; BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(ZipEntryAttachment.CopyBufferSize); byte[] array = bufferPool.Acquire(); uint num3 = 0U; using (Stream stream = Streams.CreateTemporaryStorageStream()) { try { int num4; using (Stream stream2 = new DeflateStream(stream, CompressionMode.Compress, true)) { while ((num4 = inputStream.Read(array, 0, array.Length)) > 0) { if (doComputeCrc) { num3 = ZipEntryAttachment.ComputeCrc32FromBytes(array, num4, num3); } num2 += num4; stream2.Write(array, 0, num4); } stream2.Flush(); } stream.Seek(0L, SeekOrigin.Begin); while ((num4 = stream.Read(array, 0, array.Length)) > 0) { outputStream.Write(array, 0, num4); num += (uint)num4; } } finally { if (array != null) { bufferPool.Release(array); } } } return(new uint[] { num, num3, (uint)num2 }); }
// Token: 0x060002A0 RID: 672 RVA: 0x0000EFCC File Offset: 0x0000D1CC public AirSyncStream() { this.disposeTracker = this.GetDisposeTracker(); this.internalStream = Streams.CreateTemporaryStorageStream(new Func <int, byte[]>(AirSyncStream.AcquireBuffer), new Action <byte[]>(AirSyncStream.ReleaseBuffer)); if (Command.CurrentCommand != null) { Command.CurrentCommand.RegisterDisposableData(this); } }
internal Stream OpenOleAttachmentStream() { if (this.attachMethod != 6) { throw new InvalidOperationException(MsgStorageStrings.NotAnOleAttachment); } Stream cacheStream = Streams.CreateTemporaryStorageStream(); MsgStorageWriteStream msgStorageWriteStream = new MsgStorageWriteStream(cacheStream, 0); msgStorageWriteStream.AddOnCloseNotifier(delegate(MsgStorageWriteStream stream, Exception onCloseException) { if (onCloseException != null) { this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWrite, MsgStorageStrings.ComExceptionThrown, onCloseException)); return; } TnefPropertyTag attachDataObj = TnefPropertyTag.AttachDataObj; ComStorage comStorage = null; ComStorage comStorage2 = null; string storageName = Util.PropertyStreamName(attachDataObj); try { cacheStream.Flush(); cacheStream.Position = 0L; comStorage = ComStorage.OpenStorageOnStream(cacheStream, ComStorage.OpenMode.Read); comStorage2 = this.subStorage.CreateStorage(storageName, ComStorage.OpenMode.CreateWrite); comStorage2.StorageClass = Util.ClassIdFileAttachment; ComStorage.CopyStorageContent(comStorage, comStorage2); comStorage2.Flush(); MsgStoragePropertyData.WriteObject(this.propertiesWriter, attachDataObj, MsgStoragePropertyData.ObjectType.Storage); } catch (IOException exc) { this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWriteOle, MsgStorageStrings.CorruptData, exc)); } catch (COMException exc2) { this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWriteOle, MsgStorageStrings.CorruptData, exc2)); } finally { if (comStorage2 != null) { comStorage2.Dispose(); } if (comStorage != null) { comStorage.Dispose(); } if (cacheStream != null) { cacheStream.Dispose(); } } }); return(msgStorageWriteStream); }
// 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); }
private Stream AttachmentsStreamCallback(object context) { if (this.decryptedItem == null) { throw new StoragePermanentException(ServerStrings.FailedToAddAttachments); } this.SaveAndCloseCurrentAttachment(); AttachmentType attachmentType = (AttachmentType)context; AttachmentType attachmentType2 = attachmentType; AttachmentType attachmentType3; if (attachmentType2 != AttachmentType.OleObject) { if (attachmentType2 != AttachmentType.ByValue) { if (attachmentType2 != AttachmentType.EmbeddedMessage) { throw new StoragePermanentException(ServerStrings.InvalidAttachmentType); } attachmentType3 = AttachmentType.EmbeddedMessage; } else { attachmentType3 = AttachmentType.Stream; } } else { attachmentType3 = AttachmentType.Ole; } AttachmentCollection attachmentCollection = this.decryptedItem.AttachmentCollection; this.currentAttachment = attachmentCollection.Create(attachmentType3); ExTraceGlobals.RightsManagementTracer.TraceDebug <AttachmentType>((long)this.GetHashCode(), "Decrypting Attachment. AttachmentType {0}", attachmentType3); StreamAttachmentBase streamAttachmentBase = this.currentAttachment as StreamAttachmentBase; if (streamAttachmentBase != null) { return(streamAttachmentBase.GetContentStream(PropertyOpenMode.Create)); } this.temporaryStreamForEmbeddedMessage = Streams.CreateTemporaryStorageStream(); return(this.temporaryStreamForEmbeddedMessage); }
private bool TryCalculateIrmBodyTag(StoreDriverDeliveryEventArgsImpl argsImpl) { MessageItem messageItem = null; bool result; try { OrganizationId organizationId = argsImpl.ADRecipientCache.OrganizationId; MessageItem replayItem = argsImpl.ReplayItem; using (Attachment attachment = this.TryOpenFirstAttachment(replayItem)) { StreamAttachmentBase streamAttachmentBase = attachment as StreamAttachmentBase; if (streamAttachmentBase == null) { ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "message.rpmsg attachment is not of the correct type"); return(false); } using (Stream contentStream = streamAttachmentBase.GetContentStream(PropertyOpenMode.ReadOnly)) { if (contentStream == null) { ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "The rights protected message is not properly formatted"); return(false); } using (DrmEmailMessageContainer drmEmailMessageContainer = new DrmEmailMessageContainer()) { try { drmEmailMessageContainer.Load(contentStream, (object param0) => Streams.CreateTemporaryStorageStream()); } catch (InvalidRpmsgFormatException) { ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "The rights protected message is not properly formatted"); return(false); } string text = null; if (!argsImpl.MailItemDeliver.MbxTransportMailItem.ExtendedProperties.TryGetValue <string>("Microsoft.Exchange.RightsManagement.TransportDecryptionUL", out text) || string.IsNullOrEmpty(text)) { ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "Failed to load the useLicense"); return(false); } try { Uri licenseUri; XmlNode[] array; bool flag; RmsClientManager.GetLicensingUri(organizationId, drmEmailMessageContainer.PublishLicense, out licenseUri, out array, out flag); RpMsgToMsgConverter rpMsgToMsgConverter = new RpMsgToMsgConverter(drmEmailMessageContainer, organizationId, false); RmsClientManagerContext context = new RmsClientManagerContext(organizationId, RmsClientManagerContext.ContextId.MessageId, replayItem.InternetMessageId, argsImpl.ADRecipientCache, new RmsLatencyTracker(argsImpl.MailItemDeliver.MbxTransportMailItem.LatencyTracker), drmEmailMessageContainer.PublishLicense); using (DisposableTenantLicensePair disposableTenantLicensePair = RmsClientManager.AcquireTenantLicenses(context, licenseUri)) { messageItem = rpMsgToMsgConverter.ConvertRpmsgToMsg(replayItem, text, disposableTenantLicensePair.EnablingPrincipalRac); } } catch (RightsManagementException arg) { ConversationsProcessingAgent.tracer.TraceError <RightsManagementException>((long)this.GetHashCode(), "Conversion failed: {0}", arg); return(false); } catch (InvalidRpmsgFormatException arg2) { ConversationsProcessingAgent.tracer.TraceError <InvalidRpmsgFormatException>((long)this.GetHashCode(), "Conversion failed: {0}", arg2); return(false); } catch (ExchangeConfigurationException arg3) { ConversationsProcessingAgent.tracer.TraceError <ExchangeConfigurationException>((long)this.GetHashCode(), "Conversion failed: {0}", arg3); return(false); } catch (AttachmentProtectionException arg4) { ConversationsProcessingAgent.tracer.TraceError <AttachmentProtectionException>((long)this.GetHashCode(), "Conversion failed: {0}", arg4); return(false); } } } } this.bodyTag = messageItem.Body.CalculateBodyTag(out this.latestMessageWordCount); if (messageItem.AttachmentCollection.Count == 0) { this.forceAllAttachmentsHidden = true; } else { foreach (AttachmentHandle attachmentHandle in messageItem.AttachmentCollection) { if (!attachmentHandle.IsInline) { break; } this.forceAllAttachmentsHidden = true; } } result = true; } finally { if (messageItem != null) { messageItem.Dispose(); } } return(result); }
public static Stream OpenRestrictedAttachment(StreamAttachment sourceAttachment, OrganizationId orgId, string userIdentity, SecurityIdentifier userSid, RecipientTypeDetails userType, out UseLicenseAndUsageRights validatedUseLicenseAndUsageRights, out bool acquiredNewLicense) { StreamAttachment.< > c__DisplayClass2 CS$ < > 8__locals1 = new StreamAttachment.< > c__DisplayClass2(); CS$ < > 8__locals1.sourceAttachment = sourceAttachment; CS$ < > 8__locals1.orgId = orgId; CS$ < > 8__locals1.userIdentity = userIdentity; CS$ < > 8__locals1.userSid = userSid; CS$ < > 8__locals1.userType = userType; Util.ThrowOnNullArgument(CS$ < > 8__locals1.sourceAttachment, "sourceAttachment"); Util.ThrowOnNullArgument(CS$ < > 8__locals1.orgId, "orgId"); Util.ThrowOnNullArgument(CS$ < > 8__locals1.userIdentity, "userIdentity"); Util.ThrowOnNullArgument(CS$ < > 8__locals1.userSid, "userSid"); if (!Enum.IsDefined(typeof(RecipientTypeDetails), CS$ < > 8__locals1.userType)) { throw new EnumArgumentException("userType"); } CS$ < > 8__locals1.cachedServerUseLicense = null; if (!PropertyError.IsPropertyNotFound(CS$ < > 8__locals1.sourceAttachment.TryGetProperty(AttachmentSchema.DRMServerLicenseCompressed))) { using (Stream stream = CS$ < > 8__locals1.sourceAttachment.OpenPropertyStream(AttachmentSchema.DRMServerLicenseCompressed, PropertyOpenMode.ReadOnly)) { CS$ < > 8__locals1.cachedServerUseLicense = DrmEmailCompression.DecompressUseLicense(stream); } } StreamAttachment.< > c__DisplayClass2 CS$ < > 8__locals2 = CS$ < > 8__locals1; int?valueAsNullable = CS$ < > 8__locals1.sourceAttachment.PropertyBag.GetValueAsNullable <int>(AttachmentSchema.DRMRights); CS$ < > 8__locals2.cachedUsageRights = ((valueAsNullable != null) ? new ContentRight?((ContentRight)valueAsNullable.GetValueOrDefault()) : null); CS$ < > 8__locals1.cachedExpiryTime = CS$ < > 8__locals1.sourceAttachment.PropertyBag.GetValueAsNullable <ExDateTime>(AttachmentSchema.DRMExpiryTime); CS$ < > 8__locals1.cachedDrmPropsSignature = CS$ < > 8__locals1.sourceAttachment.PropertyBag.GetValueOrDefault <byte[]>(AttachmentSchema.DRMPropsSignature); CS$ < > 8__locals1.item = CS$ < > 8__locals1.sourceAttachment.CoreAttachment.ParentCollection.ContainerItem; if (string.IsNullOrEmpty(CS$ < > 8__locals1.cachedServerUseLicense) || CS$ < > 8__locals1.cachedUsageRights == null || CS$ < > 8__locals1.cachedExpiryTime == null || CS$ < > 8__locals1.cachedDrmPropsSignature == null) { string valueOrDefault = CS$ < > 8__locals1.item.PropertyBag.GetValueOrDefault <string>(StoreObjectSchema.ItemClass, string.Empty); if (ObjectClass.IsMessage(valueOrDefault, false)) { CS$ < > 8__locals1.cachedServerUseLicense = CS$ < > 8__locals1.item.PropertyBag.GetValueOrDefault <string>(MessageItemSchema.DRMServerLicense, string.Empty); StreamAttachment.< > c__DisplayClass2 CS$ < > 8__locals3 = CS$ < > 8__locals1; int?valueAsNullable2 = CS$ < > 8__locals1.item.PropertyBag.GetValueAsNullable <int>(MessageItemSchema.DRMRights); CS$ < > 8__locals3.cachedUsageRights = ((valueAsNullable2 != null) ? new ContentRight?((ContentRight)valueAsNullable2.GetValueOrDefault()) : null); CS$ < > 8__locals1.cachedExpiryTime = CS$ < > 8__locals1.item.PropertyBag.GetValueAsNullable <ExDateTime>(MessageItemSchema.DRMExpiryTime); CS$ < > 8__locals1.cachedDrmPropsSignature = CS$ < > 8__locals1.item.PropertyBag.GetValueOrDefault <byte[]>(MessageItemSchema.DRMPropsSignature); } } CS$ < > 8__locals1.unprotectionSuccess = false; CS$ < > 8__locals1.useLicenseAndUsageRights = null; CS$ < > 8__locals1.validCachedLicense = false; Stream unprotectedAttachment; using (DisposeGuard disposeGuard = default(DisposeGuard)) { StreamAttachment.< > c__DisplayClass4 CS$ < > 8__locals4 = new StreamAttachment.< > c__DisplayClass4(); CS$ < > 8__locals4.unprotectedAttachment = disposeGuard.Add <Stream>(Streams.CreateTemporaryStorageStream()); CS$ < > 8__locals4.decryptorHandle = null; using (Stream inputStream = CS$ < > 8__locals1.sourceAttachment.GetContentStream(PropertyOpenMode.ReadOnly)) { try { MsgToRpMsgConverter.CallRM(delegate { CS$ < > 8__locals1.unprotectionSuccess = ProtectorsManager.Instance.Unprotect(delegate(string protectedDocumentIssuanceLicense) { string valueOrDefault2 = CS$ < > 8__locals1.item.PropertyBag.GetValueOrDefault <string>(ItemSchema.InternetMessageId, string.Empty); bool flag = string.IsNullOrEmpty(valueOrDefault2); RmsClientManagerContext context = new RmsClientManagerContext(CS$ < > 8__locals1.orgId, flag ? RmsClientManagerContext.ContextId.AttachmentFileName : RmsClientManagerContext.ContextId.MessageId, flag ? CS$ < > 8__locals1.sourceAttachment.FileName : valueOrDefault2, null); if (!string.IsNullOrEmpty(CS$ < > 8__locals1.cachedServerUseLicense) && CS$ < > 8__locals1.cachedUsageRights != null && CS$ < > 8__locals1.cachedExpiryTime != null && CS$ < > 8__locals1.cachedDrmPropsSignature != null) { try { CS$ < > 8__locals4.decryptorHandle = RmsClientManager.VerifyDRMPropsSignatureAndGetDecryptor(context, CS$ < > 8__locals1.userSid, CS$ < > 8__locals1.userType, CS$ < > 8__locals1.userIdentity, CS$ < > 8__locals1.cachedUsageRights.Value, CS$ < > 8__locals1.cachedExpiryTime.Value, CS$ < > 8__locals1.cachedDrmPropsSignature, CS$ < > 8__locals1.cachedServerUseLicense, protectedDocumentIssuanceLicense, UsageRightsSignatureVerificationOptions.LookupSidHistory, StreamAttachment.EmptySidList); CS$ < > 8__locals1.validCachedLicense = true; Uri licensingUri = null; XmlNode[] array = null; bool flag2; RmsClientManager.GetLicensingUri(CS$ < > 8__locals1.orgId, protectedDocumentIssuanceLicense, out licensingUri, out array, out flag2); CS$ < > 8__locals1.useLicenseAndUsageRights = new UseLicenseAndUsageRights(CS$ < > 8__locals1.cachedServerUseLicense, CS$ < > 8__locals1.cachedUsageRights.Value, CS$ < > 8__locals1.cachedExpiryTime.Value, CS$ < > 8__locals1.cachedDrmPropsSignature, CS$ < > 8__locals1.orgId, protectedDocumentIssuanceLicense, licensingUri); } catch (BadDRMPropsSignatureException) { } } if (CS$ < > 8__locals1.useLicenseAndUsageRights == null) { CS$ < > 8__locals1.useLicenseAndUsageRights = RmsClientManager.AcquireUseLicenseAndUsageRights(context, protectedDocumentIssuanceLicense, CS$ < > 8__locals1.userIdentity, CS$ < > 8__locals1.userSid, CS$ < > 8__locals1.userType); if (CS$ < > 8__locals4.decryptorHandle != null) { CS$ < > 8__locals4.decryptorHandle.Close(); CS$ < > 8__locals4.decryptorHandle = null; } RmsClientManager.BindUseLicenseForDecryption(context, CS$ < > 8__locals1.useLicenseAndUsageRights.LicensingUri, CS$ < > 8__locals1.useLicenseAndUsageRights.UseLicense, CS$ < > 8__locals1.useLicenseAndUsageRights.PublishingLicense, out CS$ < > 8__locals4.decryptorHandle); } return(CS$ < > 8__locals4.decryptorHandle); }, CS$ < > 8__locals1.sourceAttachment.FileName, inputStream, CS$ < > 8__locals4.unprotectedAttachment); }, ServerStrings.FailedToUnprotectAttachment(CS$ < > 8__locals1.sourceAttachment.FileName)); }
// Token: 0x0600012F RID: 303 RVA: 0x00007734 File Offset: 0x00005934 private static void LicenseMessage(IExchangePrincipal userPrincipal, MessageItem item) { string publishLicense; using (Attachment attachment = item.AttachmentCollection.Open(item.AttachmentCollection.GetHandles()[0])) { using (Stream contentStream = ((StreamAttachmentBase)attachment).GetContentStream(PropertyOpenMode.ReadOnly)) { using (DrmEmailMessageContainer drmEmailMessageContainer = new DrmEmailMessageContainer()) { try { drmEmailMessageContainer.Load(contentStream, (object param0) => Streams.CreateTemporaryStorageStream()); publishLicense = drmEmailMessageContainer.PublishLicense; } catch (InvalidRpmsgFormatException arg) { LicensingProcessor.Tracer.TraceError <object, InvalidRpmsgFormatException>(0L, "{0}: LicensingProcessor:Failed to load RPMSG. {1}", TraceContext.Get(), arg); return; } } } } UseLicenseAndUsageRights useLicenseAndUsageRights; try { useLicenseAndUsageRights = RmsClientManager.AcquireUseLicenseAndUsageRights(new RmsClientManagerContext(userPrincipal.MailboxInfo.OrganizationId, RmsClientManagerContext.ContextId.MessageId, item.InternetMessageId, publishLicense), publishLicense, userPrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), userPrincipal.Sid, userPrincipal.RecipientTypeDetails); } catch (RightsManagementException ex) { LicensingProcessor.Tracer.TraceError <object, RightsManagementException>(0L, "{0}: LicensingProcessor:Failed to license message. {1}", TraceContext.Get(), ex); if (!ex.IsPermanent) { throw new StorageTransientException(Strings.FailedToAcquireUseLicense, ex); } return; } catch (ExchangeConfigurationException ex2) { LicensingProcessor.Tracer.TraceError <object, ExchangeConfigurationException>(0L, "{0}: LicensingProcessor:Failed to license message. {1}", TraceContext.Get(), ex2); throw new StorageTransientException(Strings.FailedToReadIRMConfig, ex2); } LicensingProcessor.Tracer.TraceDebug(0L, "{0}: LicensingProcesssor: Saving licenses", new object[] { TraceContext.Get() }); item.OpenAsReadWrite(); item[MessageItemSchema.DRMRights] = useLicenseAndUsageRights.UsageRights; item[MessageItemSchema.DRMExpiryTime] = useLicenseAndUsageRights.ExpiryTime; if (!DrmClientUtils.IsCachingOfLicenseDisabled(useLicenseAndUsageRights.UseLicense)) { using (Stream stream = item.OpenPropertyStream(MessageItemSchema.DRMServerLicenseCompressed, PropertyOpenMode.Create)) { DrmEmailCompression.CompressUseLicense(useLicenseAndUsageRights.UseLicense, stream); } } item[MessageItemSchema.DRMPropsSignature] = useLicenseAndUsageRights.DRMPropsSignature; item.Save(SaveMode.ResolveConflicts); LicensingProcessor.Tracer.TraceDebug(0L, "{0}: LicensingProcesssor: message was saved successfully", new object[] { TraceContext.Get() }); }