Documentation
¶
Index ¶
Constants ¶
const ( // ChangeTrimmedWhitespace is applied when leading or trailing whitespace is // removed from the raw input. ChangeTrimmedWhitespace = rules.ChangeTrimmedWhitespace // ChangeRemovedTrailingDot is applied when one or more trailing dots are // stripped from the raw input. ChangeRemovedTrailingDot = rules.ChangeRemovedTrailingDot // ChangeLowercase is applied when the username or domain contains uppercase // letters that are converted to lower case. ChangeLowercase = rules.ChangeLowercase // ChangeRemovedDots is applied when dot characters are removed from the // username (e.g. Google, Protonmail). ChangeRemovedDots = rules.ChangeRemovedDots // ChangeRemovedUnderscores is applied when underscore characters are removed // from the username (e.g. Protonmail). ChangeRemovedUnderscores = rules.ChangeRemovedUnderscores // ChangeRemovedHyphens is applied when hyphen characters are removed from // the username (e.g. Protonmail). ChangeRemovedHyphens = rules.ChangeRemovedHyphens // ChangeReplacedHyphensWithDots is applied when hyphen characters in the // username are replaced with dots (e.g. Yandex). ChangeReplacedHyphensWithDots = rules.ChangeReplacedHyphensWithDots // ChangeRemovedPlusTag is applied when a plus-sign subaddress ("+tag") is // stripped from the end of the username (e.g. Google, Apple, Fastmail, // Protonmail). ChangeRemovedPlusTag = rules.ChangeRemovedPlusTag // ChangeRemovedPlusSigns is applied when plus-sign characters are removed // from the username without subaddress semantics — every "+" is deleted // regardless of position (e.g. Microsoft, Rackspace, Rambler, Yandex, Zoho). ChangeRemovedPlusSigns = rules.ChangeRemovedPlusSigns // ChangeRemovedSubaddress is applied when a dash-delimited subaddress // ("-tag") is stripped from the end of the username (e.g. Yahoo). ChangeRemovedSubaddress = rules.ChangeRemovedSubaddress // ChangeCanonicalisedDomain is applied when the domain is rewritten to its // canonical form (e.g. googlemail.com → gmail.com, me.com → icloud.com, // ya.ru → yandex.ru). ChangeCanonicalisedDomain = rules.ChangeCanonicalisedDomain )
Variables ¶
This section is empty.
Functions ¶
func ValidateEmail ¶ added in v1.2.0
Types ¶
type Change ¶
Change is a string enum identifying a single transformation applied to an email address during normalization. It is returned by Normalize2.
type NormalizeResult ¶
type NormalizeResult struct {
// Normalized is the canonical form of the email address.
Normalized string
// Changes lists every transformation that was applied, in the order they
// were first detected. Each Change value appears at most once.
Changes []Change
}
NormalizeResult is the return value of Normalize2.
type Normalizer ¶
type Normalizer struct {
// contains filtered or unexported fields
}
Normalizer : main library object for normalization emails
func (*Normalizer) AddRule ¶
func (n *Normalizer) AddRule(domain string, strategy NormalizingRule)
AddRule : appends custom normalization rule
func (*Normalizer) Normalize ¶
func (n *Normalizer) Normalize(email string) string
Normalize : converts email to canonical form
func (*Normalizer) Normalize2 ¶
func (n *Normalizer) Normalize2(email string) (NormalizeResult, error)
Normalize2 converts any input string to a canonical email address and returns a NormalizeResult that includes both the normalized address and every transformation applied.
Unlike Normalize, Normalize2 validates the input using an RFC 5322-compatible email regex (sourced from github.com/go-playground/validator). It requires a dot-separated domain (e.g. "gmail.com"), so inputs like "user@gmailcom" are rejected. Trailing whitespace and trailing dots are stripped before validation, so those are handled correctly. If the input is not a valid email address, a zero-valued NormalizeResult and a non-nil error are returned.
Rules registered via AddRule that only implement NormalizingRule (not NormalizingRuleWithChanges) are still fully supported — the normalized address will be correct, but per-rule changes will not be reported. Pre-processing changes (whitespace trimming, trailing-dot removal, domain lowercasing) are always tracked regardless of the rule type.
type NormalizingRule ¶
NormalizingRule : interface for all email normalization rules
type NormalizingRuleWithChanges ¶
type NormalizingRuleWithChanges interface {
NormalizingRule
ProcessUsernameWithChanges(username string) (result string, changes []Change)
ProcessDomainWithChanges(domain string) (result string, changes []Change)
}
NormalizingRuleWithChanges is an optional extension of NormalizingRule. Rules that implement it allow Normalize2 to report the individual transformations applied to the username and domain. Rules added via AddRule that only satisfy NormalizingRule are still supported by Normalize2 — they will not report per-rule changes, but global pre-processing changes (whitespace trimming, trailing-dot removal, domain lowercasing) are always tracked.