From 8e86bee8381868dc30afa34291a349e62d4b4d8e Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 23 May 2016 09:16:58 +0000 Subject: [PATCH] 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 --- smtp.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/smtp.php b/smtp.php index fea5465..9757c4d 100644 --- a/smtp.php +++ b/smtp.php @@ -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) {