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

Check if redirect is used for this Autodiscover call and if so, follo… #504

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions src/Autodiscover.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,24 @@ public function discover()
$result = $this->trySRVRecord();
}

if ($result === false and is_array($this->redirect) && array_key_exists('redirectAddr', $this->redirect)) {
// redirect was found. Try again with the new address
$this->email = $this->redirect['redirectAddr'];
$this->username = $this->redirect['redirectAddr'];
$this->setTLD();
$result = $this->discover();
}

if ($result === false and is_array($this->redirect) && array_key_exists('redirectUrl', $this->redirect)) {
// redirect was found. Try again with the new URL
// https://stackoverflow.com/questions/27745/getting-parts-of-a-url-regex
$regExp = "/^(.*:)//([A-Za-z0-9\-\.]+)(:[0-9]+)?(.*)$/";
if (preg_match($regExp, $this->redirect['redirectUrl'], $matches)) {
$this->tld = $matches[2];
$result = $this->discover();
}
}

if ($result === false) {
throw new \RuntimeException('Autodiscovery failed.');
}
Expand Down