internal static void EnabledPrimarySMTPAddressTemplateSetter(object value, IPropertyBag propertyBag)
        {
            ProxyAddressTemplateCollection proxyAddressTemplateCollection = (ProxyAddressTemplateCollection)propertyBag[EmailAddressPolicySchema.RawEnabledEmailAddressTemplates];
            ProxyAddressTemplate           proxyAddressTemplate           = null;

            try
            {
                proxyAddressTemplate = ProxyAddressTemplate.Parse((string)value);
            }
            catch (ArgumentException ex)
            {
                throw new DataValidationException(new PropertyValidationError(new LocalizedString(ex.Message), EmailAddressPolicySchema.EnabledPrimarySMTPAddressTemplate, null), ex);
            }
            if (!(proxyAddressTemplate is SmtpProxyAddressTemplate))
            {
                throw new DataValidationException(new PropertyValidationError(DirectoryStrings.ErrorPrimarySmtpTemplateInvalid((string)value), EmailAddressPolicySchema.EnabledPrimarySMTPAddressTemplate, value), null);
            }
            ProxyAddressTemplate proxyAddressTemplate2 = proxyAddressTemplateCollection.FindPrimary(ProxyAddressPrefix.Smtp);

            if (proxyAddressTemplate2 != null && !StringComparer.CurrentCultureIgnoreCase.Equals(proxyAddressTemplate.AddressTemplateString, proxyAddressTemplate2.AddressTemplateString))
            {
                proxyAddressTemplateCollection.Remove(proxyAddressTemplate2);
            }
            proxyAddressTemplateCollection.MakePrimary(proxyAddressTemplate);
        }
示例#2
0
            protected override void HandleNonAuthoritativeDomains(EmailAddressPolicy policy, HashSet <SmtpDomain> domains)
            {
                ProxyAddressTemplateCollection proxyAddressTemplateCollection = new ProxyAddressTemplateCollection();

                foreach (ProxyAddressTemplate proxyAddressTemplate in policy.NonAuthoritativeDomains)
                {
                    SmtpDomain smtpDomain;
                    if (!UpdateEmailAddressPolicy.DomainValidator.TryGetDomain(proxyAddressTemplate, out smtpDomain))
                    {
                        proxyAddressTemplateCollection.Add(proxyAddressTemplate);
                    }
                }
                bool flag = false;

                foreach (SmtpDomain smtpDomain2 in domains)
                {
                    SmtpProxyAddressTemplate item = new SmtpProxyAddressTemplate("@" + smtpDomain2.Domain, false);
                    proxyAddressTemplateCollection.Add(item);
                    if (!flag && !policy.NonAuthoritativeDomains.Contains(item))
                    {
                        flag = true;
                    }
                }
                if (!flag)
                {
                    flag = (proxyAddressTemplateCollection.Count != policy.NonAuthoritativeDomains.Count);
                }
                if (flag)
                {
                    UpdateEmailAddressPolicy.CheckEapVersion(policy);
                    policy.NonAuthoritativeDomains = proxyAddressTemplateCollection;
                }
            }
 public AddressTemplateList(ProxyAddressTemplateCollection templateCollection) : base(templateCollection.Count)
 {
     foreach (ProxyAddressBase address in templateCollection)
     {
         base.Add(new EmailAddressItem(address));
     }
 }
        protected override void ValidateWrite(List <ValidationError> errors)
        {
            base.ValidateWrite(errors);
            ProxyAddressTemplateCollection proxyAddressTemplateCollection = (ProxyAddressTemplateCollection)this[EmailAddressPolicySchema.RawEnabledEmailAddressTemplates];
            ProxyAddressTemplateCollection disabledEmailAddressTemplates  = this.DisabledEmailAddressTemplates;
            List <ProxyAddressTemplate>    list = new List <ProxyAddressTemplate>();

            list.AddRange(proxyAddressTemplateCollection);
            list.AddRange(disabledEmailAddressTemplates);
            if (list.Count > 0)
            {
                if (proxyAddressTemplateCollection != null && disabledEmailAddressTemplates != null)
                {
                    foreach (ProxyAddressTemplate proxyAddressTemplate in proxyAddressTemplateCollection)
                    {
                        if (disabledEmailAddressTemplates.Contains(proxyAddressTemplate))
                        {
                            errors.Add(new ObjectValidationError(DirectoryStrings.EapDuplicatedEmailAddressTemplate(proxyAddressTemplate.ToString()), base.Id, string.Empty));
                        }
                    }
                }
                Dictionary <ProxyAddressPrefix, int> dictionary = new Dictionary <ProxyAddressPrefix, int>();
                foreach (ProxyAddressTemplate proxyAddressTemplate2 in list)
                {
                    if (!dictionary.ContainsKey(proxyAddressTemplate2.Prefix))
                    {
                        dictionary[proxyAddressTemplate2.Prefix] = 0;
                    }
                    if (proxyAddressTemplate2.IsPrimaryAddress)
                    {
                        Dictionary <ProxyAddressPrefix, int> dictionary2;
                        ProxyAddressPrefix prefix;
                        (dictionary2 = dictionary)[prefix = proxyAddressTemplate2.Prefix] = dictionary2[prefix] + 1;
                    }
                }
                foreach (ProxyAddressPrefix proxyAddressPrefix in dictionary.Keys)
                {
                    if ((!(proxyAddressPrefix == ProxyAddressPrefix.Smtp) || dictionary[proxyAddressPrefix] != 0) && dictionary[proxyAddressPrefix] != 1)
                    {
                        errors.Add(new ObjectValidationError(DirectoryStrings.EapMustHaveOnePrimaryAddressTemplate(proxyAddressPrefix.ToString()), base.Id, string.Empty));
                    }
                }
            }
            ValidationError validationError = RecipientFilterHelper.ValidatePrecannedRecipientFilter(this.propertyBag, EmailAddressPolicySchema.RecipientFilterMetadata, EmailAddressPolicySchema.RecipientFilter, EmailAddressPolicySchema.IncludedRecipients, this.Identity);

            if (validationError != null)
            {
                errors.Add(validationError);
            }
            if (this.Priority == 0 && (base.IsChanged(EmailAddressPolicySchema.Priority) || base.ObjectState == ObjectState.New))
            {
                errors.Add(new PropertyValidationError(DirectoryStrings.CannotSetZeroAsEapPriority, EmailAddressPolicySchema.Priority, string.Empty));
            }
            if (string.IsNullOrEmpty(this.RecipientFilter) && (base.IsModified(EmailAddressPolicySchema.RecipientFilter) || base.ObjectState == ObjectState.New))
            {
                errors.Add(new PropertyValidationError(DirectoryStrings.ErrorInvalidOpathFilter(this.RecipientFilter ?? string.Empty), EmailAddressPolicySchema.RecipientFilter, string.Empty));
            }
        }
