From 6c721a5b6859fab5ab0b630e91c3af8a0611e64d Mon Sep 17 00:00:00 2001 From: abulhol Date: Fri, 18 Oct 2019 12:41:59 +0200 Subject: [PATCH 01/10] Add option novalidatecert to connect(); closes #63 Signed-off-by: Johan Cwiklinski --- docs/book/read.md | 4 ++++ src/Protocol/Imap.php | 48 ++++++++++++++++++++++++++++++++++++++----- src/Protocol/Pop3.php | 48 ++++++++++++++++++++++++++++++++++++++----- src/Storage/Imap.php | 5 +++++ src/Storage/Pop3.php | 5 +++++ 5 files changed, 100 insertions(+), 10 deletions(-) diff --git a/docs/book/read.md b/docs/book/read.md index 2619cd1c..4b94e9f6 100644 --- a/docs/book/read.md +++ b/docs/book/read.md @@ -117,6 +117,10 @@ $mail = new Pop3([ ]); ``` +If you are connecting to a mail server with a self-signed certificate and want to +skip the SSL verification, you can also pass an additional argument `novalidatecert` +with the value `true`. + Both constructors throw `Laminas\Mail\Exception` or `Laminas\Mail\Protocol\Exception` (extends `Laminas\Mail\Exception`) for connection errors, depending on the type of error encountered. diff --git a/src/Protocol/Imap.php b/src/Protocol/Imap.php index eb2515c4..227d9356 100644 --- a/src/Protocol/Imap.php +++ b/src/Protocol/Imap.php @@ -19,6 +19,12 @@ class Imap */ const TIMEOUT_CONNECTION = 30; + /** + * If set to true, do not validate the SSL certificate + * @var null|bool + */ + protected $novalidatecert; + /** * socket to imap server * @var resource|null @@ -34,13 +40,16 @@ class Imap /** * Public constructor * - * @param string $host hostname or IP address of IMAP server, if given connect() is called - * @param int|null $port port of IMAP server, null for default (143 or 993 for ssl) - * @param bool $ssl use ssl? 'SSL', 'TLS' or false + * @param string $host hostname or IP address of IMAP server, if given connect() is called + * @param int|null $port port of IMAP server, null for default (143 or 993 for ssl) + * @param bool $ssl use ssl? 'SSL', 'TLS' or false + * @param bool $novalidatecert set to true to skip SSL certificate validation * @throws \Laminas\Mail\Protocol\Exception\ExceptionInterface */ - public function __construct($host = '', $port = null, $ssl = false) + public function __construct($host = '', $port = null, $ssl = false, $novalidatecert = false) { + $this->novalidatecert = $novalidatecert; + if ($host) { $this->connect($host, $port, $ssl); } @@ -54,6 +63,14 @@ public function __destruct() $this->logout(); } + public function setNoValidateCert($novalidatecert) + { + + if (is_bool($novalidatecert)) { + $this->novalidatecert = $novalidatecert; + } + } + /** * Open connection to IMAP server * @@ -87,8 +104,29 @@ public function connect($host, $port = null, $ssl = false) } } + $socket_options = []; + + if ($this->novalidatecert) { + $socket_options = [ + 'ssl' => [ + 'verify_peer_name' => false, + 'verify_peer' => false, + ] + ]; + } + + $socket_context = stream_context_create($socket_options); + ErrorHandler::start(); - $this->socket = fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION); + $this->socket = stream_socket_client( + $host . ":" . $port, + $errno, + $errstr, + self::TIMEOUT_CONNECTION, + STREAM_CLIENT_CONNECT, + $socket_context + ); + $error = ErrorHandler::stop(); if (! $this->socket) { throw new Exception\RuntimeException(sprintf( diff --git a/src/Protocol/Pop3.php b/src/Protocol/Pop3.php index 342644bc..8f07fd37 100644 --- a/src/Protocol/Pop3.php +++ b/src/Protocol/Pop3.php @@ -25,6 +25,12 @@ class Pop3 */ public $hasTop = null; + /** + * If set to true, do not validate the SSL certificate + * @var null|bool + */ + protected $novalidatecert; + /** * socket to pop3 * @var null|resource @@ -40,12 +46,15 @@ class Pop3 /** * Public constructor * - * @param string $host hostname or IP address of POP3 server, if given connect() is called - * @param int|null $port port of POP3 server, null for default (110 or 995 for ssl) - * @param bool|string $ssl use ssl? 'SSL', 'TLS' or false + * @param string $host hostname or IP address of POP3 server, if given connect() is called + * @param int|null $port port of POP3 server, null for default (110 or 995 for ssl) + * @param bool|string $ssl use ssl? 'SSL', 'TLS' or false + * @param bool $novalidatecert set to true to skip SSL certificate validation */ - public function __construct($host = '', $port = null, $ssl = false) + public function __construct($host = '', $port = null, $ssl = false, $novalidatecert = false) { + $this->novalidatecert = $novalidatecert; + if ($host) { $this->connect($host, $port, $ssl); } @@ -59,6 +68,14 @@ public function __destruct() $this->logout(); } + public function setNoValidateCert($novalidatecert) + { + + if (is_bool($novalidatecert)) { + $this->novalidatecert = $novalidatecert; + } + } + /** * Open connection to POP3 server * @@ -92,8 +109,29 @@ public function connect($host, $port = null, $ssl = false) } } + $socket_options = []; + + if ($this->novalidatecert) { + $socket_options = [ + 'ssl' => [ + 'verify_peer_name' => false, + 'verify_peer' => false, + ] + ]; + } + + $socket_context = stream_context_create($socket_options); + ErrorHandler::start(); - $this->socket = fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION); + $this->socket = stream_socket_client( + $host . ":" . $port, + $errno, + $errstr, + self::TIMEOUT_CONNECTION, + STREAM_CLIENT_CONNECT, + $socket_context + ); + $error = ErrorHandler::stop(); if (! $this->socket) { throw new Exception\RuntimeException(sprintf( diff --git a/src/Storage/Imap.php b/src/Storage/Imap.php index 029e950e..b842f9c5 100644 --- a/src/Storage/Imap.php +++ b/src/Storage/Imap.php @@ -213,6 +213,11 @@ public function __construct($params) $ssl = isset($params->ssl) ? $params->ssl : false; $this->protocol = new Protocol\Imap(); + + if (isset($params->novalidatecert)) { + $this->protocol->setNoValidateCert(true); + } + $this->protocol->connect($host, $port, $ssl); if (! $this->protocol->login($params->user, $password)) { throw new Exception\RuntimeException('cannot login, user or password wrong'); diff --git a/src/Storage/Pop3.php b/src/Storage/Pop3.php index 7e799ae9..4e51836d 100644 --- a/src/Storage/Pop3.php +++ b/src/Storage/Pop3.php @@ -146,6 +146,11 @@ public function __construct($params) $ssl = isset($params->ssl) ? $params->ssl : false; $this->protocol = new Protocol\Pop3(); + + if (isset($params->novalidatecert)) { + $this->protocol->setNoValidateCert($params->novalidatecert); + } + $this->protocol->connect($host, $port, $ssl); $this->protocol->login($params->user, $password); } From 911fbeff87aa162eb1baca7b0474482b596f0d63 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 10 Jul 2020 14:18:43 +0200 Subject: [PATCH 02/10] Move common code to existing trait, add getter Signed-off-by: Johan Cwiklinski --- src/Protocol/Imap.php | 26 ++++++-------------------- src/Protocol/Pop3.php | 26 ++++++-------------------- src/Protocol/ProtocolTrait.php | 29 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/Protocol/Imap.php b/src/Protocol/Imap.php index 227d9356..381eefc3 100644 --- a/src/Protocol/Imap.php +++ b/src/Protocol/Imap.php @@ -19,12 +19,6 @@ class Imap */ const TIMEOUT_CONNECTION = 30; - /** - * If set to true, do not validate the SSL certificate - * @var null|bool - */ - protected $novalidatecert; - /** * socket to imap server * @var resource|null @@ -40,15 +34,15 @@ class Imap /** * Public constructor * - * @param string $host hostname or IP address of IMAP server, if given connect() is called - * @param int|null $port port of IMAP server, null for default (143 or 993 for ssl) - * @param bool $ssl use ssl? 'SSL', 'TLS' or false - * @param bool $novalidatecert set to true to skip SSL certificate validation + * @param string $host hostname or IP address of IMAP server, if given connect() is called + * @param int|null $port port of IMAP server, null for default (143 or 993 for ssl) + * @param bool $ssl use ssl? 'SSL', 'TLS' or false + * @param bool $novalidatecert set to true to skip SSL certificate validation * @throws \Laminas\Mail\Protocol\Exception\ExceptionInterface */ public function __construct($host = '', $port = null, $ssl = false, $novalidatecert = false) { - $this->novalidatecert = $novalidatecert; + $this->setNoValidateCert($novalidatecert); if ($host) { $this->connect($host, $port, $ssl); @@ -63,14 +57,6 @@ public function __destruct() $this->logout(); } - public function setNoValidateCert($novalidatecert) - { - - if (is_bool($novalidatecert)) { - $this->novalidatecert = $novalidatecert; - } - } - /** * Open connection to IMAP server * @@ -106,7 +92,7 @@ public function connect($host, $port = null, $ssl = false) $socket_options = []; - if ($this->novalidatecert) { + if (!$this->validateCert()) { $socket_options = [ 'ssl' => [ 'verify_peer_name' => false, diff --git a/src/Protocol/Pop3.php b/src/Protocol/Pop3.php index 8f07fd37..2d3f9dc4 100644 --- a/src/Protocol/Pop3.php +++ b/src/Protocol/Pop3.php @@ -25,12 +25,6 @@ class Pop3 */ public $hasTop = null; - /** - * If set to true, do not validate the SSL certificate - * @var null|bool - */ - protected $novalidatecert; - /** * socket to pop3 * @var null|resource @@ -46,14 +40,14 @@ class Pop3 /** * Public constructor * - * @param string $host hostname or IP address of POP3 server, if given connect() is called - * @param int|null $port port of POP3 server, null for default (110 or 995 for ssl) - * @param bool|string $ssl use ssl? 'SSL', 'TLS' or false - * @param bool $novalidatecert set to true to skip SSL certificate validation + * @param string $host hostname or IP address of POP3 server, if given connect() is called + * @param int|null $port port of POP3 server, null for default (110 or 995 for ssl) + * @param bool|string $ssl use ssl? 'SSL', 'TLS' or false + * @param bool $novalidatecert set to true to skip SSL certificate validation */ public function __construct($host = '', $port = null, $ssl = false, $novalidatecert = false) { - $this->novalidatecert = $novalidatecert; + $this->setNoValidateCert($novalidatecert); if ($host) { $this->connect($host, $port, $ssl); @@ -68,14 +62,6 @@ public function __destruct() $this->logout(); } - public function setNoValidateCert($novalidatecert) - { - - if (is_bool($novalidatecert)) { - $this->novalidatecert = $novalidatecert; - } - } - /** * Open connection to POP3 server * @@ -111,7 +97,7 @@ public function connect($host, $port = null, $ssl = false) $socket_options = []; - if ($this->novalidatecert) { + if (!$this->validateCert()) { $socket_options = [ 'ssl' => [ 'verify_peer_name' => false, diff --git a/src/Protocol/ProtocolTrait.php b/src/Protocol/ProtocolTrait.php index 17655f02..e789257e 100644 --- a/src/Protocol/ProtocolTrait.php +++ b/src/Protocol/ProtocolTrait.php @@ -13,6 +13,12 @@ */ trait ProtocolTrait { + /** + * If set to true, do not validate the SSL certificate + * @var null|bool + */ + protected $novalidatecert; + public function getCryptoMethod() { // Allow the best TLS version(s) we can @@ -27,4 +33,27 @@ public function getCryptoMethod() return $cryptoMethod; } + + /** + * Do not validate SSL certificate + * + * @param bool $novalidatecert Set to true to disable certificate validation + * + * @return Imap + */ + public function setNoValidateCert(bool $novalidatecert) + { + $this->novalidatecert = $novalidatecert; + return $this; + } + + /** + * Should we validate SSL certificate? + * + * @return bool + */ + public function validateCert() + { + return !$this->novalidatecert; + } } From cd9192b3d35aa8cd842bb1cfb2f6e3ecd4af404e Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Wed, 15 Jul 2020 13:15:11 +0200 Subject: [PATCH 03/10] Factorize socket creation code, use camelCase for variables Signed-off-by: Johan Cwiklinski --- src/Protocol/Imap.php | 37 +------------------------ src/Protocol/Pop3.php | 37 +------------------------ src/Protocol/ProtocolTrait.php | 50 +++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 73 deletions(-) diff --git a/src/Protocol/Imap.php b/src/Protocol/Imap.php index 381eefc3..51ea5d5d 100644 --- a/src/Protocol/Imap.php +++ b/src/Protocol/Imap.php @@ -19,12 +19,6 @@ class Imap */ const TIMEOUT_CONNECTION = 30; - /** - * socket to imap server - * @var resource|null - */ - protected $socket; - /** * counter for request tag * @var int @@ -90,36 +84,7 @@ public function connect($host, $port = null, $ssl = false) } } - $socket_options = []; - - if (!$this->validateCert()) { - $socket_options = [ - 'ssl' => [ - 'verify_peer_name' => false, - 'verify_peer' => false, - ] - ]; - } - - $socket_context = stream_context_create($socket_options); - - ErrorHandler::start(); - $this->socket = stream_socket_client( - $host . ":" . $port, - $errno, - $errstr, - self::TIMEOUT_CONNECTION, - STREAM_CLIENT_CONNECT, - $socket_context - ); - - $error = ErrorHandler::stop(); - if (! $this->socket) { - throw new Exception\RuntimeException(sprintf( - 'cannot connect to host %s', - ($error ? sprintf('; error = %s (errno = %d )', $error->getMessage(), $error->getCode()) : '') - ), 0, $error); - } + $this->setSocket($host, $port); if (! $this->assumedNextLine('* OK')) { throw new Exception\RuntimeException('host doesn\'t allow connection'); diff --git a/src/Protocol/Pop3.php b/src/Protocol/Pop3.php index 2d3f9dc4..1e0ff9f5 100644 --- a/src/Protocol/Pop3.php +++ b/src/Protocol/Pop3.php @@ -25,12 +25,6 @@ class Pop3 */ public $hasTop = null; - /** - * socket to pop3 - * @var null|resource - */ - protected $socket; - /** * greeting timestamp for apop * @var null|string @@ -95,36 +89,7 @@ public function connect($host, $port = null, $ssl = false) } } - $socket_options = []; - - if (!$this->validateCert()) { - $socket_options = [ - 'ssl' => [ - 'verify_peer_name' => false, - 'verify_peer' => false, - ] - ]; - } - - $socket_context = stream_context_create($socket_options); - - ErrorHandler::start(); - $this->socket = stream_socket_client( - $host . ":" . $port, - $errno, - $errstr, - self::TIMEOUT_CONNECTION, - STREAM_CLIENT_CONNECT, - $socket_context - ); - - $error = ErrorHandler::stop(); - if (! $this->socket) { - throw new Exception\RuntimeException(sprintf( - 'cannot connect to host %s', - ($error ? sprintf('; error = %s (errno = %d )', $error->getMessage(), $error->getCode()) : '') - ), 0, $error); - } + $this->setSocket($host, $port); $welcome = $this->readResponse(); diff --git a/src/Protocol/ProtocolTrait.php b/src/Protocol/ProtocolTrait.php index e789257e..4521058c 100644 --- a/src/Protocol/ProtocolTrait.php +++ b/src/Protocol/ProtocolTrait.php @@ -13,6 +13,12 @@ */ trait ProtocolTrait { + /** + * socket to mail server + * @var resource|null + */ + protected $socket; + /** * If set to true, do not validate the SSL certificate * @var null|bool @@ -39,7 +45,7 @@ public function getCryptoMethod() * * @param bool $novalidatecert Set to true to disable certificate validation * - * @return Imap + * @return Imap|Pop3 */ public function setNoValidateCert(bool $novalidatecert) { @@ -56,4 +62,46 @@ public function validateCert() { return !$this->novalidatecert; } + + /** + * Setup connection socket + * + * @param string $host hostname or IP address of IMAP server + * @param int|null $port of IMAP server, default is 143 (993 for ssl) + * + * @return void + */ + protected function setSocket($host, $port) + { + $socketOptions = []; + + if (!$this->validateCert()) { + $socketOptions = [ + 'ssl' => [ + 'verify_peer_name' => false, + 'verify_peer' => false, + ] + ]; + } + + $socketContext = stream_context_create($socketOptions); + + ErrorHandler::start(); + $this->socket = stream_socket_client( + $host . ":" . $port, + $errno, + $errstr, + self::TIMEOUT_CONNECTION, + STREAM_CLIENT_CONNECT, + $socketContext + ); + + $error = ErrorHandler::stop(); + if (! $this->socket) { + throw new Exception\RuntimeException(sprintf( + 'cannot connect to host %s', + ($error ? sprintf('; error = %s (errno = %d )', $error->getMessage(), $error->getCode()) : '') + ), 0, $error); + } + } } From 6b2d0c3bef77dbad686a03d419151b89986bd41a Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Wed, 15 Jul 2020 13:21:45 +0200 Subject: [PATCH 04/10] Prepare options in distinct method Signed-off-by: Johan Cwiklinski --- src/Protocol/ProtocolTrait.php | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Protocol/ProtocolTrait.php b/src/Protocol/ProtocolTrait.php index 4521058c..cc4fe678 100644 --- a/src/Protocol/ProtocolTrait.php +++ b/src/Protocol/ProtocolTrait.php @@ -63,6 +63,22 @@ public function validateCert() return !$this->novalidatecert; } + /** + * Prepare socket options + * + * @return array + */ + protected function prepareSocketOptions() + { + return $this->novalidatecert + ? [ + 'ssl' => [ + 'verify_peer_name' => false, + 'verify_peer' => false, + ] + ] : []; + } + /** * Setup connection socket * @@ -75,17 +91,6 @@ protected function setSocket($host, $port) { $socketOptions = []; - if (!$this->validateCert()) { - $socketOptions = [ - 'ssl' => [ - 'verify_peer_name' => false, - 'verify_peer' => false, - ] - ]; - } - - $socketContext = stream_context_create($socketOptions); - ErrorHandler::start(); $this->socket = stream_socket_client( $host . ":" . $port, @@ -93,7 +98,7 @@ protected function setSocket($host, $port) $errstr, self::TIMEOUT_CONNECTION, STREAM_CLIENT_CONNECT, - $socketContext + stream_context_create($this->prepareSocketOptions()) ); $error = ErrorHandler::stop(); From cda35c8e652f0590836f83c4003bb22b0da0efec Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Wed, 15 Jul 2020 14:17:18 +0200 Subject: [PATCH 05/10] Remove socket variable duplicate declaration in trait Signed-off-by: Johan Cwiklinski --- src/Protocol/ProtocolTrait.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Protocol/ProtocolTrait.php b/src/Protocol/ProtocolTrait.php index cc4fe678..17da5018 100644 --- a/src/Protocol/ProtocolTrait.php +++ b/src/Protocol/ProtocolTrait.php @@ -13,12 +13,6 @@ */ trait ProtocolTrait { - /** - * socket to mail server - * @var resource|null - */ - protected $socket; - /** * If set to true, do not validate the SSL certificate * @var null|bool From b18f9972e96a318c53e9d8034da9929a5a54b8a5 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Wed, 15 Jul 2020 14:55:46 +0200 Subject: [PATCH 06/10] Fix CS Signed-off-by: Johan Cwiklinski --- src/Protocol/ProtocolTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ProtocolTrait.php b/src/Protocol/ProtocolTrait.php index 17da5018..e9dc6dd4 100644 --- a/src/Protocol/ProtocolTrait.php +++ b/src/Protocol/ProtocolTrait.php @@ -54,7 +54,7 @@ public function setNoValidateCert(bool $novalidatecert) */ public function validateCert() { - return !$this->novalidatecert; + return ! $this->novalidatecert; } /** From e66d07246c9d7cdf9e82141d2bd26f52fa1a39ec Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Thu, 16 Jul 2020 07:16:37 +0200 Subject: [PATCH 07/10] Unconsistent param usage between imap and pop, and cast it Signed-off-by: Johan Cwiklinski --- src/Protocol/ProtocolTrait.php | 2 +- src/Storage/Imap.php | 2 +- src/Storage/Pop3.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ProtocolTrait.php b/src/Protocol/ProtocolTrait.php index e9dc6dd4..019707a5 100644 --- a/src/Protocol/ProtocolTrait.php +++ b/src/Protocol/ProtocolTrait.php @@ -94,8 +94,8 @@ protected function setSocket($host, $port) STREAM_CLIENT_CONNECT, stream_context_create($this->prepareSocketOptions()) ); - $error = ErrorHandler::stop(); + if (! $this->socket) { throw new Exception\RuntimeException(sprintf( 'cannot connect to host %s', diff --git a/src/Storage/Imap.php b/src/Storage/Imap.php index b842f9c5..e4acf9e1 100644 --- a/src/Storage/Imap.php +++ b/src/Storage/Imap.php @@ -215,7 +215,7 @@ public function __construct($params) $this->protocol = new Protocol\Imap(); if (isset($params->novalidatecert)) { - $this->protocol->setNoValidateCert(true); + $this->protocol->setNoValidateCert((bool)$params->novalidatecert); } $this->protocol->connect($host, $port, $ssl); diff --git a/src/Storage/Pop3.php b/src/Storage/Pop3.php index 4e51836d..3549763a 100644 --- a/src/Storage/Pop3.php +++ b/src/Storage/Pop3.php @@ -148,7 +148,7 @@ public function __construct($params) $this->protocol = new Protocol\Pop3(); if (isset($params->novalidatecert)) { - $this->protocol->setNoValidateCert($params->novalidatecert); + $this->protocol->setNoValidateCert((bool)$params->novalidatecert); } $this->protocol->connect($host, $port, $ssl); From 514fb7ef173ee714004117f7e161e10a7467a5bf Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Thu, 16 Jul 2020 08:02:51 +0200 Subject: [PATCH 08/10] Change visibility Signed-off-by: Johan Cwiklinski --- src/Protocol/ProtocolTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ProtocolTrait.php b/src/Protocol/ProtocolTrait.php index 019707a5..5ccc9842 100644 --- a/src/Protocol/ProtocolTrait.php +++ b/src/Protocol/ProtocolTrait.php @@ -62,7 +62,7 @@ public function validateCert() * * @return array */ - protected function prepareSocketOptions() + private function prepareSocketOptions() { return $this->novalidatecert ? [ From 35a9b5c8955771641d49386ee853508126feb569 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Thu, 16 Jul 2020 08:08:39 +0200 Subject: [PATCH 09/10] Add basic test Signed-off-by: Johan Cwiklinski --- test/Storage/ImapTest.php | 11 +++++++++++ test/Storage/Pop3Test.php | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/test/Storage/ImapTest.php b/test/Storage/ImapTest.php index 1ff15df0..84b519ef 100644 --- a/test/Storage/ImapTest.php +++ b/test/Storage/ImapTest.php @@ -130,6 +130,17 @@ public function testConnectTLS() new Storage\Imap($this->params); } + public function testConnectSelfSignedSSL() + { + if (! getenv('TESTS_LAMINAS_MAIL_IMAP_SSL')) { + return; + } + + $this->params['ssl'] = 'SSL'; + $this->params['novalidatecert'] = true; + new Storage\Imap($this->params); + } + public function testInvalidService() { $this->params['port'] = getenv('TESTS_LAMINAS_MAIL_IMAP_INVALID_PORT'); diff --git a/test/Storage/Pop3Test.php b/test/Storage/Pop3Test.php index d50ffd09..07e75075 100644 --- a/test/Storage/Pop3Test.php +++ b/test/Storage/Pop3Test.php @@ -138,6 +138,18 @@ public function testConnectTLS() new Storage\Pop3($this->params); } + public function testConnectSelfSignedSSL() + { + if (! getenv('TESTS_LAMINAS_MAIL_POP3_SSL')) { + return; + } + + $this->params['ssl'] = 'SSL'; + $this->params['novalidatecert'] = true; + + new Storage\Pop3($this->params); + } + public function testInvalidService() { $this->params['port'] = getenv('TESTS_LAMINAS_MAIL_POP3_INVALID_PORT'); From 8047d0251441d1de6653b8efdba11ae417ba18eb Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Thu, 16 Jul 2020 11:11:49 +0200 Subject: [PATCH 10/10] Change method name, clean dead code Signed-off-by: Johan Cwiklinski --- src/Protocol/Imap.php | 2 +- src/Protocol/Pop3.php | 2 +- src/Protocol/ProtocolTrait.php | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Protocol/Imap.php b/src/Protocol/Imap.php index 51ea5d5d..6bbbc117 100644 --- a/src/Protocol/Imap.php +++ b/src/Protocol/Imap.php @@ -84,7 +84,7 @@ public function connect($host, $port = null, $ssl = false) } } - $this->setSocket($host, $port); + $this->setupSocket($host, $port); if (! $this->assumedNextLine('* OK')) { throw new Exception\RuntimeException('host doesn\'t allow connection'); diff --git a/src/Protocol/Pop3.php b/src/Protocol/Pop3.php index 1e0ff9f5..8d31dc7d 100644 --- a/src/Protocol/Pop3.php +++ b/src/Protocol/Pop3.php @@ -89,7 +89,7 @@ public function connect($host, $port = null, $ssl = false) } } - $this->setSocket($host, $port); + $this->setupSocket($host, $port); $welcome = $this->readResponse(); diff --git a/src/Protocol/ProtocolTrait.php b/src/Protocol/ProtocolTrait.php index 5ccc9842..0e0faccb 100644 --- a/src/Protocol/ProtocolTrait.php +++ b/src/Protocol/ProtocolTrait.php @@ -81,10 +81,8 @@ private function prepareSocketOptions() * * @return void */ - protected function setSocket($host, $port) + protected function setupSocket($host, $port) { - $socketOptions = []; - ErrorHandler::start(); $this->socket = stream_socket_client( $host . ":" . $port,