summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube/rcube_imap.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2014-06-04 10:44:26 +0200
committerAleksander Machniak <alec@alec.pl>2014-06-04 10:44:26 +0200
commit354c7d3c6c457f93baae64c6df64ad99f4050b81 (patch)
tree98bca25e5ef26ea2b0e90fe623ee22bdf998399c /program/lib/Roundcube/rcube_imap.php
parentae48735f2cde8ca4ac833ebcbeeee5b899adc645 (diff)
Fix folders sorting in case when special folders are subfolders of INBOX
Diffstat (limited to 'program/lib/Roundcube/rcube_imap.php')
-rw-r--r--program/lib/Roundcube/rcube_imap.php38
1 files changed, 23 insertions, 15 deletions
diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php
index 6dcf528e0..e29bfc46b 100644
--- a/program/lib/Roundcube/rcube_imap.php
+++ b/program/lib/Roundcube/rcube_imap.php
@@ -4166,30 +4166,38 @@ class rcube_imap extends rcube_storage
// force the type of folder name variable (#1485527)
$folders = array_map('strval', $folders);
+ $out = array();
+
+ // finally we must put special folders on top and rebuild the list
+ // to move their subfolders where they belong...
$specials = array_unique(array_intersect($specials, $folders));
- $head = array();
+ $folders = array_merge($specials, array_diff($folders, $specials));
- // place default folders on top
- foreach ($specials as $special) {
- $prefix = $special . $this->delimiter;
+ $this->sort_folder_specials(null, $folders, $specials, $out);
- foreach ($folders as $idx => $folder) {
- if ($folder === $special) {
- $head[] = $special;
- unset($folders[$idx]);
- }
- // put subfolders of default folders on their place...
- else if (strpos($folder, $prefix) === 0) {
- $head[] = $folder;
- unset($folders[$idx]);
+ return $out;
+ }
+
+ /**
+ * Recursive function to put subfolders of special folders in place
+ */
+ protected function sort_folder_specials($folder, &$list, &$specials, &$out)
+ {
+ while (list($key, $name) = each($list)) {
+ if ($folder === null || strpos($name, $folder.$this->delimiter) === 0) {
+ $out[] = $name;
+ unset($list[$key]);
+
+ if (!empty($specials) && ($found = array_search($name, $specials)) !== false) {
+ unset($specials[$found]);
+ $this->sort_folder_specials($name, $list, $specials, $out);
}
}
}
- return array_merge($head, $folders);
+ reset($list);
}
-
/**
* Callback for uasort() that implements correct
* locale-aware case-sensitive sorting