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)
-
- (Object) config
readonly
Returns the value of attribute config.
Class Method Summary (collapse)
-
+ (ClientConfig) from_file(path)
Build a configuration from the specified path.
-
+ (ClientConfig) search(domain)
Try to find a configuration for the given domain, locally or remotely.
-
+ (ClientConfig) search_autoconfig_domain(domain)
Try a remote server for the configuration for the domain.
-
+ (ClientConfig) search_local_files(domain)
Search local ISPDB for configurations matching the domain.
Instance Method Summary (collapse)
-
- (Array) domains
A list of domain aliases that this configuration applies to.
-
- (Array) incoming_servers
The incoming servers for this configuration.
-
- (ClientConfig) initialize(client_config_xml)
constructor
A new instance of ClientConfig.
-
- (String) name
The full name of this service (e.g. Google Mail).
-
- (Array) outgoing_servers
The outgoing servers for this configuration.
-
- (String) provider_id
The unique string identifying this service (e.g. googlemail.com).
-
- (String) short_name
The short name of this service (e.g. GMail).
-
- (Boolean) valid_for_domain?(domain)
Does this configuration file apply to the specified domain?.
Constructor Details
- (ClientConfig) initialize(client_config_xml)
Returns a new instance of ClientConfig
59 60 61 |
# File 'lib/mail_autoconfig/client_config.rb', line 59 def initialize(client_config_xml) @config = Nokogiri::XML(client_config_xml) end |
Instance Attribute Details
- (Object) config (readonly)
Returns the value of attribute config
6 7 8 |
# File 'lib/mail_autoconfig/client_config.rb', line 6 def config @config end |
Class Method Details
+ (ClientConfig) from_file(path)
Build a configuration from the specified path
12 13 14 |
# File 'lib/mail_autoconfig/client_config.rb', line 12 def from_file(path) self.new(File.read(path)) end |
+ (ClientConfig) search(domain)
Try to find a configuration for the given domain, locally or remotely
19 20 21 |
# File 'lib/mail_autoconfig/client_config.rb', line 19 def search(domain) search_local_files(domain) || search_autoconfig_domain(domain) end |
+ (ClientConfig) search_autoconfig_domain(domain)
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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mail_autoconfig/client_config.rb', line 40 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 |
+ (ClientConfig) search_local_files(domain)
Search local ISPDB for configurations matching the domain
26 27 28 29 30 31 32 33 |
# File 'lib/mail_autoconfig/client_config.rb', line 26 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
- (Array) domains
A list of domain aliases that this configuration applies to
65 66 67 |
# File 'lib/mail_autoconfig/client_config.rb', line 65 def domains @domains ||= provider.xpath('domain').map {|domain| domain.content } end |
- (Array) incoming_servers
The incoming servers for this configuration. There can be multiple servers per configuration e.g. for IMAP and POP3, ordered in list of preference.
94 95 96 97 98 |
# File 'lib/mail_autoconfig/client_config.rb', line 94 def incoming_servers @incoming_servers ||= provider.xpath('incomingServer').map do |incoming| MailAutoconfig::IncomingServer.new(incoming) end end |
- (String) name
Returns the full name of this service (e.g. Google Mail)
82 83 84 |
# File 'lib/mail_autoconfig/client_config.rb', line 82 def name @name ||= provider.xpath('displayName').first.content end |
- (Array) outgoing_servers
The outgoing servers for this configuration. There can be multiple servers per configuration, ordered in list of preference.
103 104 105 106 107 |
# File 'lib/mail_autoconfig/client_config.rb', line 103 def outgoing_servers @outgoing_servers ||= provider.xpath('outgoingServer').map do |outgoing| MailAutoconfig::OutgoingServer.new(outgoing) end end |
- (String) provider_id
Returns The unique string identifying this service (e.g. googlemail.com)
77 78 79 |
# File 'lib/mail_autoconfig/client_config.rb', line 77 def provider_id @provider_id ||= provider.attr('id').value end |
- (String) short_name
Returns the short name of this service (e.g. GMail)
87 88 89 |
# File 'lib/mail_autoconfig/client_config.rb', line 87 def short_name @short_name ||= provider.xpath('displayShortName').first.content end |
- (Boolean) valid_for_domain?(domain)
Does this configuration file apply to the specified domain?
72 73 74 |
# File 'lib/mail_autoconfig/client_config.rb', line 72 def valid_for_domain?(domain) domains.any? {|d| d == domain} end |