mirror of
https://github.com/neilalexander/yggmail.git
synced 2026-05-08 12:56:27 +03:00
Accept usernames as email format
This commit is contained in:
19
internal/utils/address.go
Normal file
19
internal/utils/address.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const TLD = ".yggmail"
|
||||
|
||||
func ParseAddress(email string) (string, string, error) {
|
||||
if !strings.HasSuffix(email, TLD) {
|
||||
return "", "", fmt.Errorf("invalid TLD")
|
||||
}
|
||||
at := strings.LastIndex(email, "@")
|
||||
if at == 0 {
|
||||
return "", "", fmt.Errorf("invalid email address")
|
||||
}
|
||||
return email[:at], strings.TrimSuffix(email[at+1:], TLD), nil
|
||||
}
|
||||
Reference in New Issue
Block a user