class MailAutoconfig::EmailAddress

Email address that we're going to investigate

Attributes

address[R]

Public Class Methods

new(address) click to toggle source

@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

client_config() click to toggle source

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
domain() click to toggle source

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
local_part() click to toggle source

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
primary_mx_domain() click to toggle source

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

# 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

Private Instance Methods

mx_records() click to toggle source

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