smtp : push the STARTTLS to none by default, as the certificate of the server must be equal to the configuration.

smtp : Catch the STARTTLS errors instead of displaying a warning
smtp : don't loop etrenaly if there is a smtp problem


git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2722 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-05-23 09:16:58 +00:00
parent c1cbf1435a
commit 8e86bee838

View File

@@ -25,7 +25,7 @@ class smtp
* answer in this time, an exception is raised */
public $timeout = 10;
/** Activate STARTTLS if needed. Allowed values : none, may, encrypt*/
public $starttls = "may";
public $starttls = "none";
/** The authentication methods in an array. Allowed : plain, login*/
public $authmethods = array ("plain", "login");
/** The socket of the connection */
@@ -36,7 +36,8 @@ class smtp
{
if ($this->ssl)
$this->server = "tls://$this->server";
$this->debug ("####SMTP Connection to $this->server:$this->port\n");
$this->debug ("####SMTP Connection to $this->server:$this->port (".
date ("Y/m/d H:i:s").")\n");
$this->smtpStream = @fsockopen ($this->server, $this->port,
$errno, $errstr,
$this->timeout);
@@ -55,8 +56,16 @@ class smtp
if ($this->starttls === "may" || $this->starttls === "encrypt")
{
$this->putLine ("STARTTLS\r\n");
stream_socket_enable_crypto ($this->smtpStream, true,
STREAM_CRYPTO_METHOD_TLS_CLIENT);
// The track_errors permit to create the $php_errormsg in case of
// warning
ini_set('track_errors', 1);
if (@stream_socket_enable_crypto ($this->smtpStream, true,
STREAM_CRYPTO_METHOD_TLS_CLIENT) ===
false)
throw new \Exception (sprintf (_("Can't activate STARTTLS : %s"),
$php_errormsg), 500);
ini_set('track_errors', 0);
$this->debug ("STARTTLS ACTIVATED\n");
}
}
elseif ($this->starttls === "encrypt")
@@ -149,6 +158,8 @@ class smtp
while (1)
{
$line = stream_get_line ($this->smtpStream, 1024, "\r\n");
if ($line === false)
break;
$meta = stream_get_meta_data ($this->smtpStream);
if ($meta["timed_out"] !== FALSE)
{