From d7b0e412712a680ec15588909c5c7c5e3e1e9438 Mon Sep 17 00:00:00 2001 From: jtisseau Date: Wed, 16 Mar 2016 01:54:45 +0100 Subject: [PATCH] Added the STARTTLS connection mode Adds the STARTTLS connection mode in function _server_authenticate. It's use by Microsoft Hotmail and Exchange servers. I use the MAIN_MAIL_EMAIL_STARTTLS const introduced in admins/mails.php retrieved from the $conf object which is not used anywhere else in the file so it may not be the right way to do it. Maybe this value should be passed in constructor but it would then imply more changes around multiple files calling smtps class. --- htdocs/core/class/smtps.class.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/htdocs/core/class/smtps.class.php b/htdocs/core/class/smtps.class.php index cfefa223a7d..93ffb57930e 100644 --- a/htdocs/core/class/smtps.class.php +++ b/htdocs/core/class/smtps.class.php @@ -3,6 +3,7 @@ * Copyright (C) Walter Torres [with a *lot* of help!] * Copyright (C) 2005-2015 Laurent Destailleur * Copyright (C) 2006-2011 Regis Houssin + * Copyright (C) 2016 Jonathan TISSEAU * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -387,6 +388,8 @@ class SMTPs */ function _server_authenticate() { + global $conf; + // Send the RFC2554 specified EHLO. // This improvment as provided by 'SirSir' to // accomodate both SMTP AND ESMTP capable servers @@ -395,6 +398,24 @@ class SMTPs $host=preg_replace('@ssl://@i','',$host); // Remove prefix if ( $_retVal = $this->socket_send_str('EHLO ' . $host, '250') ) { + if (!empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS)) + { + if (!$_retVal = $this->socket_send_str('STARTTLS', 220)) + { + $this->_setErr(131, 'STARTTLS connection is not supported.'); + return $_retVal; + } + if (!stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) + { + $this->_setErr(132, 'STARTTLS connection failed.'); + return $_retVal; + } + if (!$_retVal = $this->socket_send_str('EHLO '.$host, '250')) + { + $this->_setErr(126, '"' . $host . '" does not support authenticated connections.'); + return $_retVal; + } + } // Send Authentication to Server // Check for errors along the way $this->socket_send_str('AUTH LOGIN', '334');