@@ -182,6 +182,8 @@ class Hm_IMAP extends Hm_IMAP_Cache {
182182 public $ folder_state = false ;
183183 private $ scramAuthenticator ;
184184 private $ namespace_count = 0 ;
185+
186+ protected $ list_sub_folders = [];
185187 /**
186188 * constructor
187189 */
@@ -1753,16 +1755,31 @@ public function delete_mailbox($mailbox) {
17531755 $ this ->debug [] = 'Delete mailbox not permitted in read only mode ' ;
17541756 return false ;
17551757 }
1756- $ command = 'DELETE " ' .str_replace ('" ' , '\" ' , $ this ->utf7_encode ($ mailbox ))."\"\r\n" ;
1757- $ this ->send_command ($ command );
1758- $ result = $ this ->get_response (false );
1759- $ status = $ this ->check_response ($ result , false );
1760- if ($ status ) {
1761- return true ;
1758+ $ this ->list_sub_folders [] = $ mailbox ;
1759+ $ this ->get_recursive_subfolders ($ mailbox , true );
1760+ $ this ->list_sub_folders = array_reverse ($ this ->list_sub_folders );
1761+ foreach ($ this ->list_sub_folders as $ key => $ del_folder ) {
1762+ $ command = 'DELETE " ' .str_replace ('" ' , '\" ' , $ this ->utf7_encode ($ del_folder ))."\"\r\n" ;
1763+ $ this ->send_command ($ command );
1764+ $ result = $ this ->get_response (false );
1765+ $ status = $ this ->check_response ($ result , false );
1766+ if ($ status ) {
1767+ unset($ this ->list_sub_folders [$ key ]);
1768+ } else {
1769+ $ this ->debug [] = str_replace ('A ' .$ this ->command_count , '' , $ result [0 ]);
1770+ return false ;
1771+ }
17621772 }
1763- else {
1764- $ this ->debug [] = str_replace ('A ' .$ this ->command_count , '' , $ result [0 ]);
1765- return false ;
1773+ return true ;
1774+ }
1775+
1776+ public function get_recursive_subfolders ($ parentFolder , $ is_delete_action ) {
1777+ $ infoFolder = $ this ->get_folder_list_by_level ($ parentFolder , false , false , $ is_delete_action );
1778+ if ($ infoFolder ) {
1779+ foreach (array_keys ($ infoFolder ) as $ folder ) {
1780+ $ this ->list_sub_folders [] = $ folder ;
1781+ $ this ->get_recursive_subfolders ($ folder , $ is_delete_action );
1782+ }
17661783 }
17671784 }
17681785
@@ -2499,7 +2516,7 @@ public function get_mailbox_page($mailbox, $sort, $rev, $filter, $offset=0, $lim
24992516 * @param string $level mailbox name or empty string for the top level
25002517 * @return array list of matching folders
25012518 */
2502- public function get_folder_list_by_level ($ level ='' , $ only_subscribed =false , $ with_input = false ) {
2519+ public function get_folder_list_by_level ($ level ='' , $ only_subscribed =false , $ with_input = false , $ is_delete_action = false ) {
25032520 $ result = array ();
25042521 $ folders = array ();
25052522 if ($ this ->server_support_children_capability ()) {
@@ -2522,6 +2539,9 @@ public function get_folder_list_by_level($level='', $only_subscribed=false, $wit
25222539 if ($ with_input ) {
25232540 $ result [$ name ]['special ' ] = $ folder ['special ' ];
25242541 }
2542+ if ($ folder ['can_have_kids ' ] && !$ is_delete_action ) {
2543+ $ result [$ name ]['number_of_children ' ] = count ($ this ->get_folder_list_by_level ($ folder ['name ' ], false , false , $ is_delete_action ));
2544+ }
25252545 }
25262546 if ($ only_subscribed || $ with_input ) {
25272547 $ subscribed_folders = array_column ($ this ->get_mailbox_list (true , children_capability:$ this ->server_support_children_capability ()), 'name ' );
0 commit comments