# File lib/mail_autoconfig/email_address.rb, line 40 def primary_mx_domain @primary_mx_domain ||= begin # Not very nice to 2nd level domains mx_records.first.split(".")[-2..-1].join(".") unless mx_records.empty? end end
class MailAutoconfig::EmailAddress
Email address that we're going to investigate
Attributes
Public Class Methods
@param address [String] the email address to look up
# File lib/mail_autoconfig/email_address.rb, line 8 def initialize(address) @address = address end
Public Instance Methods
Fetch the client configuration for this email address. First of all try the domain determined by {#domain}. If nothing is found there, check the domain specified in {#primary_mx_domain}. Returns false if none found. @return [MailAutoconfig::ClientConfig] the client configuration for this address
# File lib/mail_autoconfig/email_address.rb, line 16 def client_config @client_config ||= begin config = MailAutoconfig::ClientConfig.search(domain) config ||= MailAutoconfig::ClientConfig.search(primary_mx_domain) config.email_address = self if config config end end
The domain of the email address (the part after the @ symbol) @return [String] the domain of the email address
# File lib/mail_autoconfig/email_address.rb, line 34 def domain @domain ||= @address.split('@', 2).last end
The local part of the emai address (before the @ symbol). Useful for usage with the %EMAILLOCALPART% substitution. @return [String] the local part of the email address
# File lib/mail_autoconfig/email_address.rb, line 28 def local_part @local_part ||= @address.split('@', 2).first end
Finds the primary MX domain for this address. Would change gmail-smtp-in.l.google.com to google.com @return [String] the domain of the pimary MX record for this address
Private Instance Methods
Finds MX records for the associated email address, ordered by preference. @return [Array] MX records for this email address
# File lib/mail_autoconfig/email_address.rb, line 51 def mx_records @mx_records ||= Resolv::DNS.open.getresources(domain, Resolv::DNS::Resource::IN::MX).sort_by(&:preference).map{ |r| r.exchange.to_s } end