diff --git a/src/Protocol/Imap.php b/src/Protocol/Imap.php index 8e10c621..c3e567a2 100644 --- a/src/Protocol/Imap.php +++ b/src/Protocol/Imap.php @@ -59,10 +59,11 @@ public function __destruct() * @param string $host hostname or IP address of IMAP server * @param int|null $port of IMAP server, default is 143 (993 for ssl) * @param string|bool $ssl use 'SSL', 'TLS' or false + * @param array $ssl_context_options options, passed to stream_context_create() * @throws Exception\RuntimeException * @return string welcome message */ - public function connect($host, $port = null, $ssl = false) + public function connect($host, $port = null, $ssl = false, $ssl_context_options = []) { $isTls = false; @@ -87,7 +88,15 @@ public function connect($host, $port = null, $ssl = false) } ErrorHandler::start(); - $this->socket = fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION); + $context = stream_context_create($ssl_context_options); + $this->socket = stream_socket_client( + $host.':'.$port, + $errno, + $errstr, + self::TIMEOUT_CONNECTION, + STREAM_CLIENT_CONNECT, + $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 cbf8d979..3b8eecbd 100644 --- a/src/Storage/Imap.php +++ b/src/Storage/Imap.php @@ -167,6 +167,7 @@ public function getRawContent($id, $part = null) * - password password for user 'username' [optional, default = ''] * - port port for IMAP server [optional, default = 110] * - ssl 'SSL' or 'TLS' for secure sockets + * - ssl_context_options Options passed to stream_context_create() * - folder select this folder [optional, default = 'INBOX'] * * @param array $params mail reader specific parameters @@ -200,9 +201,10 @@ public function __construct($params) $password = isset($params->password) ? $params->password : ''; $port = isset($params->port) ? $params->port : null; $ssl = isset($params->ssl) ? $params->ssl : false; + $ssl_context_options = isset($params->ssl_context_options) ? $params->ssl_context_options: []; $this->protocol = new Protocol\Imap(); - $this->protocol->connect($host, $port, $ssl); + $this->protocol->connect($host, $port, $ssl, $ssl_context_options); if (!$this->protocol->login($params->user, $password)) { throw new Exception\RuntimeException('cannot login, user or password wrong'); }