Class: MailAutoconfig::ClientConfig
- Inherits:
-
Object
- Object
- MailAutoconfig::ClientConfig
- Defined in:
- lib/mail_autoconfig/client_config.rb
Overview
Parse the Autoconfig XML file and create a ruby representation
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#email_address ⇒ Object
Returns the value of attribute email_address.
Class Method Summary collapse
-
.from_file(path) ⇒ ClientConfig
Build a configuration from the specified path.
-
.search(domain) ⇒ ClientConfig
Try to find a configuration for the given domain, locally or remotely.
-
.search_autoconfig_domain(domain) ⇒ ClientConfig
Try a remote server for the configuration for the domain.
-
.search_local_files(domain) ⇒ ClientConfig
Search local ISPDB for configurations matching the domain.
Instance Method Summary collapse
-
#domains ⇒ Array
A list of domain aliases that this configuration applies to.
-
#incoming_servers ⇒ Array
The incoming servers for this configuration.
-
#initialize(client_config_xml) ⇒ ClientConfig
constructor
A new instance of ClientConfig.
-
#name ⇒ String
The full name of this service (e.g. Google Mail).
-
#outgoing_servers ⇒ Array
The outgoing servers for this configuration.
-
#provider_id ⇒ String
The unique string identifying this service (e.g. googlemail.com).
-
#short_name ⇒ String
The short name of this service (e.g. GMail).
-
#valid_for_domain?(domain) ⇒ Boolean
Does this configuration file apply to the specified domain?.
Constructor Details
#initialize(client_config_xml) ⇒ ClientConfig
Returns a new instance of ClientConfig.
56 57 58 |
# File 'lib/mail_autoconfig/client_config.rb', line 56 def initialize(client_config_xml) @config = Nokogiri::XML(client_config_xml) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/mail_autoconfig/client_config.rb', line 4 def config @config end |
#email_address ⇒ Object
Returns the value of attribute email_address.
5 6 7 |
# File 'lib/mail_autoconfig/client_config.rb', line 5 def email_address @email_address end |
Class Method Details
.from_file(path) ⇒ ClientConfig
Build a configuration from the specified path
11 12 13 |
# File 'lib/mail_autoconfig/client_config.rb', line 11 def from_file(path) new(File.read(path)) end |
.search(domain) ⇒ ClientConfig
Try to find a configuration for the given domain, locally or remotely
18 19 20 |
# File 'lib/mail_autoconfig/client_config.rb', line 18 def search(domain) search_local_files(domain) || search_autoconfig_domain(domain) end |
.search_autoconfig_domain(domain) ⇒ ClientConfig
Try a remote server for the configuration for the domain.
Search http://autoconfig.#{domain}/mail/config-v1.1.xml
first,
followed by http://#{domain}/.well-known/autoconfig/mail/config-v1.1.xml
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mail_autoconfig/client_config.rb', line 39 def search_autoconfig_domain(domain) last_config = false match = ["http://autoconfig.#{domain}/mail/config-v1.1.xml", "http://#{domain}/.well-known/autoconfig/mail/config-v1.1.xml"].find do |url| response = Faraday.get(url) if response.status == 200 last_config = new(response.body) else false end rescue false end match ? last_config : false end |
.search_local_files(domain) ⇒ ClientConfig
Search local ISPDB for configurations matching the domain
25 26 27 28 29 30 31 32 |
# File 'lib/mail_autoconfig/client_config.rb', line 25 def search_local_files(domain) last_config = false match = Dir.glob(File.join(MailAutoconfig.local_ispdb_path, "*")).find do |config_file| last_config = from_file(config_file) last_config.valid_for_domain?(domain) end match ? last_config : false end |
Instance Method Details
#domains ⇒ Array
A list of domain aliases that this configuration applies to
62 63 64 |
# File 'lib/mail_autoconfig/client_config.rb', line 62 def domains @domains ||= provider.xpath("domain").map { |domain| domain.content } end |
#incoming_servers ⇒ Array
The incoming servers for this configuration. There can be multiple servers per configuration e.g. for IMAP and POP3, ordered in list of preference.
91 92 93 94 95 |
# File 'lib/mail_autoconfig/client_config.rb', line 91 def incoming_servers @incoming_servers ||= provider.xpath("incomingServer").map do |incoming| MailAutoconfig::IncomingServer.new(incoming, self) end end |
#name ⇒ String
Returns the full name of this service (e.g. Google Mail).
79 80 81 |
# File 'lib/mail_autoconfig/client_config.rb', line 79 def name @name ||= provider.xpath("displayName").first.content end |
#outgoing_servers ⇒ Array
The outgoing servers for this configuration. There can be multiple servers per configuration, ordered in list of preference.
100 101 102 103 104 |
# File 'lib/mail_autoconfig/client_config.rb', line 100 def outgoing_servers @outgoing_servers ||= provider.xpath("outgoingServer").map do |outgoing| MailAutoconfig::OutgoingServer.new(outgoing, self) end end |
#provider_id ⇒ String
Returns The unique string identifying this service (e.g. googlemail.com).
74 75 76 |
# File 'lib/mail_autoconfig/client_config.rb', line 74 def provider_id @provider_id ||= provider.attr("id").value end |
#short_name ⇒ String
Returns the short name of this service (e.g. GMail).
84 85 86 |
# File 'lib/mail_autoconfig/client_config.rb', line 84 def short_name @short_name ||= provider.xpath("displayShortName").first.content end |
#valid_for_domain?(domain) ⇒ Boolean
Does this configuration file apply to the specified domain?
69 70 71 |
# File 'lib/mail_autoconfig/client_config.rb', line 69 def valid_for_domain?(domain) domains.any? { |d| d == domain } end |