email_address_validation.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. # Validation for email addresses
  3. class EmailAddressValidation
  4. attr_reader :email_address
  5. # @param [String] email_address Email address to be validated
  6. def initialize(email_address)
  7. @email_address = email_address
  8. end
  9. def to_s
  10. email_address
  11. end
  12. # Checks if the email address has a valid format.
  13. # Reports email addresses without dot in domain as valid (zammad@localhost).
  14. #
  15. # @param mx [Boolean] check only syntax or MX as well
  16. #
  17. # @return [true] if email address has valid format
  18. # @return [false] if email address has no valid format
  19. def valid?(check_mx: false)
  20. EmailAddressValidator.valid? email_address,
  21. host_validation: (check_mx ? :mx : :syntax),
  22. local_encoding: :unicode,
  23. host_local: true,
  24. host_fqdn: false,
  25. host_auto_append: false
  26. end
  27. end