Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Exchange version and typo fix #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions lib/autodiscover/pox_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
11 changes: 8 additions & 3 deletions lib/autodiscover/pox_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions lib/autodiscover/server_version_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class ServerVersionParser
},
15 => {
0 => "Exchange2013",
1 => "Exchange2013_SP1",
1 => "Exchange2016",
20 => "Exchange2017"
}
}

Expand All @@ -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
Expand Down