From 72c250ca6765b97f9ec58f81845e4a41d3716dc4 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Sun, 10 Jan 2016 05:59:07 -0500 Subject: [PATCH] Merge pull request #317 from FrancisRussell/imap-tls --- program/lib/Roundcube/rcube_imap_generic.php | 45 +++++++++++++++++++++++++++++---------------- 1 files changed, 29 insertions(+), 16 deletions(-) diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php index 3ec2167..1442eca 100644 --- a/program/lib/Roundcube/rcube_imap_generic.php +++ b/program/lib/Roundcube/rcube_imap_generic.php @@ -85,7 +85,7 @@ * * @param int Number of bytes sent, False on error */ - function putLine($string, $endln = true, $anonymized = false) + protected function putLine($string, $endln = true, $anonymized = false) { if (!$this->fp) { return false; @@ -127,7 +127,7 @@ * * @return int|bool Number of bytes sent, False on error */ - function putLineC($string, $endln=true, $anonymized=false) + protected function putLineC($string, $endln=true, $anonymized=false) { if (!$this->fp) { return false; @@ -184,7 +184,7 @@ * * @return string Line of text response */ - function readLine($size = 1024) + protected function readLine($size = 1024) { $line = ''; @@ -194,7 +194,7 @@ do { if ($this->eof()) { - return $line ? $line : null; + return $line ?: null; } $buffer = fgets($this->fp, $size); @@ -209,7 +209,8 @@ } $line .= $buffer; - } while (substr($buffer, -1) != "\n"); + } + while (substr($buffer, -1) != "\n"); return $line; } @@ -223,7 +224,7 @@ * * @return string Line of text response */ - function multLine($line, $escape = false) + protected function multLine($line, $escape = false) { $line = rtrim($line); if (preg_match('/\{([0-9]+)\}$/', $line, $m)) { @@ -253,7 +254,7 @@ * * @return string Response text */ - function readBytes($bytes) + protected function readBytes($bytes) { $data = ''; $len = 0; @@ -281,7 +282,7 @@ * * @return string Response text */ - function readReply(&$untagged = null) + protected function readReply(&$untagged = null) { do { $line = trim($this->readLine(1024)); @@ -289,7 +290,8 @@ if ($line[0] == '*') { $untagged[] = $line; } - } while ($line[0] == '*'); + } + while ($line[0] == '*'); if ($untagged) { $untagged = join("\n", $untagged); @@ -306,7 +308,7 @@ * * @return int Response status */ - function parseResult($string, $err_prefix = '') + protected function parseResult($string, $err_prefix = '') { if (preg_match('/^[a-z0-9*]+ (OK|NO|BAD|BYE)(.*)$/i', trim($string), $matches)) { $res = strtoupper($matches[1]); @@ -460,7 +462,7 @@ } } - return !empty($result) ? $result : false; + return $result ?: false; } /** @@ -995,7 +997,18 @@ return false; } - if (!stream_socket_enable_crypto($this->fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { + if (isset($this->prefs['socket_options']['ssl']['crypto_method'])) { + $crypto_method = $this->prefs['socket_options']['ssl']['crypto_method']; + } + else { + // There is no flag to enable all TLS methods. Net_SMTP + // handles enabling TLS similarly. + $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT + | @STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT + | @STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; + } + + if (!stream_socket_enable_crypto($this->fp, true, $crypto_method)) { $this->setError(self::ERROR_BAD, "Unable to negotiate TLS"); $this->closeConnection(); return false; @@ -1185,7 +1198,7 @@ list($code, $response) = $this->execute('STATUS', array($this->escape($mailbox), '(' . implode(' ', (array) $items) . ')')); - if ($code == self::ERROR_OK && preg_match('/\* STATUS /i', $response)) { + if ($code == self::ERROR_OK && preg_match('/^\* STATUS /i', $response)) { $result = array(); $response = substr($response, 9); // remove prefix "* STATUS " @@ -1652,7 +1665,7 @@ !empty($args) ? '(' . implode(' ', (array) $args) . ')' : $this->escape(null) )); - if ($code == self::ERROR_OK && preg_match('/\* ID /i', $response)) { + if ($code == self::ERROR_OK && preg_match('/^\* ID /i', $response)) { $response = substr($response, 5); // remove prefix "* ID " $items = $this->tokenizeResponse($response, 1); $result = null; @@ -1705,7 +1718,7 @@ list($code, $response) = $this->execute('ENABLE', $extension); - if ($code == self::ERROR_OK && preg_match('/\* ENABLED /i', $response)) { + if ($code == self::ERROR_OK && preg_match('/^\* ENABLED /i', $response)) { $response = substr($response, 10); // remove prefix "* ENABLED " $result = (array) $this->tokenizeResponse($response); @@ -2681,7 +2694,7 @@ while (preg_match('/^BODY\[([0-9\.]+)\.'.$type.'\]/', $line, $matches)) { $line = substr($line, strlen($matches[0])); $result[$matches[1]] = trim($this->multLine($line)); - $line = ltrim($this->readLine(1024)); + $line = $this->readLine(1024); } } } -- Gitblit v1.9.1