Skip to content

Commit

Permalink
feat(MailMgr) sort folders alphabetically with top folder global vari…
Browse files Browse the repository at this point in the history
…able MailManager_Top_Folders
  • Loading branch information
joebordes committed Apr 4, 2023
1 parent 081c3a9 commit f8f34bc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/changeSets/DefineGlobalVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions modules/GlobalVariable/language/en_us.gvdefs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions modules/GlobalVariable/language/es_es.gvdefs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions modules/GlobalVariable/language/fr_fr.gvdefs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions modules/MailManager/src/connectors/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit f8f34bc

Please sign in to comment.