Class: MailAutoconfig::EmailAddress
- Inherits:
-
Object
- Object
- MailAutoconfig::EmailAddress
- Defined in:
- lib/mail_autoconfig/email_address.rb
Overview
Email address that we're going to investigate
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
Instance Method Summary collapse
-
#client_config ⇒ MailAutoconfig::ClientConfig
Fetch the client configuration for this email address.
-
#domain ⇒ String
The domain of the email address (the part after the @ symbol).
-
#initialize(address) ⇒ EmailAddress
constructor
A new instance of EmailAddress.
-
#local_part ⇒ String
The local part of the emai address (before the @ symbol).
-
#primary_mx_domain ⇒ String
Finds the primary MX domain for this address.
Constructor Details
#initialize(address) ⇒ EmailAddress
Returns a new instance of EmailAddress.
7 8 9 |
# File 'lib/mail_autoconfig/email_address.rb', line 7 def initialize(address) @address = address end |
Instance Attribute Details
#address ⇒ Object (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_config ⇒ MailAutoconfig::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.
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 |
#domain ⇒ String
The domain of the email address (the part after the @ symbol)
33 34 35 |
# File 'lib/mail_autoconfig/email_address.rb', line 33 def domain @domain ||= @address.split("@", 2).last end |
#local_part ⇒ String
The local part of the emai address (before the @ symbol). Useful for usage with the %EMAILLOCALPART% substitution.
27 28 29 |
# File 'lib/mail_autoconfig/email_address.rb', line 27 def local_part @local_part ||= @address.split("@", 2).first end |
#primary_mx_domain ⇒ String
Finds the primary MX domain for this address. Would change gmail-smtp-in.l.google.com to google.com
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 |