@@ -87,18 +87,13 @@ var expand_adv_folder = function(res) {
8787 }
8888} ;
8989
90- $ ( document ) . on ( "change" , "input[name='all_folders'],input[name='all_special_folders'] " , function ( ) {
90+ $ ( document ) . on ( "change" , "input[name='all_folders']" , function ( ) {
9191 const folderLi = $ ( this ) . closest ( 'li' ) ;
92- const divergentCheckboxName = this . name === 'all_folders' ? 'all_special_folders' : 'all_folders' ;
93- const divergentCheckbox = $ ( this ) . closest ( 'div' ) . find ( `input[name='${ divergentCheckboxName } ']` )
9492
9593 if ( $ ( this ) . is ( ':checked' ) ) {
9694 folderLi . find ( 'a' ) . attr ( 'disabled' , 'disabled' ) ;
97- divergentCheckbox . prop ( 'checked' , false ) ;
98- divergentCheckbox . attr ( 'disabled' , 'disabled' ) ;
9995 } else {
10096 folderLi . find ( 'a' ) . removeAttr ( 'disabled' ) ;
101- divergentCheckbox . removeAttr ( 'disabled' ) ;
10297 }
10398} ) ;
10499
@@ -117,11 +112,8 @@ var adv_select_imap_folder = function(el) {
117112 folders . find ( 'li' ) . each ( function ( index ) {
118113 const wrapper = $ ( '<div class="d-flex justify-content-between wrapper"></div>' ) ;
119114 $ ( this ) . wrapInner ( wrapper ) ;
120- const allSpecialFoldersCheckbox = `
121- <span class="form-check">
122- <label class="form-check-label" for="all_special_folders-${ index } ">All special folders</label>
123- <input class="form-check-input" type="checkbox" name="all_special_folders" id="all_special_folders-${ index } ">
124- </span>
115+ const pickSpecialFoldersButton = `
116+ <a href="#" class="btn btn-light btn-sm pick_special_folders">Pick special folders</a>
125117 ` ;
126118 const allFoldersCheckbox = `
127119 <span class="form-check">
@@ -130,7 +122,7 @@ var adv_select_imap_folder = function(el) {
130122 </span>
131123 ` ;
132124 const checkboxesWrapper = $ ( '<div class="d-flex gap-3"></div>' ) ;
133- checkboxesWrapper . append ( allSpecialFoldersCheckbox ) ;
125+ checkboxesWrapper . append ( pickSpecialFoldersButton ) ;
134126 checkboxesWrapper . append ( allFoldersCheckbox ) ;
135127 $ ( this ) . find ( '.wrapper' ) . append ( checkboxesWrapper ) ;
136128 } ) ;
@@ -141,8 +133,8 @@ var adv_select_imap_folder = function(el) {
141133 $ ( '.adv_folder_list' ) . html ( folders . html ( ) ) ;
142134
143135 $ ( '.adv_folder_link' , list_container ) . on ( "click" , function ( ) { return expand_adv_folder_list ( $ ( this ) . data ( 'target' ) ) ; } ) ;
144- $ ( 'a' , list_container ) . not ( '.adv_folder_link' ) . not ( '.close_adv_folders' ) . off ( 'click' ) ;
145- $ ( 'a' , list_container ) . not ( '.adv_folder_link' ) . not ( '.close_adv_folders' ) . on ( "click" , function ( ) { adv_folder_select ( $ ( this ) . data ( 'id' ) ) ; return false ; } ) ;
136+ $ ( 'a' , list_container ) . not ( '.adv_folder_link' ) . not ( '.close_adv_folders' ) . not ( '.pick_special_folders' ) . off ( 'click' ) ;
137+ $ ( 'a' , list_container ) . not ( '.adv_folder_link' ) . not ( '.close_adv_folders' ) . not ( '.pick_special_folders' ) . on ( "click" , function ( ) { adv_folder_select ( $ ( this ) . data ( 'id' ) ) ; return false ; } ) ;
146138 $ ( '.close_adv_folders' ) . on ( "click" , function ( ) {
147139 $ ( '.adv_folder_list' ) . html ( '' ) ;
148140 $ ( '.adv_folder_list' ) . hide ( ) ;
@@ -191,6 +183,8 @@ var adv_folder_select = function(id) {
191183} ;
192184
193185var add_source_to_list = function ( id , label , includeSubfolders ) {
186+ if ( get_adv_sources ( ) . find ( source => source . label === label ) ) return ;
187+
194188 var close = $ ( globals . close_html ) ;
195189 close . addClass ( 'adv_remove_source' ) ;
196190 close . attr ( 'data-target' , id ) ;
@@ -250,13 +244,7 @@ var get_adv_sources = function() {
250244 const searchInAllFolders = $ ( '.adv_folder_list li input[name="all_folders"]:checked' ) ;
251245 searchInAllFolders . each ( function ( ) {
252246 const li = $ ( this ) . closest ( 'li' ) ;
253- sources . push ( { 'source' : li . attr ( 'class' ) , 'label' : li . find ( 'a' ) . text ( ) , allFolders : true } ) ;
254- } ) ;
255-
256- const searchInSpecialFolders = $ ( '.adv_folder_list li input[name="all_special_folders"]:checked' ) ;
257- searchInSpecialFolders . each ( function ( ) {
258- const li = $ ( this ) . closest ( 'li' ) ;
259- sources . push ( { 'source' : li . attr ( 'class' ) , 'label' : li . find ( 'a' ) . text ( ) , specialFolders : true } ) ;
247+ sources . push ( { 'source' : li . attr ( 'class' ) , 'label' : li . find ( 'a' ) . first ( ) . text ( ) , allFolders : true } ) ;
260248 } ) ;
261249
262250 const selected_sources = $ ( 'div' , $ ( '.adv_source_list' ) ) ;
@@ -265,9 +253,8 @@ var get_adv_sources = function() {
265253 }
266254 selected_sources . each ( function ( ) {
267255 const source = this . className ;
268- const mailboxSource = source . split ( '_' ) . slice ( 0 , 2 ) . join ( '_' ) ;
269- if ( ! sources . find ( s => s . source . indexOf ( mailboxSource ) > - 1 ) ) {
270- sources . push ( { 'source' : source , 'label' : $ ( 'a' , $ ( this ) ) . text ( ) , subFolders : $ ( this ) . data ( 'subfolders' ) } ) ;
256+ if ( ! sources . find ( s => s . source === source ) ) {
257+ sources . push ( { 'source' : source , 'label' : $ ( this ) . text ( ) , subFolders : $ ( this ) . data ( 'subfolders' ) } ) ;
271258 }
272259 } ) ;
273260 return sources ;
@@ -443,8 +430,6 @@ var send_requests = function(requests) {
443430
444431 if ( request [ 'all_folders' ] ) {
445432 params . push ( { name : 'all_folders' , value : true } ) ;
446- } else if ( request [ 'all_special_folders' ] ) {
447- params . push ( { name : 'all_special_folders' , value : true } ) ;
448433 } else if ( request [ 'sub_folders' ] ) {
449434 params . push ( { name : 'include_subfolders' , value : true } ) ;
450435 }
@@ -507,10 +492,8 @@ var build_adv_search_requests = function(terms, sources, targets, times, other)
507492 time = times [ ti ] ;
508493 const config = { 'source' : source . source , 'time' : time , 'other' : other ,
509494 'targets' : target_vals , 'terms' : term_vals } ;
510- if ( source . allFolders ) {
495+ if ( source . allFolders || source . source . split ( '_' ) . filter ( part => part . trim ( ) !== '' ) . length === 2 ) {
511496 config [ 'all_folders' ] = true ;
512- } else if ( source . specialFolders ) {
513- config [ 'all_special_folders' ] = true ;
514497 } else if ( source . subFolders ) {
515498 config [ 'sub_folders' ] = true ;
516499 }
@@ -567,7 +550,7 @@ var apply_saved_search = function() {
567550 }
568551 }
569552 for ( var i = 0 , len = details [ 'sources' ] . length ; i < len ; i ++ ) {
570- add_source_to_list ( details [ 'sources' ] [ i ] [ 'source' ] , details [ 'sources' ] [ i ] [ 'label' ] ) ;
553+ add_source_to_list ( details [ 'sources' ] [ i ] [ 'source' ] , details [ 'sources' ] [ i ] [ 'label' ] , details [ 'sources' ] [ i ] [ 'subFolders' ] || false ) ;
571554 }
572555 for ( var i = 0 , len = details [ 'targets' ] . length ; i < len ; i ++ ) {
573556 if ( i == 0 ) {
0 commit comments