Skip to content

Commit

Permalink
Simplify code that uses setError() followed by return
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Oct 24, 2018
1 parent a86d9cd commit c4916a8
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions program/lib/Roundcube/rcube_imap_generic.php
Expand Up @@ -405,6 +405,8 @@ protected function setError($code, $msg = '')
{
$this->errornum = $code;
$this->error = $msg;

return $code;
}

/**
Expand Down Expand Up @@ -522,9 +524,8 @@ protected function authenticate($user, $pass, $type = 'PLAIN')
{
if ($type == 'CRAM-MD5' || $type == 'DIGEST-MD5') {
if ($type == 'DIGEST-MD5' && !class_exists('Auth_SASL')) {
$this->setError(self::ERROR_BYE,
return $this->setError(self::ERROR_BYE,
"The Auth_SASL package is required for DIGEST-MD5 authentication");
return self::ERROR_BAD;
}

$this->putLine($this->nextTag() . " AUTHENTICATE $type");
Expand Down Expand Up @@ -596,9 +597,8 @@ protected function authenticate($user, $pass, $type = 'PLAIN')
$challenge = substr($line, 2);
$challenge = base64_decode($challenge);
if (strpos($challenge, 'rspauth=') === false) {
$this->setError(self::ERROR_BAD,
return $this->setError(self::ERROR_BAD,
"Unexpected response from server to DIGEST-MD5 response");
return self::ERROR_BAD;
}

$this->putLine('');
Expand All @@ -609,21 +609,18 @@ protected function authenticate($user, $pass, $type = 'PLAIN')
}
else if ($type == 'GSSAPI') {
if (!extension_loaded('krb5')) {
$this->setError(self::ERROR_BYE,
return $this->setError(self::ERROR_BYE,
"The krb5 extension is required for GSSAPI authentication");
return self::ERROR_BAD;
}

if (empty($this->prefs['gssapi_cn'])) {
$this->setError(self::ERROR_BYE,
return $this->setError(self::ERROR_BYE,
"The gssapi_cn parameter is required for GSSAPI authentication");
return self::ERROR_BAD;
}

if (empty($this->prefs['gssapi_context'])) {
$this->setError(self::ERROR_BYE,
return $this->setError(self::ERROR_BYE,
"The gssapi_context parameter is required for GSSAPI authentication");
return self::ERROR_BAD;
}

putenv('KRB5CCNAME=' . $this->prefs['gssapi_cn']);
Expand All @@ -640,8 +637,7 @@ protected function authenticate($user, $pass, $type = 'PLAIN')
}
catch (Exception $e) {
trigger_error($e->getMessage(), E_USER_WARNING);
$this->setError(self::ERROR_BYE, "GSSAPI authentication failed");
return self::ERROR_BAD;
return $this->setError(self::ERROR_BYE, "GSSAPI authentication failed");
}

$this->putLine($this->nextTag() . " AUTHENTICATE GSSAPI " . $token);
Expand All @@ -658,8 +654,7 @@ protected function authenticate($user, $pass, $type = 'PLAIN')
}
catch (Exception $e) {
trigger_error($e->getMessage(), E_USER_WARNING);
$this->setError(self::ERROR_BYE, "GSSAPI authentication failed");
return self::ERROR_BAD;
return $this->setError(self::ERROR_BYE, "GSSAPI authentication failed");
}

$this->putLine(base64_encode($challenge));
Expand Down Expand Up @@ -726,13 +721,11 @@ protected function authenticate($user, $pass, $type = 'PLAIN')
if ($line && preg_match('/\[CAPABILITY ([^]]+)\]/i', $line, $matches)) {
$this->parseCapability($matches[1], true);
}

return $this->fp;
}
else {
$this->setError($result, "AUTHENTICATE $type: $line");
}

return $result;
return $this->setError($result, "AUTHENTICATE $type: $line");
}

/**
Expand All @@ -747,8 +740,7 @@ protected function login($user, $password)
{
// Prevent from sending credentials in plain text when connection is not secure
if ($this->getCapability('LOGINDISABLED')) {
$this->setError(self::ERROR_BAD, "Login disabled by IMAP server");
return false;
return $this->setError(self::ERROR_BAD, "Login disabled by IMAP server");
}

list($code, $response) = $this->execute('LOGIN', array(
Expand Down

0 comments on commit c4916a8

Please sign in to comment.