@@ -650,37 +650,52 @@ public function process() {
650650 $ folder = $ this ->request ->post ['folder ' ];
651651 }
652652 $ path = sprintf ("imap_%s_%s " , $ form ['imap_server_id ' ], $ folder );
653- $ page_cache = $ this ->cache ->get ('imap_folders_ ' .$ path );
653+ $ with_subscription = isset ($ this ->request ->post ['subscription_state ' ]) && $ this ->request ->post ['subscription_state ' ];
654+
654655 if (array_key_exists ('imap_prefetch ' , $ this ->request ->post )) {
655656 $ prefetched = $ this ->session ->get ('imap_prefetched_ids ' , array ());
656657 $ prefetched [] = $ form ['imap_server_id ' ];
657658 $ this ->session ->set ('imap_prefetched_ids ' , array_unique ($ prefetched , SORT_STRING ));
658659 }
659- $ with_subscription = isset ($ this ->request ->post ['subscription_state ' ]) && $ this ->request ->post ['subscription_state ' ];
660+
661+ // Check cache FIRST before connecting to IMAP
662+ $ page_cache = $ this ->cache ->get ('imap_folders_ ' .$ path );
663+ if ($ page_cache && is_array ($ page_cache ) && isset ($ page_cache ['folders ' ])) {
664+ $ this ->out ('imap_expanded_folder_data ' , $ page_cache ['folders ' ]);
665+ $ this ->out ('imap_expanded_folder_id ' , $ form ['imap_server_id ' ]);
666+ $ this ->out ('imap_expanded_folder_path ' , $ path );
667+ $ this ->out ('with_input ' , $ with_subscription );
668+ $ this ->out ('folder ' , $ folder );
669+ $ this ->out ('can_share_folders ' , $ page_cache ['can_share_folders ' ]);
670+
671+ if (isset ($ page_cache ['quota ' ])) {
672+ $ this ->out ('quota ' , $ page_cache ['quota ' ]);
673+ $ this ->out ('quota_max ' , $ page_cache ['quota_max ' ]);
674+ }
675+ return ;
676+ }
677+
660678 $ mailbox = Hm_IMAP_List::get_connected_mailbox ($ form ['imap_server_id ' ], $ this ->cache );
661679 if ($ mailbox && $ mailbox ->authed ()) {
662- $ this ->out ('can_share_folders ' , stripos ($ mailbox ->get_capability (), 'ACL ' ) !== false );
680+ $ can_share_folders = stripos ($ mailbox ->get_capability (), 'ACL ' ) !== false ;
681+ $ this ->out ('can_share_folders ' , $ can_share_folders );
682+ $ quota_data = array ();
663683 $ quota_root = $ mailbox ->get_quota ($ folder ? $ folder : 'INBOX ' , true );
664684 if ($ quota_root && isset ($ quota_root [0 ]['name ' ])) {
665685 $ quota = $ mailbox ->get_quota ($ quota_root [0 ]['name ' ], false );
666686 if ($ quota ) {
667687 $ current = floatval ($ quota [0 ]['current ' ]);
668688 $ max = floatval ($ quota [0 ]['max ' ]);
669689 if ($ max > 0 ) {
670- $ this ->out ('quota ' , ceil (($ current / $ max ) * 100 ));
671- $ this ->out ('quota_max ' , $ max / 1024 );
690+ $ quota_percent = ceil (($ current / $ max ) * 100 );
691+ $ quota_max = $ max / 1024 ;
692+ $ this ->out ('quota ' , $ quota_percent );
693+ $ this ->out ('quota_max ' , $ quota_max );
694+ $ quota_data = array ('quota ' => $ quota_percent , 'quota_max ' => $ quota_max );
672695 }
673696 }
674697 }
675698 }
676- if ($ page_cache ) {
677- $ this ->out ('imap_expanded_folder_data ' , $ page_cache );
678- $ this ->out ('imap_expanded_folder_id ' , $ form ['imap_server_id ' ]);
679- $ this ->out ('imap_expanded_folder_path ' , $ path );
680- $ this ->out ('with_input ' , $ with_subscription );
681- $ this ->out ('folder ' , $ folder );
682- return ;
683- }
684699 if ($ mailbox && $ mailbox ->authed ()) {
685700 $ only_subscribed = $ this ->user_config ->get ('only_subscribed_folders_setting ' , false );
686701 if ($ with_subscription ) {
@@ -694,7 +709,16 @@ public function process() {
694709 if (isset ($ msgs [$ folder ])) {
695710 unset($ msgs [$ folder ]);
696711 }
697- $ this ->cache ->set ('imap_folders_ ' .$ path , $ msgs );
712+
713+ $ cache_data = array (
714+ 'folders ' => $ msgs ,
715+ 'can_share_folders ' => $ can_share_folders ?? false
716+ );
717+ if (!empty ($ quota_data )) {
718+ $ cache_data = array_merge ($ cache_data , $ quota_data );
719+ }
720+ $ this ->cache ->set ('imap_folders_ ' .$ path , $ cache_data );
721+
698722 $ this ->out ('imap_expanded_folder_data ' , $ msgs );
699723 $ this ->out ('imap_expanded_folder_id ' , $ form ['imap_server_id ' ]);
700724 $ this ->out ('imap_expanded_folder_path ' , $ path );
0 commit comments