burner/validate/mail.go

34 lines
644 B
Go
Raw Normal View History

2016-02-02 18:43:57 +00:00
package validate
import (
"errors"
"strings"
)
// Friendly user-facing errors
var (
errBadEmail = errors.New("User doesn't exist.")
)
// Email does basic validation on the intended receiving address. It returns a
// friendly error message that can be served directly to connecting clients if
// validation fails.
func Email(to string) error {
host := to[strings.IndexRune(to, '@')+1:]
// TODO: use given configurable host (don't hardcode)
if host != "writ.es" {
return errBadEmail
}
toName := to[:strings.IndexRune(to, '@')]
if toName == "anyone" {
return nil
}
if len(toName) != 32 {
return errBadEmail
}
return nil
}