@@ -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 */
@@ -1923,16 +1925,31 @@ public function delete_mailbox($mailbox) {
19231925 $ this ->debug [] = 'Delete mailbox not permitted in read only mode ' ;
19241926 return false ;
19251927 }
1926- $ command = 'DELETE " ' .str_replace ('" ' , '\" ' , $ this ->utf7_encode ($ mailbox ))."\"\r\n" ;
1927- $ this ->send_command ($ command );
1928- $ result = $ this ->get_response (false );
1929- $ status = $ this ->check_response ($ result , false );
1930- if ($ status ) {
1931- return true ;
1928+ $ this ->list_sub_folders [] = $ mailbox ;
1929+ $ this ->get_recursive_subfolders ($ mailbox , true );
1930+ $ this ->list_sub_folders = array_reverse ($ this ->list_sub_folders );
1931+ foreach ($ this ->list_sub_folders as $ key => $ del_folder ) {
1932+ $ command = 'DELETE " ' .str_replace ('" ' , '\" ' , $ this ->utf7_encode ($ del_folder ))."\"\r\n" ;
1933+ $ this ->send_command ($ command );
1934+ $ result = $ this ->get_response (false );
1935+ $ status = $ this ->check_response ($ result , false );
1936+ if ($ status ) {
1937+ unset($ this ->list_sub_folders [$ key ]);
1938+ } else {
1939+ $ this ->debug [] = str_replace ('A ' .$ this ->command_count , '' , $ result [0 ]);
1940+ return false ;
1941+ }
19321942 }
1933- else {
1934- $ this ->debug [] = str_replace ('A ' .$ this ->command_count , '' , $ result [0 ]);
1935- return false ;
1943+ return true ;
1944+ }
1945+
1946+ public function get_recursive_subfolders ($ parentFolder , $ is_delete_action ) {
1947+ $ infoFolder = $ this ->get_folder_list_by_level ($ parentFolder , false , false , $ is_delete_action );
1948+ if ($ infoFolder ) {
1949+ foreach (array_keys ($ infoFolder ) as $ folder ) {
1950+ $ this ->list_sub_folders [] = $ folder ;
1951+ $ this ->get_recursive_subfolders ($ folder , $ is_delete_action );
1952+ }
19361953 }
19371954 }
19381955
@@ -2669,7 +2686,7 @@ public function get_mailbox_page($mailbox, $sort, $rev, $filter, $offset=0, $lim
26692686 * @param string $level mailbox name or empty string for the top level
26702687 * @return array list of matching folders
26712688 */
2672- public function get_folder_list_by_level ($ level ='' , $ only_subscribed =false , $ with_input = false ) {
2689+ public function get_folder_list_by_level ($ level ='' , $ only_subscribed =false , $ with_input = false , $ is_delete_action = false ) {
26732690 $ result = array ();
26742691 $ folders = array ();
26752692 if ($ this ->server_support_children_capability ()) {
@@ -2692,6 +2709,9 @@ public function get_folder_list_by_level($level='', $only_subscribed=false, $wit
26922709 if ($ with_input ) {
26932710 $ result [$ name ]['special ' ] = $ folder ['special ' ];
26942711 }
2712+ if ($ folder ['can_have_kids ' ] && !$ is_delete_action ) {
2713+ $ result [$ name ]['number_of_children ' ] = count ($ this ->get_folder_list_by_level ($ folder ['name ' ], false , false , $ is_delete_action ));
2714+ }
26952715 }
26962716 if ($ only_subscribed || $ with_input ) {
26972717 $ subscribed_folders = array_column ($ this ->get_mailbox_list (true , children_capability:$ this ->server_support_children_capability ()), 'name ' );
0 commit comments