Skip to content

Commit

Permalink
added dynamic parser idn email domain
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Jun 26, 2024
1 parent d6a1163 commit 73ed31e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 0 additions & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
class ApplicationController < ActionController::Base
include Pagy::Backend

# prepend_before_action :convert_punycode_params

helper_method :turbo_frame_request?

protect_from_forgery with: :exception
Expand Down Expand Up @@ -66,12 +64,6 @@ def clear_flash
flash.clear if turbo_frame_request?
end

# def convert_punycode_params
# return unless email = request.params.dig(:user, :email)

# request.params[:user][:email] = email.split('@').map { |val| SimpleIDN.to_ascii(val) }.join('@')
# end

protected

def authenticate_user!
Expand Down
13 changes: 13 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ApplicationMailer < ActionMailer::Base
before_action :add_smtputf8_header
before_action :convert_email_to_punycode

default from: Rails.application.config.customization['email_from_address']
layout 'mailer'
Expand All @@ -9,4 +10,16 @@ class ApplicationMailer < ActionMailer::Base
def add_smtputf8_header
headers['SMTPUTF8'] = 'true'
end

def convert_email_to_punycode
mail.to = Array(mail.to).map { |email| convert_domain_to_punycode(email) }
mail.cc = Array(mail.cc).map { |email| convert_domain_to_punycode(email) }
mail.bcc = Array(mail.bcc).map { |email| convert_domain_to_punycode(email) }
end

def convert_domain_to_punycode(email)
local, domain = email.split('@')
domain = SimpleIDN.to_ascii(domain)
"#{local}@#{domain}"
end
end

0 comments on commit 73ed31e

Please sign in to comment.