protected function _getBestAuthMethod($authmethod = null)
{
if (!isset($this->_capability['sasl'])) {
throw new Exception('This server doesn\'t support any authentication methods. SASL problem?');
}
if (!$this->_capability['sasl']) {
throw new Exception('This server doesn\'t support any authentication methods.');
}
if ($authmethod) {
if (in_array($authmethod, $this->_capability['sasl'])) {
return $authmethod;
}
throw new Exception(sprintf('No supported authentication method found. The server supports these methods: %s, but we want to use: %s', implode(', ', $this->_capability['sasl']), $authmethod));
}
foreach ($this->supportedAuthMethods as $method) {
if (in_array($method, $this->_capability['sasl'])) {
return $method;
}
}
throw new Exception(sprintf('No supported authentication method found. The server supports these methods: %s, but we only support: %s', implode(', ', $this->_capability['sasl']), implode(', ', $this->supportedAuthMethods)));
}