protected override void BuildAttachments(BodyConversionCallbacks callbacks, InboundConversionOptions optionsForSmime)
        {
            RightsManagedMessageItem rightsManagedMessageItem  = this.originalItem as RightsManagedMessageItem;
            RightsManagedMessageItem rightsManagedMessageItem2 = this.newItem as RightsManagedMessageItem;

            base.CopyAttachments(callbacks, rightsManagedMessageItem.ProtectedAttachmentCollection, rightsManagedMessageItem2.ProtectedAttachmentCollection, false, this.parameters.TargetFormat == BodyFormat.TextPlain, optionsForSmime);
        }
        protected override void BuildBody(BodyConversionCallbacks callbacks)
        {
            RightsManagedMessageItem rightsManagedMessageItem  = this.originalItem as RightsManagedMessageItem;
            RightsManagedMessageItem rightsManagedMessageItem2 = this.newItem as RightsManagedMessageItem;

            ReplyForwardCommon.CopyBodyWithPrefix(rightsManagedMessageItem.ProtectedBody, rightsManagedMessageItem2.ProtectedBody, this.parameters, callbacks);
        }
示例#3
0
        public static RightsManagedMessageItem ReBind(MessageItem item, OutboundConversionOptions options, bool acquireLicense)
        {
            Util.ThrowOnNullArgument(item, "item");
            Util.ThrowOnNullArgument(options, "options");
            StoreSession storeSession = item.Session ?? ((item.CoreItem.TopLevelItem != null) ? item.CoreItem.TopLevelItem.Session : null);

            if (storeSession == null)
            {
                throw new ArgumentException("Cannot use ReBind() for in-memory message.", "item");
            }
            RightsManagedMessageItem.CheckSession(storeSession);
            if (!item.IsRestricted)
            {
                throw new ArgumentException("Only protected messages can be used for ReBind()");
            }
            RightsManagedMessageItem result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                RightsManagedMessageItem rightsManagedMessageItem = new RightsManagedMessageItem(new CoreItemWrapper(item.CoreItem));
                disposeGuard.Add <RightsManagedMessageItem>(rightsManagedMessageItem);
                rightsManagedMessageItem.Decode(options, acquireLicense);
                disposeGuard.Success();
                rightsManagedMessageItem.originalItem = item;
                result = rightsManagedMessageItem;
            }
            return(result);
        }
示例#4
0
 private void CopyLicenseDataFrom(RightsManagedMessageItem source)
 {
     this.rmsTemplate            = source.rmsTemplate;
     this.conversationOwner      = source.conversationOwner;
     this.publishLicense         = source.publishLicense;
     this.serverUseLicense       = source.serverUseLicense;
     this.restrictionInfo        = source.restrictionInfo;
     this.publishedByExternalRMS = source.publishedByExternalRMS;
     this.UpdateEffectiveRights();
 }
示例#5
0
 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);
 }
示例#6
0
        public static RightsManagedMessageItem CreateInMemory(OutboundConversionOptions options)
        {
            Util.ThrowOnNullArgument(options, "options");
            RightsManagedMessageItem rightsManagedMessageItem = null;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                rightsManagedMessageItem = ItemBuilder.ConstructItem <RightsManagedMessageItem>(null, null, null, StoreObjectSchema.ContentConversionProperties, () => new InMemoryPersistablePropertyBag(StoreObjectSchema.ContentConversionProperties), ItemCreateInfo.RightsManagedMessageItemInfo.Creator, Origin.Existing, ItemLevel.TopLevel);
                disposeGuard.Add <RightsManagedMessageItem>(rightsManagedMessageItem);
                rightsManagedMessageItem[InternalSchema.ItemClass] = "IPM.Note";
                rightsManagedMessageItem.InitNewItem(options);
                rightsManagedMessageItem.SetDefaultEnvelopeBody(null);
                disposeGuard.Success();
            }
            return(rightsManagedMessageItem);
        }
示例#7
0
        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);
        }
示例#8
0
        public static RightsManagedMessageItem Bind(MailboxSession session, StoreId messageId, OutboundConversionOptions options, bool acquireLicense, ICollection <PropertyDefinition> propsToReturn)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(messageId, "messageId");
            Util.ThrowOnNullArgument(options, "options");
            RightsManagedMessageItem.CheckSession(session);
            RightsManagedMessageItem rightsManagedMessageItem = null;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                rightsManagedMessageItem = ItemBuilder.ItemBind <RightsManagedMessageItem>(session, messageId, RightsManagedMessageItemSchema.Instance, propsToReturn);
                disposeGuard.Add <RightsManagedMessageItem>(rightsManagedMessageItem);
                rightsManagedMessageItem.Decode(options, acquireLicense);
                disposeGuard.Success();
            }
            return(rightsManagedMessageItem);
        }
