public bool Decode(OutboundConversionOptions options, bool acquireLicense) { this.CheckDisposed("Decode"); Util.ThrowOnNullArgument(options, "options"); this.decryptionStatus = RightsManagedMessageDecryptionStatus.Success; if (this.decodedItem != null) { return(true); } if (this.InternalSession == null) { this.decryptionStatus = RightsManagedMessageDecryptionStatus.NotSupported; throw new InvalidOperationException("Decoding of in-memory messages is not supported."); } RightsManagedMessageItem.CheckSession(this.InternalSession); this.SetConversionOptions(options); using (DisposeGuard disposeGuard = default(DisposeGuard)) { try { MessageItem messageItem = ItemConversion.OpenRestrictedContent(this, this.orgId, acquireLicense, out this.licenseAcquired, out this.useLicenseValue, out this.restrictionInfo); if (messageItem == null) { ExTraceGlobals.StorageTracer.TraceError(0L, "Failed to decode protected message - no user license is present."); throw new RightsManagementPermanentException(RightsManagementFailureCode.UnknownFailure, ServerStrings.GenericFailureRMDecryption); } disposeGuard.Add <MessageItem>(messageItem); this.UpdateEffectiveRights(); this.conversationOwner = new Participant(this.restrictionInfo.ConversationOwner, this.restrictionInfo.ConversationOwner, "SMTP"); this.CheckPermission(ContentRight.View); messageItem.CoreItem.TopLevelItem = (base.CoreItem.TopLevelItem ?? base.CoreItem); this.serverUseLicense = (messageItem.TryGetProperty(MessageItemSchema.DRMServerLicense) as string); this.publishLicense = (messageItem.TryGetProperty(MessageItemSchema.DrmPublishLicense) as string); this.rmsTemplate = RmsTemplate.CreateFromPublishLicense(this.publishLicense); MsgToRpMsgConverter.CallRM(delegate { this.publishedByExternalRMS = !RmsClientManager.IsPublishedByOrganizationRMS(this.orgId, this.publishLicense); }, ServerStrings.FailedToCheckPublishLicenseOwnership(this.orgId.ToString())); this.decodedItem = messageItem; disposeGuard.Success(); } catch (RightsManagementPermanentException exception) { this.decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception); throw; } catch (RightsManagementTransientException exception2) { this.decryptionStatus = RightsManagedMessageDecryptionStatus.CreateFromException(exception2); throw; } } return(true); }
internal MsgToRpMsgConverter(MessageItem envelopeMessage, OrganizationId orgId, string publishLicense, string serverUseLicense, OutboundConversionOptions options) { using (DisposeGuard disposeGuard = this.Guard()) { this.serverUseLicense = serverUseLicense; this.publishLicense = publishLicense; this.options = options; this.charset = ConvertUtils.GetItemMimeCharset(envelopeMessage.CoreItem.PropertyBag); this.messageId = envelopeMessage.InternetMessageId; this.orgId = RmsClientManagerUtils.OrgIdFromPublishingLicenseOrDefault(publishLicense, orgId); this.InitTenantLicenses(); MsgToRpMsgConverter.CallRM(delegate { DrmClientUtils.GetContentIdFromLicense(this.publishLicense, out this.contentId, out this.contentIdType); }, ServerStrings.FailedToParseUseLicense); disposeGuard.Success(); } }