From 74016fd47aa1fdee5fbd8c698a0f7a07e088181d Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Fri, 2 Oct 2015 14:02:10 +0000 Subject: [PATCH] use own code for sorting autofolders, as autofolders may contain subfolders; regard autofolder-test must either match identically OR match with delimiter --- .../inc/class.emailadmin_imapbase.inc.php | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/emailadmin/inc/class.emailadmin_imapbase.inc.php b/emailadmin/inc/class.emailadmin_imapbase.inc.php index 44d006ea88..ce24796db8 100644 --- a/emailadmin/inc/class.emailadmin_imapbase.inc.php +++ b/emailadmin/inc/class.emailadmin_imapbase.inc.php @@ -2737,7 +2737,7 @@ class emailadmin_imapbase } } if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder')); - ksort($aFolders); + //ksort($aFolders); // Sort none auto folders base on mailbox name uasort($nFolders,array($this,'sortByMailbox')); @@ -2817,7 +2817,8 @@ class emailadmin_imapbase foreach($autoFoldersTmp as $afk=>$aF) { //error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]); - if($aF && strlen($mySpecialUseFolders[$aF])&&strlen($k)>=strlen($mySpecialUseFolders[$aF])&&substr($k,0,strlen($mySpecialUseFolders[$aF]))==$mySpecialUseFolders[$aF]) + if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/ + ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter)) { //error_log($k.'->'.$mySpecialUseFolders[$aF]); $isAutoFolder=true; @@ -2840,7 +2841,8 @@ class emailadmin_imapbase foreach($autoFoldersTmp as $afk=>$aF) { //error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]); - if($aF && strlen($mySpecialUseFolders[$aF])&&strlen($k)>=strlen($mySpecialUseFolders[$aF])&&substr($k,0,strlen($mySpecialUseFolders[$aF]))==$mySpecialUseFolders[$aF]) + if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/ + ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter)) { //error_log($k.'->'.$mySpecialUseFolders[$aF]); $isAutoFolder=true; @@ -2857,7 +2859,8 @@ class emailadmin_imapbase foreach($autoFoldersTmp as $afk=>$aF) { //error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]); - if($aF && strlen($mySpecialUseFolders[$aF])&&strlen($k)>=strlen($mySpecialUseFolders[$aF])&&substr($k,0,strlen($mySpecialUseFolders[$aF]))==$mySpecialUseFolders[$aF]) + if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/ + ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter)) { //error_log($k.'->'.$mySpecialUseFolders[$aF]); $isAutoFolder=true; @@ -2886,12 +2889,38 @@ class emailadmin_imapbase } } //error_log(__METHOD__.__LINE__.array2string($autoFoldersTmp)); - uasort ($autoFolderObjects, array($this,'sortByAutofolder')); + // avoid calling sortByAutoFolder as it is not regarding subfolders + $autoFolderObjectsTmp = $autoFolderObjects; + unset($autoFolderObjects); + uasort($autoFolderObjectsTmp, array($this,'sortByMailbox')); + foreach($autoFoldersTmp as $afk=>$aF) + { + foreach($autoFolderObjectsTmp as $k => $f) + { + if($aF && ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter)) + { + $autoFolderObjects[$k]=$f; + } + } + } //error_log(__METHOD__.__LINE__.array2string($autoFolderObjects)); if (!$isGoogleMail) { $folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']); } else { - uasort ($googleAutoFolderObjects, array($this,'sortByAutofolder')); + // avoid calling sortByAutoFolder as it is not regarding subfolders + $gAutoFolderObjectsTmp = $googleAutoFolderObjects; + unset($googleAutoFolderObjects); + uasort($gAutoFolderObjectsTmp, array($this,'sortByMailbox')); + foreach($autoFoldersTmp as $afk=>$aF) + { + foreach($gAutoFolderObjectsTmp as $k => $f) + { + if($aF && ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter)) + { + $googleAutoFolderObjects[$k]=$f; + } + } + } $folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']); } if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');