protected function auth() {
if (!$this->username || !$this->password) return;
+ $authException = null;
foreach ($this->features as $feature) {
$parameters = explode(" ", $feature);
if ($parameters[0] == 'auth') {
- // try mechanisms in order of preference
+ // Try mechanisms in order of preference.
foreach (['login', 'plain'] as $method) {
if (in_array($method, $parameters)) {
switch ($method) {
$this->read([334]);
}
catch (SystemException $e) {
+ $authException = $e;
// try next authentication method
continue 2;
}
$this->write(base64_encode($this->password));
$this->lastWrite = '*redacted*';
$this->read([235]);
+
+ // Authentication was successful.
return;
break;
case 'plain':
$this->read([334]);
}
catch (SystemException $e) {
+ $authException = $e;
// try next authentication method
continue 2;
}
$this->write(base64_encode("\0".$this->username."\0".$this->password));
$this->lastWrite = '*redacted*';
$this->read([235]);
+
+ // Authentication was successful.
return;
}
}
}
- return;
+ // No mechanism was accepted.
+ break;
}
}
// server does not support auth
+ throw new TransientFailure("Remote SMTP server does not support AUTH, but SMTP credentials are specified.", 0, $authException);
}
/**