Skip to content
Snippets Groups Projects
Commit b40025b6 authored by Francé Wilke's avatar Francé Wilke
Browse files

Cater for only parsing an email address and not doing the domain checks

parent da19884f
No related branches found
No related tags found
No related merge requests found
......@@ -59,7 +59,7 @@ func PointerToValue[V any](value *V) V {
return *new(V) // zero value of V
}
func ValidateEmailAddress(email string) (string, error) {
func ValidateEmailAddress(email string, options ...map[string]string) (string, error) {
// To lower
cleanedEmail := strings.ToLower(strings.TrimSpace(email))
......@@ -79,12 +79,27 @@ func ValidateEmailAddress(email string) (string, error) {
return "", errors.Error("email address is empty")
}
doOnlyParse := false
if options != nil {
if value, exists := options[0]["do_only_parse"]; exists && value == "true" {
doOnlyParse = true
}
}
// Parse and verify the email
verifier := emailverifier.NewVerifier()
if doOnlyParse {
result := verifier.ParseAddress(cleanedEmail)
if !result.Valid {
return cleanedEmail, errors.Error("could not parse email address")
}
} else {
result, err := verifier.Verify(cleanedEmail)
if err != nil || !result.Syntax.Valid {
return cleanedEmail, errors.Wrap(err, "could not parse email address")
}
}
return cleanedEmail, nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment