Fix bug where subfolders of special folders could have been duplicated on folder list

pull/5786/merge
Aleksander Machniak 5 years ago
parent bb06645b8f
commit e9c592a6e8

@ -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
-------------

@ -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);
}
/**

@ -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);
}
}

Loading…
Cancel
Save