// Token: 0x060012F6 RID: 4854 RVA: 0x0003E1EC File Offset: 0x0003C3EC
        internal static IEnumerable <SmtpDomainWithSubdomains> GetAcceptedDomains(OrganizationId organizationId, OrganizationId executingOrganizationId)
        {
            ProvisioningCache provisioningCache = ProvisioningCache.Instance;

            return(provisioningCache.TryAddAndGetOrganizationData <IEnumerable <SmtpDomainWithSubdomains> >(CannedProvisioningCacheKeys.OrganizationAcceptedDomains, organizationId, delegate()
            {
                ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(), organizationId, executingOrganizationId, false);
                IConfigurationSession cfgSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.PartiallyConsistent, sessionSettings, 245, "GetAcceptedDomains", "f:\\15.00.1497\\sources\\dev\\Configuration\\src\\ObjectModel\\rbac\\AuthZPluginHelper.cs");
                ADObjectId rootId = organizationId.ConfigurationUnit ?? provisioningCache.TryAddAndGetGlobalData <ADObjectId>(CannedProvisioningCacheKeys.FirstOrgContainerId, () => cfgSession.GetOrgContainerId());
                QueryFilter filter = new NotFilter(new BitMaskAndFilter(AcceptedDomainSchema.AcceptedDomainFlags, 1UL));
                ADPagedReader <AcceptedDomain> adpagedReader = cfgSession.FindPaged <AcceptedDomain>(rootId, QueryScope.SubTree, filter, null, 0);
                AcceptedDomain[] array = adpagedReader.ReadAllPages();
                SmtpDomainWithSubdomains[] array2 = new SmtpDomainWithSubdomains[array.Length];
                for (int i = 0; i < array2.Length; i++)
                {
                    array2[i] = array[i].DomainName;
                }
                return array2;
            }));
        }
        public static SiteMailboxAddressesTemplate GetSiteMailboxAddressesTemplate(IConfigurationSession cfgSession, ProvisioningCache provisioningCache)
        {
            if (cfgSession == null)
            {
                throw new ArgumentNullException("cfgSession");
            }
            if (provisioningCache == null)
            {
                throw new ArgumentNullException("provisioningCache");
            }
            OrganizationId orgId = cfgSession.GetOrgContainer().OrganizationId;

            return(provisioningCache.TryAddAndGetOrganizationData <SiteMailboxAddressesTemplate>(CannedProvisioningCacheKeys.OrganizationSiteMailboxAddressesTemplate, orgId, delegate()
            {
                ADObjectId rootId = orgId.ConfigurationUnit ?? provisioningCache.TryAddAndGetGlobalData <ADObjectId>(CannedProvisioningCacheKeys.FirstOrgContainerId, () => cfgSession.GetOrgContainerId());
                MultiValuedProperty <SmtpDomain> multiValuedProperty = null;
                ADPagedReader <OnPremisesOrganization> adpagedReader = cfgSession.FindPaged <OnPremisesOrganization>(rootId, QueryScope.SubTree, null, null, 0);
                using (IEnumerator <OnPremisesOrganization> enumerator = adpagedReader.GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        OnPremisesOrganization onPremisesOrganization = enumerator.Current;
                        multiValuedProperty = onPremisesOrganization.HybridDomains;
                    }
                }
                QueryFilter filter = new NotFilter(new BitMaskAndFilter(AcceptedDomainSchema.AcceptedDomainFlags, 1UL));
                ADPagedReader <AcceptedDomain> adpagedReader2 = cfgSession.FindPaged <AcceptedDomain>(rootId, QueryScope.SubTree, filter, new SortBy(ADObjectSchema.Name, SortOrder.Ascending), 0);
                bool flag = false;
                string text = string.Empty;
                string text2 = string.Empty;
                string text3 = string.Empty;
                foreach (AcceptedDomain acceptedDomain in adpagedReader2)
                {
                    if (acceptedDomain.AuthenticationType != AuthenticationType.Federated && (string.IsNullOrEmpty(text) || acceptedDomain.Default))
                    {
                        text = acceptedDomain.DomainName.Domain;
                    }
                    if ((multiValuedProperty == null || multiValuedProperty.Count == 0 || multiValuedProperty.Contains(acceptedDomain.DomainName.SmtpDomain)) && (string.IsNullOrEmpty(text2) || acceptedDomain.Default))
                    {
                        text2 = acceptedDomain.DomainName.Domain;
                    }
                    if (acceptedDomain.IsCoexistenceDomain && string.IsNullOrEmpty(text3))
                    {
                        text3 = acceptedDomain.DomainName.Domain;
                    }
                    flag = (flag || acceptedDomain.Default);
                    if (flag && !string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2) && !string.IsNullOrEmpty(text3))
                    {
                        break;
                    }
                }
                SiteMailboxAddressesTemplate siteMailboxAddressesTemplate = new SiteMailboxAddressesTemplate();
                siteMailboxAddressesTemplate.UserPrincipalNameDomain = text;
                if (!string.IsNullOrEmpty(text2))
                {
                    siteMailboxAddressesTemplate.AddressTemplates.Add(new SmtpProxyAddressTemplate(string.Format("@{0}", text2), true));
                    if (!string.IsNullOrEmpty(text3) && !string.Equals(text2, text3, StringComparison.OrdinalIgnoreCase))
                    {
                        siteMailboxAddressesTemplate.AddressTemplates.Add(new SmtpProxyAddressTemplate(string.Format("@{0}", text3), false));
                    }
                }
                if (!siteMailboxAddressesTemplate.IsValid)
                {
                    throw new ErrorSiteMailboxCannotLoadAddressTemplateException();
                }
                return siteMailboxAddressesTemplate;
            }));
        }