public RpMsgToMsgConverter(DrmEmailMessageContainer drmMsgContainer, OrganizationId orgId, bool decryptAttachments) { Util.ThrowOnNullArgument(drmMsgContainer, "drmMsgContainer"); Util.ThrowOnNullArgument(orgId, "orgId"); this.drmMsgContainer = drmMsgContainer; this.orgId = orgId; this.decryptAttachments = decryptAttachments; }
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); }
// 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() }); }