示例#5
0
        private void AddTenantRoutingAddressToPolicy(EmailAddressPolicy policy)
        {
            List <ProxyAddressTemplate> list = new List <ProxyAddressTemplate>(policy.EnabledEmailAddressTemplates);
            SmtpProxyAddressTemplate    item = new SmtpProxyAddressTemplate("%m@" + this.tenantRoutingDomain, false);

            list.Add(item);
            ProxyAddressTemplateCollection enabledEmailAddressTemplates = new ProxyAddressTemplateCollection(list.ToArray());

            base.OnPremisesSession.SetEmailAddressPolicy(policy.DistinguishedName, null, enabledEmailAddressTemplates);
        }
        internal static object EnabledPrimarySMTPAddressTemplateGetter(IPropertyBag propertyBag)
        {
            ProxyAddressTemplateCollection proxyAddressTemplateCollection = (ProxyAddressTemplateCollection)propertyBag[EmailAddressPolicySchema.RawEnabledEmailAddressTemplates];
            ProxyAddressTemplate           proxyAddressTemplate           = proxyAddressTemplateCollection.FindPrimary(ProxyAddressPrefix.Smtp);

            if (!(null == proxyAddressTemplate))
            {
                return(proxyAddressTemplate.AddressTemplateString);
            }
            return(string.Empty);
        }
示例#7
0
            protected override void HandleNonAuthoritativeDomains(EmailAddressPolicy policy, HashSet <SmtpDomain> domains)
            {
                ProxyAddressTemplateCollection proxyAddressTemplateCollection = new ProxyAddressTemplateCollection();

                foreach (ProxyAddressTemplate proxyAddressTemplate in policy.NonAuthoritativeDomains)
                {
                    SmtpDomain template;
                    if (!UpdateEmailAddressPolicy.DomainValidator.TryGetDomain(proxyAddressTemplate, out template) || (!SetAcceptedDomain.DomainEditValidator.Conflict(this.newDomain, template) && !SetAcceptedDomain.DomainEditValidator.Conflict(this.oldDomain, template)))
                    {
                        proxyAddressTemplateCollection.Add(proxyAddressTemplate);
                    }
                }
                foreach (SmtpDomain smtpDomain in domains)
                {
                    if (SetAcceptedDomain.DomainEditValidator.Conflict(this.newDomain, smtpDomain) || SetAcceptedDomain.DomainEditValidator.Conflict(this.oldDomain, smtpDomain))
                    {
                        SmtpProxyAddressTemplate item = new SmtpProxyAddressTemplate("@" + smtpDomain.Domain, false);
                        proxyAddressTemplateCollection.Add(item);
                    }
                }
                UpdateEmailAddressPolicy.CheckEapVersion(policy);
                policy.NonAuthoritativeDomains = proxyAddressTemplateCollection;
                this.session.Save(policy);
            }
示例#8
0
        public void SetEmailAddressPolicy(string identity, string includedRecipients, ProxyAddressTemplateCollection enabledEmailAddressTemplates)
        {
            SessionParameters sessionParameters = new SessionParameters();

            sessionParameters.Set("Identity", identity);
            sessionParameters.Set("ForceUpgrade", true);
            if (!string.IsNullOrEmpty(includedRecipients))
            {
                sessionParameters.Set("IncludedRecipients", includedRecipients);
            }
            if (enabledEmailAddressTemplates != null)
            {
                sessionParameters.Set <ProxyAddressTemplate>("EnabledEmailAddressTemplates", enabledEmailAddressTemplates);
            }
            base.RemotePowershellSession.RunCommand("Set-EmailAddressPolicy", sessionParameters);
        }