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 Method Summary (collapse)

Constructor Details

- (EmailAddress) initialize(address)

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 Method Details

- (MailAutoconfig::ClientConfig) client_config

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
23
24
# File 'lib/mail_autoconfig/email_address.rb', line 15

def client_config
  return @client_config if @client_config
  
  @client_config = MailAutoconfig::ClientConfig.search(domain)
  unless @client_config
    @client_config = MailAutoconfig::ClientConfig.search(primary_mx_domain)
  end
  
  @client_config
end

- (String) domain

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

Returns:

  • (String)

    the domain of the email address



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

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

- (String) local_part

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



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

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

- (String) primary_mx_domain

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



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

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