示例#9
0
        public static RightsManagedMessageItem Create(MailboxSession session, StoreId destFolderId, OutboundConversionOptions options)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(destFolderId, "destFolderId");
            Util.ThrowOnNullArgument(options, "options");
            RightsManagedMessageItem.CheckSession(session);
            RightsManagedMessageItem rightsManagedMessageItem = null;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                rightsManagedMessageItem = ItemBuilder.CreateNewItem <RightsManagedMessageItem>(session, destFolderId, ItemCreateInfo.RightsManagedMessageItemInfo, CreateMessageType.Normal);
                disposeGuard.Add <RightsManagedMessageItem>(rightsManagedMessageItem);
                rightsManagedMessageItem[InternalSchema.ItemClass] = "IPM.Note";
                rightsManagedMessageItem.InitNewItem(options);
                rightsManagedMessageItem.SetDefaultEnvelopeBody(null);
                disposeGuard.Success();
            }
            return(rightsManagedMessageItem);
        }
示例#10
0
        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);
        }
示例#11
0
        private RightsManagedMessageItem CreateReplyForwardInternal(MailboxSession session, StoreId parentFolderId, ReplyForwardConfiguration configuration, RightsManagedMessageItem.ReplyForwardCreationCall call)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(parentFolderId, "parentFolderId");
            Util.ThrowOnNullArgument(configuration, "configuration");
            if ((configuration.ForwardCreationFlags & (ForwardCreationFlags.PreserveSender | ForwardCreationFlags.TreatAsMeetingMessage)) != ForwardCreationFlags.None)
            {
                throw new InvalidOperationException("Invalid forward creation flags used.");
            }
            RightsManagedMessageItem result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                RightsManagedMessageItem rightsManagedMessageItem = RightsManagedMessageItem.Create(session, parentFolderId, this.options);
                disposeGuard.Add <RightsManagedMessageItem>(rightsManagedMessageItem);
                call(this, rightsManagedMessageItem, configuration);
                rightsManagedMessageItem.CopyLicenseDataFrom(this);
                disposeGuard.Success();
                result = rightsManagedMessageItem;
            }
            return(result);
        }
示例#12
0
        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;
                }
            }
        }
示例#13
0
 private static void CopyProtectableData(RightsManagedMessageItem sourceItem, MessageItem targetItem)
 {
     RightsManagedMessageItem.CopyProtectableData(sourceItem.Body, sourceItem.AttachmentCollection, targetItem);
 }
示例#14
0
        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();
        }
示例#15
0
 public void SetProtectedData(Body body, AttachmentCollection attachments)
 {
     this.CheckDisposed("SetProtectedData");
     this.EnsureIsDecoded();
     RightsManagedMessageItem.CopyProtectableData(body, attachments, this.decodedItem);
 }
        protected override BodyConversionCallbacks GetCallbacks()
        {
            RightsManagedMessageItem rightsManagedMessageItem = this.originalItem as RightsManagedMessageItem;

            return(base.GetCallbacksInternal(rightsManagedMessageItem.ProtectedBody, rightsManagedMessageItem.ProtectedAttachmentCollection));
        }
 internal RightsManagedForwardCreation(RightsManagedMessageItem originalItem, RightsManagedMessageItem message, ReplyForwardConfiguration parameters) : base(originalItem, message, parameters)
 {
 }
示例#18
0
 public static RightsManagedMessageItem Bind(MailboxSession session, StoreId messageId, OutboundConversionOptions options, ICollection <PropertyDefinition> propsToReturn)
 {
     return(RightsManagedMessageItem.Bind(session, messageId, options, true, propsToReturn));
 }
示例#19
0
 public static RightsManagedMessageItem Bind(MailboxSession session, StoreId messageId, OutboundConversionOptions options, bool acquireLicense)
 {
     return(RightsManagedMessageItem.Bind(session, messageId, options, acquireLicense, new PropertyDefinition[0]));
 }
 internal RightsManagedReplyCreation(RightsManagedMessageItem originalItem, RightsManagedMessageItem message, ReplyForwardConfiguration parameters, bool isReplyAll) : base(originalItem, message, parameters, isReplyAll, false, true)
 {
 }