Merge pull request #2609 from internetee/unable-to-create-contact-with-punnycode

Unable to create contact with punnycode
This commit is contained in:
Timo Võhmar 2023-08-23 12:12:38 +03:00 committed by GitHub
commit 5fc8bc92d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View file

@ -3,6 +3,8 @@ module Actions
extend self
def run(email:, level:)
email = decode_email_punycode(email)
result = truemail_validate(email: email, level: level)
result = validate_for_a_and_aaaa_records(email) if !result && level == :mx
result
@ -32,6 +34,12 @@ module Actions
logger.info "Validated #{type} record for #{email}. Validation result - #{result}"
end
def decode_email_punycode(email)
local_part, domain = email.split('@')
decoded_domain = Addressable::IDNA.to_unicode(domain)
"#{local_part}@#{decoded_domain}"
end
def logger
@logger ||= Rails.logger
end

View file

@ -96,6 +96,13 @@ class EmailCheckTest < ActiveSupport::TestCase
assert_equal contact_two.validation_events.count, 3
end
def test_should_test_email_with_punnycode
email = "info@xn--energiathus-mfb.ee"
result = Actions::SimpleMailValidator.run(email: email, level: :mx)
assert result
end
private
def trumail_result