]> git.openstreetmap.org Git - rails.git/blob - app/controllers/concerns/email_methods.rb
471a61e6aafb052ba9bea9346a1045666f4e2fbc
[rails.git] / app / controllers / concerns / email_methods.rb
1 module EmailMethods
2   extend ActiveSupport::Concern
3
4   private
5
6   def canonical_email(email)
7     local_part, domain = if email.nil?
8                            nil
9                          else
10                            email.split("@")
11                          end
12
13     local_part.sub!(/\+.*$/, "")
14
15     local_part.delete!(".") if %w[gmail.com googlemail.com].include?(domain)
16
17     "#{local_part}@#{domain}"
18   end
19
20   ##
21   # get list of MX servers for a domains
22   def domain_mx_servers(domain)
23     Resolv::DNS.open do |dns|
24       dns.getresources(domain, Resolv::DNS::Resource::IN::MX).collect { |mx| mx.exchange.to_s }
25     end
26   end
27 end