public static RightsManagedMessageItem CreateFromInMemory(MessageItem item, MailboxSession session, StoreId destFolderId, OutboundConversionOptions options) { Util.ThrowOnNullArgument(item, "item"); Util.ThrowOnNullArgument(session, "session"); Util.ThrowOnNullArgument(destFolderId, "destFolderId"); Util.ThrowOnNullArgument(options, "options"); RightsManagedMessageItem.CheckSession(session); if (item.Session != null) { throw new InvalidOperationException("Item should be in-memory, not backed by store."); } RightsManagedMessageItem result; using (DisposeGuard disposeGuard = default(DisposeGuard)) { RightsManagedMessageItem rightsManagedMessageItem = RightsManagedMessageItem.Create(session, destFolderId, options); disposeGuard.Add <RightsManagedMessageItem>(rightsManagedMessageItem); RightsManagedMessageItem.CopyProtectableData(item, rightsManagedMessageItem.decodedItem); foreach (NativeStorePropertyDefinition nativeStorePropertyDefinition in item.AllNativeProperties) { if (!Body.BodyPropSet.Contains(nativeStorePropertyDefinition) && nativeStorePropertyDefinition != StoreObjectSchema.ContentClass) { object obj = item.TryGetProperty(nativeStorePropertyDefinition); if (!(obj is PropertyError)) { rightsManagedMessageItem[nativeStorePropertyDefinition] = obj; } else if (PropertyError.IsPropertyValueTooBig(obj)) { using (Stream stream = item.OpenPropertyStream(nativeStorePropertyDefinition, PropertyOpenMode.ReadOnly)) { using (Stream stream2 = rightsManagedMessageItem.OpenPropertyStream(nativeStorePropertyDefinition, PropertyOpenMode.Create)) { Util.StreamHandler.CopyStreamData(stream, stream2); } } } } } rightsManagedMessageItem.Recipients.CopyRecipientsFrom(item.Recipients); rightsManagedMessageItem.SaveFlags |= (PropertyBagSaveFlags.IgnoreMapiComputedErrors | PropertyBagSaveFlags.IgnoreUnresolvedHeaders); disposeGuard.Success(); result = rightsManagedMessageItem; } return(result); }
public static RightsManagedMessageItem Create(MessageItem item, OutboundConversionOptions options) { Util.ThrowOnNullArgument(item, "item"); Util.ThrowOnNullArgument(options, "options"); RightsManagedMessageItem.CheckSession(item.Session); RightsManagedMessageItem result; using (DisposeGuard disposeGuard = default(DisposeGuard)) { RightsManagedMessageItem rightsManagedMessageItem = new RightsManagedMessageItem(new CoreItemWrapper(item.CoreItem)); disposeGuard.Add <RightsManagedMessageItem>(rightsManagedMessageItem); rightsManagedMessageItem.InitNewItem(options); RightsManagedMessageItem.CopyProtectableData(item, rightsManagedMessageItem.decodedItem); rightsManagedMessageItem.SetDefaultEnvelopeBody(null); disposeGuard.Success(); rightsManagedMessageItem.originalItem = item; result = rightsManagedMessageItem; } return(result); }
private static void CopyProtectableData(MessageItem sourceItem, MessageItem targetItem) { RightsManagedMessageItem rightsManagedMessageItem = targetItem as RightsManagedMessageItem; if (rightsManagedMessageItem != null) { if (!rightsManagedMessageItem.isFullCharsetDetectionEnabled) { throw new InvalidOperationException(); } rightsManagedMessageItem.isFullCharsetDetectionEnabled = false; } try { RightsManagedMessageItem.CopyProtectableData(sourceItem.Body, sourceItem.AttachmentCollection, targetItem); } finally { if (rightsManagedMessageItem != null) { rightsManagedMessageItem.isFullCharsetDetectionEnabled = true; } } }
private static void CopyProtectableData(RightsManagedMessageItem sourceItem, MessageItem targetItem) { RightsManagedMessageItem.CopyProtectableData(sourceItem.Body, sourceItem.AttachmentCollection, targetItem); }
protected override void OnBeforeSave() { if (this.decodedItem == null && !base.AttachmentCollection.IsDirty && base.IsRestricted && (base.Recipients.IsDirty || base.IsPropertyDirty(ItemSchema.Sender))) { this.EnsureIsDecoded(); } if (this.decodedItem != null) { string contentClass = base.TryGetProperty(InternalSchema.ContentClass) as string; if (this.rmsTemplate == null) { this.UnprotectAllAttachments(); RightsManagedMessageItem.CopyProtectableData(this.decodedItem, this); if (ObjectClass.IsRightsManagedContentClass(contentClass)) { base.Delete(StoreObjectSchema.ContentClass); } } else { this.charsetDetectionStringForProtectedData = new StringBuilder((int)Math.Min(this.ProtectedBody.Size, 2147483647L)); this.GetCharsetDetectionStringFromProtectedData(this.charsetDetectionStringForProtectedData); if (!ObjectClass.IsRightsManagedContentClass(contentClass)) { this[StoreObjectSchema.ContentClass] = "rpmsg.message"; } if (this.isSending) { byte[][] valueOrDefault = base.GetValueOrDefault <byte[][]>(InternalSchema.DRMLicense); if (valueOrDefault != null && valueOrDefault.Length == RightsManagedMessageItem.EmptyDrmLicense.Length && valueOrDefault[0].Length == RightsManagedMessageItem.EmptyDrmLicense[0].Length) { base.DeleteProperties(new PropertyDefinition[] { InternalSchema.DRMLicense }); } } else if (base.IsDraft && base.GetValueOrDefault <byte[][]>(InternalSchema.DRMLicense) == null) { this[InternalSchema.DRMLicense] = RightsManagedMessageItem.EmptyDrmLicense; } base.AttachmentCollection.RemoveAll(); using (StreamAttachment streamAttachment = base.AttachmentCollection.Create(AttachmentType.Stream) as StreamAttachment) { streamAttachment.FileName = "message.rpmsg"; streamAttachment.ContentType = "application/x-microsoft-rpmsg-message"; using (Stream stream = new PooledMemoryStream(131072)) { if (this.serverUseLicense == null || ((this.UsageRights & ContentRight.Owner) == ContentRight.Owner && this.rmsTemplate.RequiresRepublishingWhenRecipientsChange && this.CanRepublish && (base.Recipients.IsDirty || (base.IsPropertyDirty(ItemSchema.Sender) && this.conversationOwner == null)))) { if (this.ConversationOwner == null) { throw new InvalidOperationException("Conversation owner must be set before protecting the message."); } this.UnprotectAllAttachments(); using (MsgToRpMsgConverter msgToRpMsgConverter = new MsgToRpMsgConverter(this, this.ConversationOwner, this.orgId, this.rmsTemplate, this.options)) { msgToRpMsgConverter.Convert(this.decodedItem, stream); using (Stream stream2 = base.OpenPropertyStream(MessageItemSchema.DRMServerLicenseCompressed, PropertyOpenMode.Create)) { DrmEmailCompression.CompressUseLicense(msgToRpMsgConverter.ServerUseLicense, stream2); } if (this.InternalSession != null && this.InternalSession.MailboxOwner.Sid != null) { ExDateTime useLicenseExpiryTime = RmsClientManagerUtils.GetUseLicenseExpiryTime(msgToRpMsgConverter.ServerUseLicense, this.UsageRights); this[MessageItemSchema.DRMRights] = (int)this.UsageRights; this[MessageItemSchema.DRMExpiryTime] = useLicenseExpiryTime; using (RightsSignatureBuilder rightsSignatureBuilder = new RightsSignatureBuilder(msgToRpMsgConverter.ServerUseLicense, msgToRpMsgConverter.PublishLicense, RmsClientManager.EnvironmentHandle, msgToRpMsgConverter.LicensePair)) { this[MessageItemSchema.DRMPropsSignature] = rightsSignatureBuilder.Sign(this.UsageRights, useLicenseExpiryTime, this.InternalSession.MailboxOwner.Sid); } } goto IL_362; } } using (MsgToRpMsgConverter msgToRpMsgConverter2 = new MsgToRpMsgConverter(this, this.orgId, this.publishLicense, this.serverUseLicense, this.options)) { msgToRpMsgConverter2.Convert(this.decodedItem, stream); } IL_362: using (Stream contentStream = streamAttachment.GetContentStream(PropertyOpenMode.Create)) { stream.Seek(0L, SeekOrigin.Begin); Util.StreamHandler.CopyStreamData(stream, contentStream); } } bool flag = false; foreach (AttachmentHandle handle in this.decodedItem.AttachmentCollection) { if (!CoreAttachmentCollection.IsInlineAttachment(handle)) { flag = true; break; } } this[InternalSchema.AllAttachmentsHidden] = !flag; streamAttachment.Save(); } } this.decodedItem.Dispose(); this.decodedItem = null; this.effectiveRights = ContentRight.Owner; this.publishLicense = null; this.restrictionInfo = null; this.rmsTemplate = null; this.serverUseLicense = null; this.conversationOwner = null; } base.OnBeforeSave(); }
public void SetProtectedData(Body body, AttachmentCollection attachments) { this.CheckDisposed("SetProtectedData"); this.EnsureIsDecoded(); RightsManagedMessageItem.CopyProtectableData(body, attachments, this.decodedItem); }