class MailAutoconfig::ClientConfig

Parse the Autoconfig XML file and create a ruby representation

Attributes

config[R]
email_address[RW]

Public Class Methods

from_file(path) click to toggle source

Build a configuration from the specified path @param path [String] the loction of the client configuartion file @return [ClientConfig] new client configuration

# File lib/mail_autoconfig/client_config.rb, line 13
def from_file(path)
  self.new(File.read(path))
end
new(client_config_xml) click to toggle source

@param client_config_xml [String] the raw XML to build the ClientConfig from.

# File lib/mail_autoconfig/client_config.rb, line 60
def initialize(client_config_xml)
  @config = Nokogiri::XML(client_config_xml)
end
search_autoconfig_domain(domain) click to toggle source

Try a remote server for the configuration for the domain. Search `autoconfig.#{domain}/mail/config-v1.1.xml` first, followed by `#{domain}/.well-known/autoconfig/mail/config-v1.1.xml` @param domain [String] the domain to look for @return [ClientConfig] the client configuration for the domain

# 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) click to toggle source

Search local ISPDB for configurations matching the domain @param domain [String] the domain to look for @return [ClientConfig] client configuration for the domain

# 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

Public Instance Methods

domains() click to toggle source

A list of domain aliases that this configuration applies to @return [Array] list of domains for this configuration

# File lib/mail_autoconfig/client_config.rb, line 66
def domains
  @domains ||= provider.xpath('domain').map {|domain| domain.content }
end
incoming_servers() click to toggle source

The incoming servers for this configuration. There can be multiple servers per configuration e.g. for IMAP and POP3, ordered in list of preference. @return [Array] list of incoming servers

# 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() click to toggle source

@return [String] the full name of this service (e.g. Google Mail)

# File lib/mail_autoconfig/client_config.rb, line 83
def name
  @name ||= provider.xpath('displayName').first.content
end
outgoing_servers() click to toggle source

The outgoing servers for this configuration. There can be multiple servers per configuration, ordered in list of preference. @return [Array] list of outgoing servers

# 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() click to toggle source

@return [String] The unique string identifying this service (e.g. googlemail.com)

# File lib/mail_autoconfig/client_config.rb, line 78
def provider_id
  @provider_id ||= provider.attr('id').value
end
short_name() click to toggle source

@return [String] the short name of this service (e.g. GMail)

# File lib/mail_autoconfig/client_config.rb, line 88
def short_name
  @short_name ||= provider.xpath('displayShortName').first.content
end
valid_for_domain?(domain) click to toggle source

Does this configuration file apply to the specified domain? @param domain [String] the domain to check @return [Boolean] Does the domain match?

# File lib/mail_autoconfig/client_config.rb, line 73
def valid_for_domain?(domain)
  domains.any? {|d| d == domain}
end

Private Instance Methods

provider() click to toggle source

@return [Nokogiri::XML::Node] the root configuration node

# File lib/mail_autoconfig/client_config.rb, line 113
def provider
  @provider ||= config.xpath('//clientConfig/emailProvider')
end