From 9f4d4ecb8a1aa255200e7baaddee5ffbf53b4bf0 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 22 Aug 2023 15:29:18 +0300 Subject: [PATCH 1/3] email validation support for hostnames with punnycode --- app/interactions/actions/simple_mail_validator.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/interactions/actions/simple_mail_validator.rb b/app/interactions/actions/simple_mail_validator.rb index 7d945e875d..f2e9a479f8 100644 --- a/app/interactions/actions/simple_mail_validator.rb +++ b/app/interactions/actions/simple_mail_validator.rb @@ -3,6 +3,10 @@ module SimpleMailValidator extend self def run(email:, level:) + local_part, domain = email.split('@') + decoded_domain = Addressable::IDNA.to_unicode(domain) + email = "#{local_part}@#{decoded_domain}" + result = truemail_validate(email: email, level: level) result = validate_for_a_and_aaaa_records(email) if !result && level == :mx result From 64fb5c6149e39c439f067e7fb6a2b4319bcb4521 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 22 Aug 2023 15:30:19 +0300 Subject: [PATCH 2/3] refactoring --- app/interactions/actions/simple_mail_validator.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/interactions/actions/simple_mail_validator.rb b/app/interactions/actions/simple_mail_validator.rb index f2e9a479f8..8d71076027 100644 --- a/app/interactions/actions/simple_mail_validator.rb +++ b/app/interactions/actions/simple_mail_validator.rb @@ -3,9 +3,7 @@ module SimpleMailValidator extend self def run(email:, level:) - local_part, domain = email.split('@') - decoded_domain = Addressable::IDNA.to_unicode(domain) - email = "#{local_part}@#{decoded_domain}" + email = decode_email_punycode(email) result = truemail_validate(email: email, level: level) result = validate_for_a_and_aaaa_records(email) if !result && level == :mx @@ -36,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 From f8fcf0e456e84a8f1e4b7a3247c56346457ff292 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 22 Aug 2023 15:36:11 +0300 Subject: [PATCH 3/3] added test --- test/interactions/email_check_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) 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