From 5804ef8aa23cd5e8855bb4c8a4c89bc0b4d62936 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 8 May 2017 10:37:06 +0200 Subject: [PATCH] Fix folders list sorting on Windows - if php-intl is available (#5732) --- CHANGELOG | 1 + program/lib/Roundcube/rcube.php | 1 + program/lib/Roundcube/rcube_imap.php | 15 +++++++++++++++ program/lib/Roundcube/rcube_storage.php | 10 +++++----- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d1a06cef1..87b4f6c16 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ CHANGELOG Roundcube Webmail - Print error from CLI scripts when system/exec function is disabled (#5744) - Fix bug where comment notation within style tag would cause the whole style to be ignored (#5747) - Fix bug where it wasn't possible to scroll folders list in Edge (#5750) +- Fix folders list sorting on Windows - if php-intl is available (#5732) RELEASE 1.3-rc -------------- diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 7c9d5ccd7..fb7bf76f0 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -390,6 +390,7 @@ class rcube ); if (!empty($_SESSION['storage_host'])) { + $options['language'] = $_SESSION['language']; $options['host'] = $_SESSION['storage_host']; $options['user'] = $_SESSION['username']; $options['port'] = $_SESSION['storage_port']; diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index e2984c1c1..d5135bf74 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -4262,6 +4262,17 @@ class rcube_imap extends rcube_storage */ protected function sort_folder_comparator($str1, $str2) { + if ($this->sort_folder_collator === null) { + $this->sort_folder_collator = false; + + // strcoll() does not work with UTF8 locale on Windows, + // use Collator from the intl extension + if (stripos(PHP_OS, 'win') === 0 && function_exists('collator_compare')) { + $locale = $this->options['language'] ?: 'en_US'; + $this->sort_folder_collator = collator_create($locale) ?: false; + } + } + $path1 = explode($this->delimiter, $str1); $path2 = explode($this->delimiter, $str2); @@ -4272,6 +4283,10 @@ class rcube_imap extends rcube_storage continue; } + if ($this->sort_folder_collator) { + return collator_compare($this->sort_folder_collator, $folder1, $folder2); + } + return strcoll($folder1, $folder2); } } diff --git a/program/lib/Roundcube/rcube_storage.php b/program/lib/Roundcube/rcube_storage.php index d5bcf27a5..56703177c 100644 --- a/program/lib/Roundcube/rcube_storage.php +++ b/program/lib/Roundcube/rcube_storage.php @@ -42,13 +42,13 @@ abstract class rcube_storage */ public static $folder_types = array('drafts', 'sent', 'junk', 'trash'); - protected $folder = 'INBOX'; + protected $folder = 'INBOX'; protected $default_charset = 'ISO-8859-1'; + protected $options = array('auth_type' => 'check', 'language' => 'en_US'); + protected $page_size = 10; + protected $list_page = 1; + protected $threading = false; protected $search_set; - protected $options = array('auth_type' => 'check'); - protected $page_size = 10; - protected $list_page = 1; - protected $threading = false; /** * All (additional) headers used (in any way) by Roundcube