From e9c592a6e817c856ba87301cc85c5bbc6aa6f4cc Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 8 Jun 2020 20:35:19 +0200 Subject: [PATCH] Fix bug where subfolders of special folders could have been duplicated on folder list --- CHANGELOG | 1 + program/lib/Roundcube/rcube_imap.php | 13 ++++-- tests/Framework/Imap.php | 61 ++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 821d73261..81cd4e10b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -27,6 +27,7 @@ CHANGELOG Roundcube Webmail - Templates: Make [space][slash] ending of condition objects optional (#6954) - Fix so messages in threads with no root aren't displayed separately (#4999) - Fix so anchor tags without href attribute are not modified (#7413) +- Fix bug where subfolders of special folders could have been duplicated on folder list RELEASE 1.4.6 ------------- diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 0a3b30fc9..314ee4ab7 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -4383,10 +4383,17 @@ class rcube_imap extends rcube_storage */ protected function sort_folder_specials($folder, &$list, &$specials, &$out) { - foreach ($list as $key => $name) { + $count = count($list); + + for ($i = 0; $i < $count; $i++) { + $name = $list[$i]; + if ($name === null) { + continue; + } + if ($folder === null || strpos($name, $folder.$this->delimiter) === 0) { $out[] = $name; - unset($list[$key]); + $list[$i] = null; if (!empty($specials) && ($found = array_search($name, $specials)) !== false) { unset($specials[$found]); @@ -4394,8 +4401,6 @@ class rcube_imap extends rcube_storage } } } - - reset($list); } /** diff --git a/tests/Framework/Imap.php b/tests/Framework/Imap.php index bebee465e..2b8ec5611 100644 --- a/tests/Framework/Imap.php +++ b/tests/Framework/Imap.php @@ -17,4 +17,65 @@ class Framework_Imap extends PHPUnit\Framework\TestCase $this->assertInstanceOf('rcube_imap', $object, "Class constructor"); } + + /** + * Folder sorting + */ + function test_sort_folder_list() + { + $_SESSION['imap_delimiter'] = '.'; + $_SESSION['imap_namespace'] = [ + 'personal' => null, + 'other' => [['Other Users.', '.']], + 'shared' => [['Shared.', '.']], + ]; + + foreach (array('drafts', 'sent', 'junk', 'trash') as $mbox) { + rcube::get_instance()->config->set("$mbox_mbox", ucfirst($mbox)); + } + + $object = new rcube_imap; + + $result = $object->sort_folder_list([]); + $this->assertSame([], $result); + + $result = $object->sort_folder_list(['B', 'A']); + $this->assertSame(['A', 'B'], $result); + + $folders = [ + 'Trash', + 'Sent', + 'ABC', + 'Drafts', + 'INBOX.Trash', + 'INBOX.Junk', + 'INBOX.Sent', + 'INBOX.Drafts', + 'Shared.Test1', + 'Other Users.Test2', + 'Junk', + 'INBOX', + 'DEF', + ]; + + $expected = [ + 'INBOX', + 'INBOX.Drafts', + 'INBOX.Junk', + 'INBOX.Sent', + 'INBOX.Trash', + 'Drafts', + 'Sent', + 'Junk', + 'Trash', + 'ABC', + 'DEF', + 'Other Users.Test2', + 'Shared.Test1', + ]; + + $result = $object->sort_folder_list($folders); + + $this->assertSame($expected, $result); + } }