// Token: 0x06000E4F RID: 3663 RVA: 0x00056108 File Offset: 0x00054308
        private void ApplyPolicyToFolder(SharingPolicy policy, FolderData folderData)
        {
            StoreObjectType objectType = ObjectClass.GetObjectType(folderData.Folder.ClassName);
            List <PermissionSecurityPrincipal> list = new List <PermissionSecurityPrincipal>();
            PermissionSet permissionSet             = folderData.Folder.GetPermissionSet();

            foreach (Permission permission in permissionSet)
            {
                if (permission.Principal.Type == PermissionSecurityPrincipal.SecurityPrincipalType.ExternalUserPrincipal)
                {
                    SharingPolicyAction sharingPolicyAction = (SharingPolicyAction)0;
                    if (policy != null)
                    {
                        sharingPolicyAction = (permission.Principal.ExternalUser.IsReachUser ? policy.GetAllowedForAnonymousCalendarSharing() : policy.GetAllowed(permission.Principal.ExternalUser.SmtpAddress.Domain));
                    }
                    MemberRights memberRights = MemberRights.None;
                    if (sharingPolicyAction != (SharingPolicyAction)0)
                    {
                        memberRights = PolicyAllowedMemberRights.GetAllowed(sharingPolicyAction, objectType);
                    }
                    if (memberRights == MemberRights.None)
                    {
                        list.Add(permission.Principal);
                    }
                    else
                    {
                        MemberRights memberRights2 = ~memberRights & permission.MemberRights;
                        if (memberRights2 != MemberRights.None)
                        {
                            if (objectType == StoreObjectType.CalendarFolder)
                            {
                                if ((permission.MemberRights & MemberRights.ReadAny) != MemberRights.None)
                                {
                                    permission.MemberRights |= MemberRights.FreeBusyDetailed;
                                }
                                if ((permission.MemberRights & MemberRights.FreeBusyDetailed) != MemberRights.None)
                                {
                                    permission.MemberRights |= MemberRights.FreeBusySimple;
                                }
                            }
                            permission.MemberRights = (memberRights & permission.MemberRights);
                            folderData.IsChanged    = true;
                        }
                    }
                }
            }
            if (list.Count > 0)
            {
                foreach (PermissionSecurityPrincipal securityPrincipal in list)
                {
                    permissionSet.RemoveEntry(securityPrincipal);
                }
                folderData.IsChanged = true;
            }
        }
        // Token: 0x06000E51 RID: 3665 RVA: 0x00056330 File Offset: 0x00054530
        private void ApplyPolicyToFolder(int maxAllowedDetailLevel, FolderData folderData)
        {
            SharingPolicyAssistant.Tracer.TraceDebug <IExchangePrincipal, StoreId, int>((long)this.GetHashCode(), "{0}: Apply policy to a published folder {1}. MaxAllowedDetailLevel = {2}", folderData.MailboxSession.MailboxOwner, folderData.Id, maxAllowedDetailLevel);
            UserConfiguration publishingConfiguration = this.GetPublishingConfiguration(folderData.MailboxSession, folderData.Id);

            if (publishingConfiguration == null)
            {
                return;
            }
            using (publishingConfiguration)
            {
                IDictionary dictionary = null;
                Exception   ex         = null;
                try
                {
                    dictionary = publishingConfiguration.GetDictionary();
                }
                catch (CorruptDataException ex2)
                {
                    ex = ex2;
                }
                catch (InvalidOperationException ex3)
                {
                    ex = ex3;
                }
                if (ex != null)
                {
                    SharingPolicyAssistant.Tracer.TraceError <IExchangePrincipal, Exception>((long)this.GetHashCode(), "{0}: Data of user configuration is invalid or corrupt. Exception = {1}", folderData.MailboxSession.MailboxOwner, ex);
                }
                else if (maxAllowedDetailLevel == 0)
                {
                    if ((bool)dictionary[MailboxCalendarFolderSchema.PublishEnabled.Name])
                    {
                        SharingPolicyAssistant.Tracer.TraceDebug <IExchangePrincipal>((long)this.GetHashCode(), "{0}: Anonymous sharing is not allowed at all. Trying to disable.", folderData.MailboxSession.MailboxOwner);
                        dictionary[MailboxCalendarFolderSchema.PublishEnabled.Name]       = false;
                        dictionary[MailboxCalendarFolderSchema.PublishedCalendarUrl.Name] = null;
                        dictionary[MailboxCalendarFolderSchema.PublishedICalUrl.Name]     = null;
                        publishingConfiguration.Save();
                        ExtendedFolderFlags?valueAsNullable = folderData.Folder.GetValueAsNullable <ExtendedFolderFlags>(FolderSchema.ExtendedFolderFlags);
                        if (valueAsNullable != null)
                        {
                            ExtendedFolderFlags extendedFolderFlags = valueAsNullable.Value & (ExtendedFolderFlags)2147483647;
                            if (valueAsNullable.Value != extendedFolderFlags)
                            {
                                folderData.Folder[FolderSchema.ExtendedFolderFlags] = extendedFolderFlags;
                                folderData.IsChanged = true;
                            }
                        }
                    }
                }
                else
                {
                    object obj = dictionary[MailboxCalendarFolderSchema.DetailLevel.Name];
                    if (obj != null && (int)obj > maxAllowedDetailLevel)
                    {
                        SharingPolicyAssistant.Tracer.TraceDebug <IExchangePrincipal>((long)this.GetHashCode(), "{0}: Anonymous sharing is not allowed with current detail level. Trying to reduce.", folderData.MailboxSession.MailboxOwner);
                        dictionary[MailboxCalendarFolderSchema.DetailLevel.Name] = maxAllowedDetailLevel;
                        publishingConfiguration.Save();
                    }
                }
            }
        }
        // Token: 0x06000E50 RID: 3664 RVA: 0x000562A4 File Offset: 0x000544A4
        private void ApplyPolicyForAnonymousSharing(object[] row, MailboxData mailboxData, FolderData folderData)
        {
            object obj = row[3];

            if (obj == null || obj is PropertyError)
            {
                SharingPolicyAssistant.Tracer.TraceDebug <IExchangePrincipal, StoreId, object>((long)this.GetHashCode(), "{0}: Got null ExtendedFolderFlags property from folder query for folder {1}: {2}", mailboxData.MailboxSession.MailboxOwner, folderData.Id, obj ?? "<null>");
                return;
            }
            if (((ExtendedFolderFlags)obj & ExtendedFolderFlags.ExchangePublishedCalendar) != (ExtendedFolderFlags)0)
            {
                SharingPolicyAssistant.Tracer.TraceDebug <IExchangePrincipal, object>((long)this.GetHashCode(), "{0}: This is a published folder, need to apply policy to folder. ExtendedFolderFlags = {1}", mailboxData.MailboxSession.MailboxOwner, obj);
                this.ApplyPolicyToFolder(mailboxData.MaxAnonymousDetailLevel, folderData);
            }
        }
        // Token: 0x06000E4D RID: 3661 RVA: 0x00055FE4 File Offset: 0x000541E4
        private void ApplyPolicyForExternalSharing(object[] row, MailboxData mailboxData, FolderData folderData)
        {
            RawSecurityDescriptor rawSecurityDescriptor = row[2] as RawSecurityDescriptor;

            if (rawSecurityDescriptor == null)
            {
                SharingPolicyAssistant.Tracer.TraceDebug <IExchangePrincipal, StoreId>((long)this.GetHashCode(), "{0}: Got null security descriptor property from folder query for folder {1}", mailboxData.MailboxSession.MailboxOwner, folderData.Id);
                this.ApplyPolicyToFolder(mailboxData.SharingPolicy, folderData);
                return;
            }
            SharingPolicyAssistant.Tracer.TraceDebug <IExchangePrincipal, StoreId, RawSecurityDescriptor>((long)this.GetHashCode(), "{0}: Security descriptor retrieved from folder {1}: {2}", mailboxData.MailboxSession.MailboxOwner, folderData.Id, rawSecurityDescriptor);
            if (SharingPolicyAssistant.HasExternalUser(mailboxData.ExternalUserCollection, rawSecurityDescriptor))
            {
                SharingPolicyAssistant.Tracer.TraceDebug <IExchangePrincipal>((long)this.GetHashCode(), "{0}: Security descriptor contains external users, need to apply policy to folder", mailboxData.MailboxSession.MailboxOwner);
                this.ApplyPolicyToFolder(mailboxData.SharingPolicy, folderData);
            }
        }