diff --git a/lib/autodiscover/pox_request.rb b/lib/autodiscover/pox_request.rb index fc661b3..f53593e 100644 --- a/lib/autodiscover/pox_request.rb +++ b/lib/autodiscover/pox_request.rb @@ -16,21 +16,13 @@ def initialize(client, **options) # @return [Autodiscover::PoxResponse, nil] def autodiscover available_urls.each do |url| - begin - response = client.http.post(url, request_body, {'Content-Type' => 'text/xml; charset=utf-8'}) - return PoxResponse.new(response.body) if good_response?(response) - rescue Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError - next - rescue OpenSSL::SSL::SSLError - options[:ignore_ssl_errors] ? next : raise - end + response = client.http.post(url, request_body, {'Content-Type' => 'text/xml; charset=utf-8'}) + return PoxResponse.new(response.body) if good_response?(response) end end - private - def good_response?(response) response.status == 200 end @@ -39,10 +31,14 @@ def available_urls(&block) return to_enum(__method__) unless block_given? formatted_https_urls.each {|url| logger.debug "Yielding HTTPS Url #{url}" - yield url + handle_allowed_errors do + yield url + end } - logger.debug "Yielding HTTP Redirected Url #{redirected_http_url}" - yield redirected_http_url + handle_allowed_errors do + logger.debug "Yielding HTTP Redirected Url #{redirected_http_url}" + yield redirected_http_url + end end def formatted_https_urls @@ -71,5 +67,12 @@ def request_body end.to_xml end + def handle_allowed_errors + yield + rescue SocketError, Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError + rescue Errno::EADDRNOTAVAIL + rescue OpenSSL::SSL::SSLError + raise if !options[:ignore_ssl_errors] + end end end diff --git a/lib/autodiscover/pox_response.rb b/lib/autodiscover/pox_response.rb index 7d0dfbf..5b1d296 100644 --- a/lib/autodiscover/pox_response.rb +++ b/lib/autodiscover/pox_response.rb @@ -17,16 +17,21 @@ def ews_url end def exch_proto - @exch_proto ||= (response["Account"]["Protocol"].select{|p| p["Type"] == "EXCH"}.first || {}) + @exch_proto ||= protocols.find { |p| p["Type"] == "EXCH" } || {} end def expr_proto - @expr_proto ||= (response["Account"]["Protocol"].select{|p| p["Type"] == "EXPR"}.first || {}) + @expr_proto ||= protocols.find { |p| p["Type"] == "EXPR" } || {} end def web_proto - @web_proto ||= (response["Account"]["Protocol"].select{|p| p["Type"] == "WEB"}.first || {}) + @web_proto ||= protocols.find { |p| p["Type"] == "WEB" } || {} end + private + + def protocols + response["Account"]["Protocol"] || [] + end end end diff --git a/lib/autodiscover/server_version_parser.rb b/lib/autodiscover/server_version_parser.rb index cc8fde2..a79e627 100644 --- a/lib/autodiscover/server_version_parser.rb +++ b/lib/autodiscover/server_version_parser.rb @@ -16,7 +16,8 @@ class ServerVersionParser }, 15 => { 0 => "Exchange2013", - 1 => "Exchange2013_SP1", + 1 => "Exchange2016", + 20 => "Exchange2017" } } @@ -38,7 +39,7 @@ def build def exchange_version v = VERSIONS[major][minor] - v.nil? ? VERIONS[8][0] : v + v.nil? ? VERSIONS[8][0] : v end end