A temporary email service written in Go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
644 B

  1. package validate
  2. import (
  3. "errors"
  4. "strings"
  5. )
  6. // Friendly user-facing errors
  7. var (
  8. errBadEmail = errors.New("User doesn't exist.")
  9. )
  10. // Email does basic validation on the intended receiving address. It returns a
  11. // friendly error message that can be served directly to connecting clients if
  12. // validation fails.
  13. func Email(to string) error {
  14. host := to[strings.IndexRune(to, '@')+1:]
  15. // TODO: use given configurable host (don't hardcode)
  16. if host != "writ.es" {
  17. return errBadEmail
  18. }
  19. toName := to[:strings.IndexRune(to, '@')]
  20. if toName == "anyone" {
  21. return nil
  22. }
  23. if len(toName) != 32 {
  24. return errBadEmail
  25. }
  26. return nil
  27. }