mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Add punycode email support
This commit is contained in:
parent
c344b91d84
commit
550c5abd6c
4 changed files with 45 additions and 4 deletions
|
@ -9,16 +9,17 @@ module Actions
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
result = check_email
|
parsed_email = EmailAddressConverter.punycode_to_unicode(email)
|
||||||
|
result = check_email(parsed_email)
|
||||||
save_result(result)
|
save_result(result)
|
||||||
log_failure(result) unless result.success
|
result.success ? log_success : log_failure(result)
|
||||||
result.success
|
result.success
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_email
|
def check_email(parsed_email)
|
||||||
Truemail.validate(email, with: check_level).result
|
Truemail.validate(parsed_email, with: check_level).result
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_result(result)
|
def save_result(result)
|
||||||
|
@ -46,6 +47,10 @@ module Actions
|
||||||
logger.info "Validation level #{check_level}, the result was #{result}"
|
logger.info "Validation level #{check_level}, the result was #{result}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log_success
|
||||||
|
logger.info "Successfully validated email #{email} for the #{log_object_id}."
|
||||||
|
end
|
||||||
|
|
||||||
def log_object_id
|
def log_object_id
|
||||||
"#{validation_eventable.class}: #{validation_eventable.id}"
|
"#{validation_eventable.class}: #{validation_eventable.id}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
require 'application_service'
|
require 'application_service'
|
||||||
|
require 'email_address_converter'
|
||||||
require 'xsd/schema'
|
require 'xsd/schema'
|
33
lib/email_address_converter.rb
Normal file
33
lib/email_address_converter.rb
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
module EmailAddressConverter
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def punycode_to_unicode(email)
|
||||||
|
return email if domain(email) == 'not_found'
|
||||||
|
|
||||||
|
local = local(email)
|
||||||
|
domain = SimpleIDN.to_unicode(domain(email))
|
||||||
|
"#{local}@#{domain}"&.downcase
|
||||||
|
end
|
||||||
|
|
||||||
|
def unicode_to_punycode(email)
|
||||||
|
return email if domain(email) == 'not_found'
|
||||||
|
|
||||||
|
local = local(email)
|
||||||
|
domain = SimpleIDN.to_ascii(domain(email))
|
||||||
|
"#{local}@#{domain}"&.downcase
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def domain(email)
|
||||||
|
Mail::Address.new(email).domain&.downcase || 'not_found'
|
||||||
|
rescue Mail::Field::IncompleteParseError
|
||||||
|
'not_found'
|
||||||
|
end
|
||||||
|
|
||||||
|
def local(email)
|
||||||
|
Mail::Address.new(email).local&.downcase || email
|
||||||
|
rescue Mail::Field::IncompleteParseError
|
||||||
|
email
|
||||||
|
end
|
||||||
|
end
|
|
@ -20,4 +20,6 @@ namespace :verify_email do
|
||||||
.by_domain(args[:domain_name])
|
.by_domain(args[:domain_name])
|
||||||
verifications_by_domain.map { |ver| VerifyEmailsJob.perform_later(ver.id) }
|
verifications_by_domain.map { |ver| VerifyEmailsJob.perform_later(ver.id) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'Starts verifying email jobs with check level and '
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue