Exemplo n.º 1
0
        /// <summary>
        /// Normalize email
        /// </summary>
        /// <param name="email"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static MailAddress Normalize(MailAddress email, NormalizerSettings settings = null)
        {
            settings = settings ?? DefaultSettings;

            var host = email.Host.ToLower();
            var user = email.User;

            if (settings.LowerCase)
            {
                user = user.ToLowerInvariant();
            }

            if (settings.NormalizeHost && normalizedDomains.TryGetValue(host, out var normalizedHost))
            {
                host = normalizedHost;
            }

            if (settings.RemoveDots && domainsWithDots.Contains(host))
            {
                user = user.Replace(".", string.Empty);
            }

            if (settings.RemoveTags && domainTags.TryGetValue(host, out var tag) && user.IndexOf(tag) != -1)
            {
                user = user.Substring(0, user.IndexOf(tag));
            }

            return(new MailAddress(user + "@" + host, email.DisplayName));
        }
Exemplo n.º 2
0
 static Normalizer()
 {
     domainTags        = GetDomainsWithTags();
     domainsWithDots   = GetDomainsWithDots();
     normalizedDomains = GetNormalizedDomains();
     DefaultSettings   = new NormalizerSettings();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Configure the default settings to use when normalizing
 /// </summary>
 /// <param name="settings"></param>
 public static void ConfigureDefaults(NormalizerSettings settings)
 {
     DefaultSettings = settings;
 }
 /// <summary>
 /// Normalize email
 /// </summary>
 /// <param name="email"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static MailAddress Normalize(this MailAddress email, NormalizerSettings settings = null)
 {
     return(Normalizer.Normalize(email, settings));
 }