From f8f34bc3216da1c8a06d0b20fd9b59a218c623fb Mon Sep 17 00:00:00 2001 From: joebordes Date: Tue, 4 Apr 2023 08:59:03 +0200 Subject: [PATCH] feat(MailMgr) sort folders alphabetically with top folder global variable MailManager_Top_Folders --- build/changeSets/DefineGlobalVariables.php | 1 + .../GlobalVariable/language/en_us.gvdefs.php | 6 ++++++ .../GlobalVariable/language/es_es.gvdefs.php | 6 ++++++ .../GlobalVariable/language/fr_fr.gvdefs.php | 6 ++++++ .../MailManager/src/connectors/Connector.php | 21 +++++++++++++++++++ 5 files changed, 40 insertions(+) diff --git a/build/changeSets/DefineGlobalVariables.php b/build/changeSets/DefineGlobalVariables.php index f923812667..84f6526076 100644 --- a/build/changeSets/DefineGlobalVariables.php +++ b/build/changeSets/DefineGlobalVariables.php @@ -274,6 +274,7 @@ public function applyChange() { 'EMail_Signature_BeforeQuote', 'EMail_Company_Signature', 'MailManager_Show_SentTo_Links', + 'MailManager_Top_Folders', 'ToolTip_MaxFieldValueLength', 'ToolTip_NumberOfComments', 'HelpDesk_Support_EMail', diff --git a/modules/GlobalVariable/language/en_us.gvdefs.php b/modules/GlobalVariable/language/en_us.gvdefs.php index 92011166de..13f1a57e3b 100644 --- a/modules/GlobalVariable/language/en_us.gvdefs.php +++ b/modules/GlobalVariable/language/en_us.gvdefs.php @@ -1510,6 +1510,12 @@ 'values' => '0 | 1', 'definition' => 'MailManager shows, by default, on the left panel a set of links to filter emails related to Accounts, Contacts and some other modules. Setting this variable to 0 will hide those quick actions.', ), +'MailManager_Top_Folders' => array( + 'valuetype' => 'String', + 'category' => 'Application', + 'values' => 'CSV list of folder names', + 'definition' => 'MailManager sorts the folders to be shown. This list sets the given folders to the top of the list regardless of their sort order.', +), 'Calendar_Show_WeekNumber' => array( 'valuetype' => 'Boolean', 'category' => 'Module Functionality', diff --git a/modules/GlobalVariable/language/es_es.gvdefs.php b/modules/GlobalVariable/language/es_es.gvdefs.php index 0b8e867470..3f16aeccad 100644 --- a/modules/GlobalVariable/language/es_es.gvdefs.php +++ b/modules/GlobalVariable/language/es_es.gvdefs.php @@ -1510,6 +1510,12 @@ 'values' => '0 | 1', 'definition' => 'MailManager muestra, de manera predeterminada, en el panel izquierdo un conjunto de enlaces para filtrar los correos electrónicos relacionados con Cuentas, Contactos y algunos otros módulos. Establecer esta variable a 0 ocultará esas acciones rápidas.', ), +'MailManager_Top_Folders' => array( + 'valuetype' => 'Texto', + 'category' => 'Applicación', + 'values' => 'lista CSV de nombres de carpetas', + 'definition' => 'MailManager ordena las carpetas que se mostrarán. Esta lista coloca las carpetas dadas en la parte superior de la lista, independientemente de su orden de clasificación.', +), 'Calendar_Show_WeekNumber' => array( 'valuetype' => 'Booleano', 'category' => 'Aplicación', diff --git a/modules/GlobalVariable/language/fr_fr.gvdefs.php b/modules/GlobalVariable/language/fr_fr.gvdefs.php index a8b436b0ad..332a351c84 100644 --- a/modules/GlobalVariable/language/fr_fr.gvdefs.php +++ b/modules/GlobalVariable/language/fr_fr.gvdefs.php @@ -1510,6 +1510,12 @@ 'values' => '0 | 1', 'definition' => 'MailManager shows, by default, on the left panel a set of links to filter emails related to Accounts, Contacts and some other modules. Setting this variable to 0 will hide those quick actions.', ), +'MailManager_Top_Folders' => array( + 'valuetype' => 'String', + 'category' => 'Application', + 'values' => 'CSV list of folder names', + 'definition' => 'MailManager sorts the folders to be shown. This list sets the given folders to the top of the list regardless of their sort order.', +), 'Calendar_Show_WeekNumber' => array( 'valuetype' => 'Boolean', 'category' => 'Module Functionality', diff --git a/modules/MailManager/src/connectors/Connector.php b/modules/MailManager/src/connectors/Connector.php index 4da8a30e99..b386082144 100644 --- a/modules/MailManager/src/connectors/Connector.php +++ b/modules/MailManager/src/connectors/Connector.php @@ -169,6 +169,27 @@ public function folders($ref = '{folder}') { $folder = $this->convertCharacterEncoding($folderName, 'ISO-8859-1', 'UTF7-IMAP'); //Decode folder name $folders[] = $this->folderInstance($folder); } + + $listfolders = GlobalVariable::getVariable('MailManager_Top_Folders', 'INBOX,Sent,Sent Items,sent-mail', 'MailManager'); + $topFolders = explode(',', $listfolders); + usort( + $folders, + function ($a, $b) use ($topFolders) { + $foldera = preg_replace('/{(.*?)}/', '', $a->name($this->mBoxUrl)); + $folderb = preg_replace('/{(.*?)}/', '', $b->name($this->mBoxUrl)); + $topa = array_search($foldera, $topFolders); + $topb = array_search($folderb, $topFolders); + if (is_numeric($topa) && is_numeric($topb)) { + return $topa < $topb ? -1 : 1; + } elseif (is_numeric($topa)) { + return -1; + } elseif (is_numeric($topb)) { + return 1; + } else { + return strtolower($foldera) < strtolower($folderb) ? -1 : 1; + } + } + ); $this->mFolders = $folders; return $folders; }