diff --git a/app/interactions/actions/simple_mail_validator.rb b/app/interactions/actions/simple_mail_validator.rb index 7d945e875d..8d71076027 100644 --- a/app/interactions/actions/simple_mail_validator.rb +++ b/app/interactions/actions/simple_mail_validator.rb @@ -3,6 +3,8 @@ module SimpleMailValidator 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 @@ def output_a_and_aaaa_validation_results(email:, result:, type:) 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 diff --git a/test/interactions/email_check_test.rb b/test/interactions/email_check_test.rb index e3b1a8a170..adecd37d48 100644 --- a/test/interactions/email_check_test.rb +++ b/test/interactions/email_check_test.rb @@ -96,6 +96,13 @@ def test_should_remove_old_record_if_multiple_contacts_has_the_same_email 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