diff --git a/modules/advanced_search/js_modules/route_handlers.js b/modules/advanced_search/js_modules/route_handlers.js index 4cd54ff165..b5b41beaaf 100644 --- a/modules/advanced_search/js_modules/route_handlers.js +++ b/modules/advanced_search/js_modules/route_handlers.js @@ -21,7 +21,6 @@ function applyAdvancedSearchPageHandlers() { $('.adv_controls').show(); $('.core_msg_control').off('click'); $('.core_msg_control').on("click", function() { return Hm_Message_List.message_action($(this).data('action')); }); - Hm_Message_List.set_checkbox_callback(); if (typeof check_select_for_imap !== 'undefined') { check_select_for_imap(); } diff --git a/modules/advanced_search/modules.php b/modules/advanced_search/modules.php index 6b08f1e093..eaf230250b 100644 --- a/modules/advanced_search/modules.php +++ b/modules/advanced_search/modules.php @@ -91,10 +91,15 @@ public function process() { } } - if ($this->request->post['all_folders']) { + $searchInAllFolders = $this->request->post['all_folders'] ?? false; + $searchInSpecialFolders = $this->request->post['all_special_folders'] ?? false; + $includeSubfolders = $this->request->post['include_subfolders'] ?? false; + if ($searchInAllFolders) { $msg_list = $this->all_folders_search($imap, $flags, $params, $limit); - } elseif ($this->request->post['all_special_folders']) { + } elseif ($searchInSpecialFolders) { $msg_list = $this->special_folders_search($imap, $flags, $params, $limit); + } else if ($includeSubfolders) { + $msg_list = $this->all_folders_search($imap, $flags, $params, $limit, $this->folder); } else if (!$imap->select_mailbox($this->folder)) { return; } else { @@ -105,8 +110,8 @@ public function process() { $this->out('imap_server_ids', array($this->imap_id)); } - private function all_folders_search($imap, $flags, $params, $limit) { - $folders = $imap->get_mailbox_list(); + private function all_folders_search($imap, $flags, $params, $limit, $parent = '') { + $folders = $imap->get_mailbox_list(mailbox:$parent); $msg_list = array(); foreach ($folders as $folder) { $this->folder = $folder['name']; diff --git a/modules/advanced_search/setup.php b/modules/advanced_search/setup.php index c147a48c45..cef80eb541 100644 --- a/modules/advanced_search/setup.php +++ b/modules/advanced_search/setup.php @@ -41,5 +41,6 @@ 'adv_targets' => array('filter' => FILTER_DEFAULT, 'flags' => FILTER_REQUIRE_ARRAY), 'all_folders' => FILTER_VALIDATE_BOOLEAN, 'all_special_folders' => FILTER_VALIDATE_BOOLEAN, + 'include_subfolders' => FILTER_VALIDATE_BOOLEAN, ) ); diff --git a/modules/advanced_search/site.js b/modules/advanced_search/site.js index b8cf2020f3..5b221b34f0 100644 --- a/modules/advanced_search/site.js +++ b/modules/advanced_search/site.js @@ -82,6 +82,7 @@ var expand_adv_folder = function(res) { $('.adv_folder_link', list_container).on("click", function() { return expand_adv_folder_list($(this).data('target')); }); $('a', list_container).not('.adv_folder_link').off('click'); $('a', list_container).not('.adv_folder_link').on("click", function() { adv_folder_select($(this).data('id')); return false; }); + modifyInnerLists(); } }; @@ -131,7 +132,9 @@ var adv_select_imap_folder = function(el) { checkboxesWrapper.append(allSpecialFoldersCheckbox); checkboxesWrapper.append(allFoldersCheckbox); $(this).find('.wrapper').append(checkboxesWrapper); - }) + }); + + modifyInnerLists(); $('.imap_folder_link', folders).addClass('adv_folder_link').removeClass('imap_folder_link'); $('.adv_folder_list').html(folders.html()); @@ -147,6 +150,20 @@ var adv_select_imap_folder = function(el) { }); }; +function modifyInnerLists() { + $('.adv_folder_list').find('.inner_list li').each(function(index) { + const subFoldersCheckbox = ` + + + + + `; + $(this).wrapInner('
'); + $(this).find('.wrapper').append(subFoldersCheckbox); + $(this).find('#main-link').css('flex-grow', 0) + }); +} + var adv_folder_select = function(id) { if ($('.'+id, $('.adv_source_list')).length > 0) { $('.adv_folder_list').html(''); @@ -164,17 +181,19 @@ var adv_folder_select = function(id) { var parent_class = '.'+parts[0]+'_'+parts[1]+'_'; var account = $('a', $(parent_class, container)).first().text(); var label = account+' > '+folder; - add_source_to_list(id, label); + const includeSubfolders = $(`.${id}`).closest('li').find('input[name="include_subfolders"]').is(':checked'); + + add_source_to_list(id, label, includeSubfolders); $('.adv_folder_list').html(''); $('.close_adv_folders').remove(); $('.adv_folder_list').hide(); }; -var add_source_to_list = function(id, label) { +var add_source_to_list = function(id, label, includeSubfolders) { var close = $(globals.close_html); close.addClass('adv_remove_source'); close.attr('data-target', id); - var row = '