private static StoreObjectType?TryDetectRightsManagementStoreObjectType(ICorePropertyBag propertyBag, string itemClass, StoreObjectType detectedType)
 {
     if (detectedType != StoreObjectType.Message || !ObjectClass.IsRightsManagedContentClass(propertyBag.GetValueOrDefault <string>(CoreObjectSchema.ContentClass, null)))
     {
         return(null);
     }
     return(new StoreObjectType?(StoreObjectType.RightsManagedMessage));
 }
Exemple #2
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();
        }
        internal ReplyForwardCommon(Item originalItem, Item newItem, ReplyForwardConfiguration parameters, bool decodeSmime)
        {
            Util.ThrowOnNullArgument(parameters, "parameters");
            if (decodeSmime && ObjectClass.IsSmime(originalItem.ClassName))
            {
                if (parameters.ConversionOptionsForSmime == null || parameters.ConversionOptionsForSmime.IgnoreImceaDomain || parameters.ConversionOptionsForSmime.ImceaEncapsulationDomain == null)
                {
                    throw new InvalidOperationException("Cannot decode SMIME without valid ConversionOptionsForSmime");
                }
                this.originalItem = originalItem;
                MessageItem messageItem = originalItem as MessageItem;
                if (messageItem != null)
                {
                    Item item = messageItem.FetchSmimeContent(parameters.ConversionOptionsForSmime.ImceaEncapsulationDomain);
                    if (item != null)
                    {
                        this.originalItem = item;
                        this.originalItem[InternalSchema.NormalizedSubjectInternal] = messageItem.GetValueOrDefault <string>(InternalSchema.NormalizedSubjectInternal, string.Empty);
                        this.originalItem[InternalSchema.Sender] = messageItem.Sender;
                        this.originalItem[InternalSchema.From]   = messageItem.From;
                    }
                }
            }
            else
            {
                this.originalItem = originalItem;
            }
            this.newItem    = newItem;
            this.parameters = parameters;
            this.culture    = ReplyForwardUtils.CalculateReplyForwardCulture(parameters.Culture, newItem);
            if (this.culture == null)
            {
                throw new InvalidOperationException("Forward message culture is unknown");
            }
            this.FetchPropertiesFromOriginalItem();
            if (originalItem is MessageItem)
            {
                if (originalItem.MapiMessage != null)
                {
                    SetReadFlags readFlag = parameters.ShouldSuppressReadReceipt ? SetReadFlags.SuppressReceipt : SetReadFlags.None;
                    try
                    {
                        StoreSession session = originalItem.Session;
                        bool         flag    = false;
                        try
                        {
                            if (session != null)
                            {
                                session.BeginMapiCall();
                                session.BeginServerHealthCall();
                                flag = true;
                            }
                            if (StorageGlobals.MapiTestHookBeforeCall != null)
                            {
                                StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                            }
                            originalItem.MapiMessage.SetReadFlag(readFlag);
                        }
                        catch (MapiPermanentException ex)
                        {
                            throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSetReadFlags, ex, session, this, "{0}. MapiException = {1}.", new object[]
                            {
                                string.Format("ReplyForwardCommon::ctor.", new object[0]),
                                ex
                            });
                        }
                        catch (MapiRetryableException ex2)
                        {
                            throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSetReadFlags, ex2, session, this, "{0}. MapiException = {1}.", new object[]
                            {
                                string.Format("ReplyForwardCommon::ctor.", new object[0]),
                                ex2
                            });
                        }
                        finally
                        {
                            try
                            {
                                if (session != null)
                                {
                                    session.EndMapiCall();
                                    if (flag)
                                    {
                                        session.EndServerHealthCall();
                                    }
                                }
                            }
                            finally
                            {
                                if (StorageGlobals.MapiTestHookAfterCall != null)
                                {
                                    StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                                }
                            }
                        }
                    }
                    catch (StoragePermanentException)
                    {
                    }
                    catch (StorageTransientException)
                    {
                    }
                }
                (this.originalItem as MessageItem).IsRead = true;
            }
            else if (this.originalItem is CalendarItemOccurrence)
            {
                this.parentPropValues[ParentPropertyIndex.IsRecurring]               = true;
                this.parentPropValues[ParentPropertyIndex.AppointmentRecurring]      = false;
                this.parentPropValues[ParentPropertyIndex.RecurrenceType]            = 0;
                this.parentPropValues[ParentPropertyIndex.TimeZoneBlob]              = new PropertyError(InternalSchema.TimeZoneBlob, PropertyErrorCode.NotFound);
                this.parentPropValues[ParentPropertyIndex.AppointmentRecurrenceBlob] = new PropertyError(InternalSchema.AppointmentRecurrenceBlob, PropertyErrorCode.NotFound);
                this.parentPropValues[ParentPropertyIndex.IsException]               = true;
                if (string.IsNullOrEmpty(this.parentPropValues[ParentPropertyIndex.RecurrencePattern] as string))
                {
                    CalendarItemOccurrence calendarItemOccurrence = this.originalItem as CalendarItemOccurrence;
                    this.parentPropValues[ParentPropertyIndex.RecurrencePattern] = calendarItemOccurrence.OccurrencePropertyBag.MasterCalendarItem.GenerateWhen();
                }
            }
            string valueOrDefault = originalItem.GetValueOrDefault <string>(InternalSchema.ItemClass, string.Empty);

            this.originalItemSigned = (ObjectClass.IsOfClass(valueOrDefault, "IPM.Note.Secure.Sign") || ObjectClass.IsSmimeClearSigned(valueOrDefault));
            if (!this.originalItemSigned)
            {
                this.originalItemEncrypted = (ObjectClass.IsOfClass(valueOrDefault, "IPM.Note.Secure") || ObjectClass.IsSmime(valueOrDefault));
            }
            string valueOrDefault2 = originalItem.GetValueOrDefault <string>(InternalSchema.ContentClass, string.Empty);

            this.originalItemIrm = ObjectClass.IsRightsManagedContentClass(valueOrDefault2);
        }