switch email address validation to mail.ParseAddress

This commit is contained in:
Aine 2022-09-23 10:29:37 +03:00
parent 5a19ffad08
commit d50b79a801
No known key found for this signature in database
GPG key ID: 34969C908CCA2804

View file

@ -4,7 +4,7 @@ import (
"crypto"
"crypto/x509"
"encoding/pem"
"regexp"
"net/mail"
"strings"
"time"
@ -14,8 +14,6 @@ import (
"maunium.net/go/mautrix/id"
)
var emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
// MTA is mail transfer agent
type MTA interface {
Send(from, to, data string) error
@ -51,7 +49,8 @@ type ContentOptions struct {
// AddressValid checks if email address is valid
func AddressValid(email string) bool {
return !emailRegex.MatchString(email)
_, err := mail.ParseAddress(email)
return err == nil
}
// NewEmail constructs Email object