[ticket/10076] Move EHLO/HELO code into its own method.

PHPBB3-10076
This commit is contained in:
Andreas Fischer 2011-08-22 23:33:34 +02:00
parent 522090ab28
commit ac492d8f1e

View file

@ -1286,30 +1286,10 @@ class smtp_class
} }
} }
// Try EHLO first $hello_result = $this->hello($local_host);
$this->server_send("EHLO {$local_host}"); if (!is_null($hello_result))
if ($err_msg = $this->server_parse('250', __LINE__))
{ {
// a 503 response code means that we're already authenticated return $hello_result;
if ($this->numeric_response_code == 503)
{
return false;
}
// If EHLO fails, we try HELO
$this->server_send("HELO {$local_host}");
if ($err_msg = $this->server_parse('250', __LINE__))
{
return ($this->numeric_response_code == 503) ? false : $err_msg;
}
}
foreach ($this->responses as $response)
{
$response = explode(' ', $response);
$response_code = $response[0];
unset($response[0]);
$this->commands[$response_code] = implode(' ', $response);
} }
// If we are not authenticated yet, something might be wrong if no username and passwd passed // If we are not authenticated yet, something might be wrong if no username and passwd passed
@ -1355,6 +1335,42 @@ class smtp_class
return $this->$method($username, $password); return $this->$method($username, $password);
} }
/**
* SMTP EHLO/HELO
*
* @return mixed Null if the authentication process is supposed to continue
* False if already authenticated
* Error message (string) otherwise
*/
protected function hello($hostname)
{
// Try EHLO first
$this->server_send("EHLO $hostname");
if ($err_msg = $this->server_parse('250', __LINE__))
{
// a 503 response code means that we're already authenticated
if ($this->numeric_response_code == 503)
{
return false;
}
// If EHLO fails, we try HELO
$this->server_send("HELO $hostname");
if ($err_msg = $this->server_parse('250', __LINE__))
{
return ($this->numeric_response_code == 503) ? false : $err_msg;
}
}
foreach ($this->responses as $response)
{
$response = explode(' ', $response);
$response_code = $response[0];
unset($response[0]);
$this->commands[$response_code] = implode(' ', $response);
}
}
/** /**
* Pop before smtp authentication * Pop before smtp authentication
*/ */