Vergleich inc/mailhandlers/smtp.php - 1.8.5 - 1.8.17

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 99Zeile 99
	 * @var string
*/
public $host = '';

	 * @var string
*/
public $host = '';


/**
* The last received response from the SMTP server.
*
* @var string
*/
public $data = '';

/**
* The last received response code from the SMTP server.
*
* @var string
*/
public $code = 0;

 

/**
* The last received error message from the SMTP server.


/**
* The last received error message from the SMTP server.

Zeile 120Zeile 106
	 * @var string
*/
public $last_error = '';

	 * @var string
*/
public $last_error = '';





	/**
* Are we keeping the connection to the SMTP server alive?

	/**
* Are we keeping the connection to the SMTP server alive?

	 *
* @var boolean
*/

	 *
* @var boolean
*/

	public $keep_alive = false;

/**

	public $keep_alive = false;

/**

Zeile 141Zeile 127

$protocol = '';
switch($mybb->settings['secure_smtp'])


$protocol = '';
switch($mybb->settings['secure_smtp'])

		{

		{

			case MYBB_SSL:
$protocol = 'ssl://';
break;

			case MYBB_SSL:
$protocol = 'ssl://';
break;

Zeile 151Zeile 137
		}

if(empty($mybb->settings['smtp_host']))

		}

if(empty($mybb->settings['smtp_host']))

		{

		{

			$this->host = @ini_get('SMTP');

			$this->host = @ini_get('SMTP');

		}

		}

		else
{
$this->host = $mybb->settings['smtp_host'];

		else
{
$this->host = $mybb->settings['smtp_host'];

		}

		}


$local = array('127.0.0.1', '::1', 'localhost');
if(!in_array($this->host, $local))


$local = array('127.0.0.1', '::1', 'localhost');
if(!in_array($this->host, $local))

Zeile 191Zeile 177
			$this->port = @ini_get('smtp_port');
}
else if(!empty($mybb->settings['smtp_port']))

			$this->port = @ini_get('smtp_port');
}
else if(!empty($mybb->settings['smtp_port']))

		{

		{

			$this->port = $mybb->settings['smtp_port'];
}


			$this->port = $mybb->settings['smtp_port'];
}


Zeile 202Zeile 188
	/**
* Sends the email.
*

	/**
* Sends the email.
*

	 * @return true/false whether or not the email got sent or not.

	 * @return bool whether or not the email got sent or not.

	 */
