diff --git a/src/Protocol/Imap/ClientFactory.php b/src/Protocol/Imap/ClientFactory.php index c33b2b94..e694124e 100644 --- a/src/Protocol/Imap/ClientFactory.php +++ b/src/Protocol/Imap/ClientFactory.php @@ -174,9 +174,10 @@ public function newClient(): Client /** * @param string $dataSourceName + * @param array> $contextOptions * @return ClientFactory */ - public static function fromString(string $dataSourceName):ClientFactory + public static function fromString(string $dataSourceName, array $contextOptions = []):ClientFactory { $components = \parse_url($dataSourceName); if ($components === false || !isset($components['scheme'], $components['host'])) { @@ -190,11 +191,15 @@ public static function fromString(string $dataSourceName):ClientFactory } $insecureConnectionAllowed = false; + $startTls = true; + switch ($components['scheme']) { case 'imap': $connection = new PlainTcpConnection( $components['host'], - $components['port'] ?? 143 + $components['port'] ?? 143, + 1.0, + $contextOptions ); break; case 'imaps': @@ -202,15 +207,32 @@ public static function fromString(string $dataSourceName):ClientFactory $components['host'], $components['port'] ?? 993, new SecureConnectionOptions( - (int)($query['crypto'] ?? CryptoConstant::getDefaultMethod(PHP_VERSION)) + (int)($query['crypto'] ?? CryptoConstant::getDefaultMethod(PHP_VERSION)), + 10, + $contextOptions ) ); break; case 'imap-starttls': $insecureConnectionAllowed = true; + $startTls = false; + + $connection = new PlainTcpConnection( + $components['host'], + $components['port'] ?? 143, + 1.0, + $contextOptions + ); + break; + case 'imap+starttls': + $insecureConnectionAllowed = true; + $startTls = true; + $connection = new PlainTcpConnection( $components['host'], - $components['port'] ?? 143 + $components['port'] ?? 143, + 1.0, + $contextOptions ); break; default: @@ -237,7 +259,9 @@ public static function fromString(string $dataSourceName):ClientFactory $factory->reconnectAfter = $query['reconnectAfter']; } - if (isset($query['crypto'])) { + if (!$startTls) { + $factory->startTls = 0; + } elseif (isset($query['crypto'])) { $factory->startTls = (int)$query['crypto']; } diff --git a/src/Protocol/Smtp/ClientFactory.php b/src/Protocol/Smtp/ClientFactory.php index 8dd00270..0908fb95 100644 --- a/src/Protocol/Smtp/ClientFactory.php +++ b/src/Protocol/Smtp/ClientFactory.php @@ -189,9 +189,10 @@ public function newClient(): Client /** * @param string $dataSourceName + * @param array> $contextOptions * @return ClientFactory */ - public static function fromString(string $dataSourceName):ClientFactory + public static function fromString(string $dataSourceName, array $contextOptions = []):ClientFactory { $components = \parse_url($dataSourceName); if ($components === false || !isset($components['scheme']) || !isset($components['host'])) { @@ -210,7 +211,9 @@ public static function fromString(string $dataSourceName):ClientFactory case 'smtp': $connection = new PlainTcpConnection( $components['host'], - $components['port'] ?? 587 + $components['port'] ?? 587, + 1.0, + $contextOptions ); break; case 'smtps': @@ -218,7 +221,9 @@ public static function fromString(string $dataSourceName):ClientFactory $components['host'], $components['port'] ?? 465, new SecureConnectionOptions( - (int)($query['crypto'] ?? CryptoConstant::getDefaultMethod(PHP_VERSION)) + (int)($query['crypto'] ?? CryptoConstant::getDefaultMethod(PHP_VERSION)), + 10, + $contextOptions ) ); break; @@ -228,7 +233,9 @@ public static function fromString(string $dataSourceName):ClientFactory $connection = new PlainTcpConnection( $components['host'], - $components['port'] ?? 25 + $components['port'] ?? 25, + 1.0, + $contextOptions ); break; case 'smtp+starttls': @@ -237,7 +244,9 @@ public static function fromString(string $dataSourceName):ClientFactory $connection = new PlainTcpConnection( $components['host'], - $components['port'] ?? 25 + $components['port'] ?? 25, + 1.0, + $contextOptions ); break; default: