| 706 | } |
| 707 | |
| 708 | func (a *API) validateEmail(email string) (string, error) { |
| 709 | if email == "" { |
| 710 | return "", apierrors.NewBadRequestError(apierrors.ErrorCodeValidationFailed, "An email address is required") |
| 711 | } |
| 712 | if len(email) > 255 { |
| 713 | return "", apierrors.NewBadRequestError(apierrors.ErrorCodeValidationFailed, "An email address is too long") |
| 714 | } |
| 715 | if err := checkmail.ValidateFormat(email); err != nil { |
| 716 | return "", apierrors.NewBadRequestError(apierrors.ErrorCodeValidationFailed, "Unable to validate email address: %s", err.Error()) |
| 717 | } |
| 718 | |
| 719 | return strings.ToLower(email), nil |
| 720 | } |
| 721 | |
| 722 | func validateSentWithinFrequencyLimit(sentAt *time.Time, frequency time.Duration) error { |
| 723 | if sentAt != nil && sentAt.Add(frequency).After(time.Now()) { |