function send()
{

	 */
function send()
{

Zeile 211Zeile 197
		if(!$this->connected())
{
if(!$this->connect())

		if(!$this->connected())
{
if(!$this->connect())

			{

			{

				$this->close();
}
}

if($this->connected())
{

				$this->close();
}
}

if($this->connected())
{

			if(!$this->send_data('MAIL FROM:<'.$this->from.'>', '250'))

			if(!$this->send_data('MAIL FROM:<'.$this->from.'>', 250))

			{
$this->fatal_error("The mail server does not understand the MAIL FROM command. Reason: ".$this->get_error());
return false;

			{
$this->fatal_error("The mail server does not understand the MAIL FROM command. Reason: ".$this->get_error());
return false;

Zeile 229Zeile 215
			foreach($emails as $to)
{
$to = trim($to);

			foreach($emails as $to)
{
$to = trim($to);

				if(!$this->send_data('RCPT TO:<'.$to.'>', '250'))

				if(!$this->send_data('RCPT TO:<'.$to.'>', 250))

				{
$this->fatal_error("The mail server does not understand the RCPT TO command. Reason: ".$this->get_error());
return false;
}
}


				{
$this->fatal_error("The mail server does not understand the RCPT TO command. Reason: ".$this->get_error());
return false;
}
}


			if($this->send_data('DATA', '354'))

			if($this->send_data('DATA', 354))

			{
$this->send_data('Date: ' . gmdate('r'));
$this->send_data('To: ' . $this->to);

			{
$this->send_data('Date: ' . gmdate('r'));
$this->send_data('To: ' . $this->to);

Zeile 250Zeile 236
				}

$this->send_data("");

				}

$this->send_data("");





				// Queue the actual message
$this->message = str_replace("\n.", "\n..", $this->message);
$this->send_data($this->message);
}
else

				// Queue the actual message
$this->message = str_replace("\n.", "\n..", $this->message);
$this->send_data($this->message);
}
else

			{

			{

				$this->fatal_error("The mail server did not understand the DATA command");
return false;

				$this->fatal_error("The mail server did not understand the DATA command");
return false;

			}

$this->send_data('.', '250');

			}

$this->send_data('.', 250);


if(!$this->keep_alive)


if(!$this->keep_alive)

			{
$this->close();
}
return true;
}

			{
$this->close();
}
return true;
}

		else
{
return false;

		else
{
return false;

Zeile 288Zeile 274

// DIRECTORY_SEPARATOR checks if running windows
if(function_exists('stream_set_timeout') && DIRECTORY_SEPARATOR != '\\')


// DIRECTORY_SEPARATOR checks if running windows
if(function_exists('stream_set_timeout') && DIRECTORY_SEPARATOR != '\\')

		{

		{

			@stream_set_timeout($this->connection, $this->timeout, 0);
}


			@stream_set_timeout($this->connection, $this->timeout, 0);
}


Zeile 311Zeile 297
				$helo = 'HELO';
}


				$helo = 'HELO';
}


			$data = $this->send_data("{$helo} {$this->helo}", '250');

			$data = $this->send_data("{$helo} {$this->helo}", 250);

			if(!$data)
{
$this->fatal_error("The server did not understand the {$helo} command");

			if(!$data)
{
$this->fatal_error("The server did not understand the {$helo} command");

Zeile 319Zeile 305
			}

if($this->use_tls && preg_match("#250( |-)STARTTLS#mi", $data))

			}

if($this->use_tls && preg_match("#250( |-)STARTTLS#mi", $data))

			{
if(!$this->send_data('STARTTLS', '220'))
{
$this->fatal_error("The server did not understand the STARTTLS command. Reason: ".$this->get_error());
return false;
}

			{
if(!$this->send_data('STARTTLS', 220))
{
$this->fatal_error("The server did not understand the STARTTLS command. Reason: ".$this->get_error());
return false;
}

				if(!@stream_socket_enable_crypto($this->connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
{
$this->fatal_error("Failed to start TLS encryption");
return false;
}
// Resend EHLO to get updated service list

				if(!@stream_socket_enable_crypto($this->connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
{
$this->fatal_error("Failed to start TLS encryption");
return false;
}
// Resend EHLO to get updated service list

				$data = $this->send_data("{$helo} {$this->helo}", '250');

				$data = $this->send_data("{$helo} {$this->helo}", 250);

				if(!$data)
{
$this->fatal_error("The server did not understand the EHLO command");

				if(!$data)
{
$this->fatal_error("The server did not understand the EHLO command");

Zeile 341Zeile 327

if(!empty($this->username) && !empty($this->password))
{


if(!empty($this->username) && !empty($this->password))
{

				preg_match("#250( |-)AUTH( |=)(.+)$#mi", $data, $matches);





				if(!preg_match("#250( |-)AUTH( |=)(.+)$#mi", $data, $matches))
{
$this->fatal_error("The server did not understand the AUTH command");
return false;
}

				if(!$this->auth($matches[3]))
{
return false;

				if(!$this->auth($matches[3]))
{
return false;

Zeile 359Zeile 349
	/**
* Authenticate against the SMTP server.
*

	/**
* Authenticate against the SMTP server.
*

	 * @param string A list of authentication methods supported by the server

	 * @param string $auth_methods A list of authentication methods supported by the server

	 * @return boolean True on success
*/
function auth($auth_methods)

	 * @return boolean True on success
*/
function auth($auth_methods)

Zeile 377Zeile 367
					return true;
}
$this->fatal_error("The SMTP server did not respond correctly to the AUTH LOGIN command");

					return true;
}
$this->fatal_error("The SMTP server did not respond correctly to the AUTH LOGIN command");

				return false;
}

if(!$this->send_data(base64_encode($this->username), '334'))
{

				return false;
}

if(!$this->send_data(base64_encode($this->username), 334))
{

				$this->fatal_error("The SMTP server rejected the supplied SMTP username. Reason: ".$this->get_error());
return false;
}


				$this->fatal_error("The SMTP server rejected the supplied SMTP username. Reason: ".$this->get_error());
return false;
}


			if(!$this->send_data(base64_encode($this->password), '235'))

			if(!$this->send_data(base64_encode($this->password), 235))

			{
$this->fatal_error("The SMTP server rejected the supplied SMTP password. Reason: ".$this->get_error());

			{
$this->fatal_error("The SMTP server rejected the supplied SMTP password. Reason: ".$this->get_error());

				return false;



















				return false;
}
}
else if(in_array("PLAIN", $auth_methods))
{
if(!$this->send_data("AUTH PLAIN", 334))
{
if($this->code == 503)
{
return true;
}
$this->fatal_error("The SMTP server did not respond correctly to the AUTH PLAIN command");
return false;
}
$auth = base64_encode(chr(0).$this->username.chr(0).$this->password);
if(!$this->send_data($auth, 235))
{
$this->fatal_error("The SMTP server rejected the supplied login username and password. Reason: ".$this->get_error());
return false;

			}
}

			}
}

		else if(in_array("PLAIN", $auth_methods))

		else if(in_array("CRAM-MD5", $auth_methods))

		{

		{

			if(!$this->send_data("AUTH PLAIN", '334'))


			$data = $this->send_data("AUTH CRAM-MD5", 334);
if(!$data)

			{
if($this->code == 503)
{
return true;
}

			{
if($this->code == 503)
{
return true;
}

				$this->fatal_error("The SMTP server did not respond correctly to the AUTH PLAIN command");
return false;
}
$auth = base64_encode(chr(0).$this->username.chr(0).$this->password);




				$this->fatal_error("The SMTP server did not respond correctly to the AUTH CRAM-MD5 command");
return false;
}

$challenge = base64_decode(substr($data, 4));
$auth = base64_encode($this->username.' '.$this->cram_md5_response($this->password, $challenge));


			if(!$this->send_data($auth, 235))
{
$this->fatal_error("The SMTP server rejected the supplied login username and password. Reason: ".$this->get_error());

			if(!$this->send_data($auth, 235))
{
$this->fatal_error("The SMTP server rejected the supplied login username and password. Reason: ".$this->get_error());

Zeile 435Zeile 447
			if(substr($line, 3, 1) == ' ')
{
break;

			if(substr($line, 3, 1) == ' ')
{
break;

			}
}

			}
}

		$string = trim($string);
$this->data = $string;
$this->code = substr($this->data, 0, 3);

		$string = trim($string);
$this->data = $string;
$this->code = substr($this->data, 0, 3);

Zeile 460Zeile 472
	/**
* Send data through to the SMTP server.
*

	/**
* Send data through to the SMTP server.
*

	 * @param string The data to be sent
* @param int The response code expected back from the server (if we have one)

	 * @param string $data The data to be sent
* @param int|bool $status_num The response code expected back from the server (if we have one)

	 * @return boolean True on success
*/
function send_data($data, $status_num = false)

	 * @return boolean True on success
*/
function send_data($data, $status_num = false)

Zeile 497Zeile 509
	/**
* Checks if the received status code matches the one we expect.
*

	/**
* Checks if the received status code matches the one we expect.
*

	 * @param int The status code we expected back from the server
* @param boolean True if it matches

	 * @param int $status_num The status code we expected back from the server
* @return string|bool

	 */
function check_status($status_num)
{

	 */
function check_status($status_num)
{

Zeile 543Zeile 555
	/**
* Set the last error message response from the SMTP server
*

	/**
* Set the last error message response from the SMTP server
*

	 * @param string The error message response

	 * @param string $error The error message response

	 */
function set_error($error)
{
$this->last_error = $error;

	 */
function set_error($error)
{
$this->last_error = $error;

 
	}

/**
* Generate a CRAM-MD5 response from a server challenge.
*
* @param string $password Password.
* @param string $challenge Challenge sent from SMTP server.
*
* @return string CRAM-MD5 response.
*/
function cram_md5_response($password, $challenge)
{
if(strlen($password) > 64)
{
$password = pack('H32', md5($password));
}

if(strlen($password) < 64)
{
$password = str_pad($password, 64, chr(0));
}

$k_ipad = substr($password, 0, 64) ^ str_repeat(chr(0x36), 64);
$k_opad = substr($password, 0, 64) ^ str_repeat(chr(0x5C), 64);

$inner = pack('H32', md5($k_ipad.$challenge));

return md5($k_opad.$inner);

	}
}

	}
}