예제 #1
0
        public virtual NormalizedEmailAddress NormalizeAsParts(string emailAddress)
        {
            if (string.IsNullOrWhiteSpace(emailAddress))
            {
                return(null);
            }

            var parts = emailAddress
                        .Trim()
                        .Split('@', System.StringSplitOptions.RemoveEmptyEntries);

            // only 1 @ permitted, not at the start or end
            if (parts.Length != 2)
            {
                return(null);
            }

            // Note that in practice it's very unlikely that the local part needs to be case-sensitive
            // but technically only the domain part is case-insensitive. A username formatter may choose
            // to be less RFC compliant here, but for email correspondance we should honor the spec.
            var local = parts[0];

            var domain = EmailDomainName.Parse(parts[1]);
            var result = new NormalizedEmailAddress(local, domain);

            return(result);
        }
예제 #2
0
 public virtual NormalizedEmailAddress UniquifyAsParts(NormalizedEmailAddress emailAddressParts)
 {
     return(emailAddressParts?.ToLower());
 }
 /// <summary>
 /// Format an email address into a value that can be used for
 /// uniqueness comparisons. The default implementation simply lowercases
 /// the email, but this can be overriden to provide more strict uniqueness
 /// checks.
 /// </summary>
 /// <param name="emailAddressParts">
 /// The pre-normalized email address to uniquify. If the value is <see langword="null"/>
 /// then <see langword="null"/> is returned.
 /// </param>
 public static string Uniquify(this IEmailAddressUniquifier uniquifier, NormalizedEmailAddress emailAddressParts)
 {
     return(uniquifier
            .UniquifyAsParts(emailAddressParts)
            ?.ToEmailAddress());
 }