switch email address validation to mail.ParseAddress
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user