Skip to content

Commit

Permalink
Merge pull request #2609 from internetee/unable-to-create-contact-wit…
Browse files Browse the repository at this point in the history
…h-punnycode

Unable to create contact with punnycode
  • Loading branch information
vohmar authored Aug 23, 2023
2 parents 2880373 + f8fcf0e commit 5fc8bc9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/interactions/actions/simple_mail_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/interactions/email_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5fc8bc9

Please sign in to comment.