From f5c20527aa76aa6758e4f84e82b8ba82b9599adc Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Fri, 1 Sep 2023 19:33:22 +0300 Subject: [PATCH 1/1] Move email-related methods to mixin --- app/controllers/concerns/email_methods.rb | 27 +++++++++++++++++++++++ app/controllers/users_controller.rb | 23 +------------------ 2 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 app/controllers/concerns/email_methods.rb diff --git a/app/controllers/concerns/email_methods.rb b/app/controllers/concerns/email_methods.rb new file mode 100644 index 000000000..471a61e6a --- /dev/null +++ b/app/controllers/concerns/email_methods.rb @@ -0,0 +1,27 @@ +module EmailMethods + extend ActiveSupport::Concern + + private + + def canonical_email(email) + local_part, domain = if email.nil? + nil + else + email.split("@") + end + + local_part.sub!(/\+.*$/, "") + + local_part.delete!(".") if %w[gmail.com googlemail.com].include?(domain) + + "#{local_part}@#{domain}" + end + + ## + # get list of MX servers for a domains + def domain_mx_servers(domain) + Resolv::DNS.open do |dns| + dns.getresources(domain, Resolv::DNS::Resource::IN::MX).collect { |mx| mx.exchange.to_s } + end + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9d4b3d258..5ba1b702b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ class UsersController < ApplicationController + include EmailMethods include SessionMethods include UserMethods @@ -361,26 +362,4 @@ class UsersController < ApplicationController !blocked end - - def canonical_email(email) - local_part, domain = if email.nil? - nil - else - email.split("@") - end - - local_part.sub!(/\+.*$/, "") - - local_part.delete!(".") if %w[gmail.com googlemail.com].include?(domain) - - "#{local_part}@#{domain}" - end - - ## - # get list of MX servers for a domains - def domain_mx_servers(domain) - Resolv::DNS.open do |dns| - dns.getresources(domain, Resolv::DNS::Resource::IN::MX).collect { |mx| mx.exchange.to_s } - end - end end -- 2.39.5