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



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

def initialize(address)
  @address = address
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



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

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:



15
16
17
18
19
20
21
22
# File 'lib/mail_autoconfig/email_address.rb', line 15

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



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

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



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

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



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

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