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.
60 61 62 |
# File 'lib/mail_autoconfig/client_config.rb', line 60 def initialize(client_config_xml) @config = Nokogiri::XML(client_config_xml) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/mail_autoconfig/client_config.rb', line 6 def config @config end |
#email_address ⇒ Object
Returns the value of attribute email_address.
7 8 9 |
# File 'lib/mail_autoconfig/client_config.rb', line 7 def email_address @email_address end |
Class Method Details
.from_file(path) ⇒ ClientConfig
Build a configuration from the specified path
13 14 15 |
# File 'lib/mail_autoconfig/client_config.rb', line 13 def from_file(path) self.new(File.read(path)) end |
.search(domain) ⇒ ClientConfig
Try to find a configuration for the given domain, locally or remotely
20 21 22 |
# File 'lib/mail_autoconfig/client_config.rb', line 20 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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mail_autoconfig/client_config.rb', line 41 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| begin response = Faraday.get(url) if response.status == 200 last_config = self.new(response.body) else false end rescue false end end match ? last_config : false end |
.search_local_files(domain) ⇒ ClientConfig
Search local ISPDB for configurations matching the domain
27 28 29 30 31 32 33 34 |
# File 'lib/mail_autoconfig/client_config.rb', line 27 def search_local_files(domain) last_config = false match = Dir.glob(File.join(MailAutoconfig.local_ispdb_path, '*')).find do |config_file| last_config = self.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
66 67 68 |
# File 'lib/mail_autoconfig/client_config.rb', line 66 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.
95 96 97 98 99 |
# File 'lib/mail_autoconfig/client_config.rb', line 95 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).
83 84 85 |
# File 'lib/mail_autoconfig/client_config.rb', line 83 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.
104 105 106 107 108 |
# File 'lib/mail_autoconfig/client_config.rb', line 104 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).
78 79 80 |
# File 'lib/mail_autoconfig/client_config.rb', line 78 def provider_id @provider_id ||= provider.attr('id').value end |
#short_name ⇒ String
Returns the short name of this service (e.g. GMail).
88 89 90 |
# File 'lib/mail_autoconfig/client_config.rb', line 88 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?
73 74 75 |
# File 'lib/mail_autoconfig/client_config.rb', line 73 def valid_for_domain?(domain) domains.any? {|d| d == domain} end |