public void validateInviteUsers(InviteCommand command, MessageContext context) {
    if (!StringUtils.hasLength(command.getEmails())) {
      context.addMessage(
          new MessageBuilder()
              .error()
              .defaultText("Turite nurodyti bent vieną e-pašto adresą")
              .build());
      return;
    }

    StringTokenizer t = new StringTokenizer(command.getEmails());

    while (t.hasMoreTokens()) {
      String email = t.nextToken();
      EmailAddress a = new EmailAddress(email);
      logger.debug("validating email " + email);
      if (!a.isValid()) {
        context.addMessage(
            new MessageBuilder()
                .error()
                .defaultText(
                    "Nurodytas adresas \""
                        + email
                        + "\" neatitinka e-pašto adresų standarto. Ištrinkite arba pataisykite jį ir mėginkite dar kartą.")
                .build());
      }
    }
  }
  /**
   * @param email The user entered email address that you want to check for suggestions with
   * @return null, if no suggestions, or an EmailAddress object containing the suggestion
   */
  public EmailAddress suggest(String email) {

    EmailAddress emailParts = new EmailAddress(email);
    if (!emailParts.isValid()) return null;

    String closestDomain =
        this.findClosestString(
            emailParts.getDomain(),
            configuration.getDomains(),
            configuration.getDistanceAlgorithm(),
            configuration.getThreshold());

    if (closestDomain != null) {
      // we have a suggestion
      if (!emailParts.hasDomain(closestDomain)) {
        // if we have a suggestion different to the actual domain, return it
        return emailParts.emailAddressWithDifferentDomain(closestDomain);
      }
    } else {
      // we don't have a suggestion, check tld
      String closestTopLevelDomain =
          this.findClosestString(
              emailParts.getTLD(),
              configuration.getTopLevelDomains(),
              configuration.getDistanceAlgorithm(),
              configuration.getThreshold());
      if (emailParts.getDomain() != null
          && closestTopLevelDomain != null
          && !closestTopLevelDomain.equals(emailParts.getTLD())) {
        // return suggestion based off tld
        String domain = emailParts.getDomain();
        closestDomain =
            domain.substring(0, domain.lastIndexOf(emailParts.getTLD())) + closestTopLevelDomain;
        return emailParts.emailAddressWithDifferentDomain(closestDomain);
      }
    }

    // exact match, no match, or invalid email so no suggestion
    return null;
  }