Class: MailAutoconfig::EmailAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_autoconfig/email_address.rb

Overview

Email address that we're going to investigate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ EmailAddress

Returns a new instance of EmailAddress.

Parameters:

  • address (String)

    the email address to look up



8
9
10
# File 'lib/mail_autoconfig/email_address.rb', line 8

def initialize(address)
  @address = address
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



5
6
7
# File 'lib/mail_autoconfig/email_address.rb', line 5

def address
  @address
end

Instance Method Details

#client_configMailAutoconfig::ClientConfig

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.

Returns:



16
17
18
19
20
21
22
23
# 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

#domainString

The domain of the email address (the part after the @ symbol)

Returns:

  • (String)

    the domain of the email address



34
35
36
# File 'lib/mail_autoconfig/email_address.rb', line 34

def domain
  @domain ||= @address.split('@', 2).last
end

#local_partString

The local part of the emai address (before the @ symbol). Useful for usage with the %EMAILLOCALPART% substitution.

Returns:

  • (String)

    the local part of the email address



28
29
30
# File 'lib/mail_autoconfig/email_address.rb', line 28

def local_part
  @local_part ||= @address.split('@', 2).first
end

#primary_mx_domainString

Finds the primary MX domain for this address. Would change gmail-smtp-in.l.google.com to google.com

Returns:

  • (String)

    the domain of the pimary MX record for this address



40
41
42
# File 'lib/mail_autoconfig/email_address.rb', line 40

def primary_mx_domain
  @primary_mx_domain ||= mx_records.first.split(".")[-2..-1].join(".") # Not very nice to 2nd level domains
end