switch email address validation to mail.ParseAddress
This commit is contained in:
parent
5a19ffad08
commit
d50b79a801
1 changed files with 3 additions and 4 deletions
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"regexp"
|
"net/mail"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -14,8 +14,6 @@ import (
|
||||||
"maunium.net/go/mautrix/id"
|
"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
|
// MTA is mail transfer agent
|
||||||
type MTA interface {
|
type MTA interface {
|
||||||
Send(from, to, data string) error
|
Send(from, to, data string) error
|
||||||
|
|
@ -51,7 +49,8 @@ type ContentOptions struct {
|
||||||
|
|
||||||
// AddressValid checks if email address is valid
|
// AddressValid checks if email address is valid
|
||||||
func AddressValid(email string) bool {
|
func AddressValid(email string) bool {
|
||||||
return !emailRegex.MatchString(email)
|
_, err := mail.ParseAddress(email)
|
||||||
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEmail constructs Email object
|
// NewEmail constructs Email object
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue