Zeile 99 | Zeile 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 120 | Zeile 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 141 | Zeile 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 151 | Zeile 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)) { if(function_exists('gethostname') && gethostname() !== false) { $this->helo = gethostname();
|
$local = array('127.0.0.1', '::1', 'localhost'); if(!in_array($this->host, $local)) { if(function_exists('gethostname') && gethostname() !== false) { $this->helo = gethostname();
|
}
| }
|
elseif(function_exists('php_uname')) { $helo = php_uname('n');
| elseif(function_exists('php_uname')) { $helo = php_uname('n');
|
Zeile 178 | Zeile 164 |
---|
{ $this->helo = $_SERVER['SERVER_NAME']; }
|
{ $this->helo = $_SERVER['SERVER_NAME']; }
|
}
| }
|
$this->host = $protocol . $this->host;
if(empty($mybb->settings['smtp_port']) && !empty($protocol) && !@ini_get('smtp_port')) { $this->port = $this->secure_port;
|
$this->host = $protocol . $this->host;
if(empty($mybb->settings['smtp_port']) && !empty($protocol) && !@ini_get('smtp_port')) { $this->port = $this->secure_port;
|
}
| }
|
else if(empty($mybb->settings['smtp_port']) && @ini_get('smtp_port')) { $this->port = @ini_get('smtp_port');
| else if(empty($mybb->settings['smtp_port']) && @ini_get('smtp_port')) { $this->port = @ini_get('smtp_port');
|
Zeile 211 | Zeile 197 |
---|
if(!$this->connected()) { if(!$this->connect())
|
if(!$this->connected()) { if(!$this->connect())
|
{ $this->close();
| { $this->close();
|
} }
if($this->connected()) {
|
} }
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 229 | Zeile 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 261 | Zeile 247 |
---|
return false; }
|
return false; }
|
$this->send_data('.', '250');
| if(!$this->send_data('.', 250)) { $this->fatal_error("Mail may not be delivered. Reason: ".$this->get_error()); }
|
if(!$this->keep_alive)
|
if(!$this->keep_alive)
|
{ $this->close(); } return true; } else
| { $this->close(); } return true; } else
|
{ return false; }
| { return false; }
|
Zeile 283 | Zeile 272 |
---|
function connect() { global $lang, $mybb;
|
function connect() { global $lang, $mybb;
|
|
|
$this->connection = @fsockopen($this->host, $this->port, $error_number, $error_string, $this->timeout);
// DIRECTORY_SEPARATOR checks if running windows
|
$this->connection = @fsockopen($this->host, $this->port, $error_number, $error_string, $this->timeout);
// DIRECTORY_SEPARATOR checks if running windows
|
if(function_exists('stream_set_timeout') && DIRECTORY_SEPARATOR != '\\')
| if(is_resource($this->connection) && function_exists('stream_set_timeout') && DIRECTORY_SEPARATOR != '\\')
|
{ @stream_set_timeout($this->connection, $this->timeout, 0); }
|
{ @stream_set_timeout($this->connection, $this->timeout, 0); }
|
|
|
if(is_resource($this->connection)) { $this->status = 1; $this->get_data(); if(!$this->check_status('220'))
|
if(is_resource($this->connection)) { $this->status = 1; $this->get_data(); if(!$this->check_status('220'))
|
{
| {
|
$this->fatal_error("The mail server is not ready, it did not respond with a 220 status message."); return false; }
| $this->fatal_error("The mail server is not ready, it did not respond with a 220 status message."); return false; }
|
Zeile 311 | Zeile 300 |
---|
$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 320 | Zeile 309 |
---|
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'))
| if(!$this->send_data('STARTTLS', 220))
|
{
|
{
|
$this->fatal_error("The server did not understand the STARTTLS command. Reason: ".$this->get_error());
| $this->fatal_error("The server did not understand the STARTTLS command. Reason: ".$this->get_error());
|
return false; }
|
return false; }
|
if(!@stream_socket_enable_crypto($this->connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
| $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; // Fix for PHP >=5.6.7 and <7.2 not including TLS 1.1 and 1.2 if(defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) { $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT; }
if(!@stream_socket_enable_crypto($this->connection, true, $crypto_method))
|
{ $this->fatal_error("Failed to start TLS encryption");
|
{ $this->fatal_error("Failed to start TLS encryption");
|
return false; }
| return false; }
|
// Resend EHLO to get updated service list
|
// 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");
|
return false; }
| return false; }
|
}
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 371 | Zeile 373 |
---|
if(in_array("LOGIN", $auth_methods)) { if(!$this->send_data("AUTH LOGIN", 334))
|
if(in_array("LOGIN", $auth_methods)) { if(!$this->send_data("AUTH LOGIN", 334))
|
{
| {
|
if($this->code == 503) { return true;
| if($this->code == 503) { return true;
|
Zeile 380 | Zeile 382 |
---|
return false; }
|
return false; }
|
if(!$this->send_data(base64_encode($this->username), '334'))
| if(!$this->send_data(base64_encode($this->username), 334))
|
{ $this->fatal_error("The SMTP server rejected the supplied SMTP username. Reason: ".$this->get_error());
|
{ $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'))
| return false; }
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)) {
|
} else if(in_array("PLAIN", $auth_methods)) {
|
if(!$this->send_data("AUTH PLAIN", '334'))
| 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("CRAM-MD5", $auth_methods)) { $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");
| $this->fatal_error("The SMTP server did not respond correctly to the AUTH CRAM-MD5 command");
|
return false; }
|
return false; }
|
$auth = base64_encode(chr(0).$this->username.chr(0).$this->password);
| $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 492 | Zeile 516 |
---|
} } return false;
|
} } return false;
|
}
/**
| }
/**
|
* Checks if the received status code matches the one we expect. * * @param int $status_num The status code we expected back from the server * @return string|bool */ function check_status($status_num)
|
* Checks if the received status code matches the one we expect. * * @param int $status_num The status code we expected back from the server * @return string|bool */ function check_status($status_num)
|
{
| {
|
if($this->code == $status_num) { return $this->data;
| if($this->code == $status_num) { return $this->data;
|
Zeile 514 | Zeile 538 |
---|
/** * Close the connection to the SMTP server.
|
/** * Close the connection to the SMTP server.
|
*/
| */
|
function close() { if($this->status == 1)
| function close() { if($this->status == 1)
|
Zeile 548 | Zeile 572 |
---|
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);
|
} }
| } }
|