@@ -54,7 +54,7 @@ var imap_unhide = function(event) {
5454 imap_hide_action ( form , server_id , 0 ) ;
5555} ;
5656
57- var imap_test_action = function ( event ) {
57+ var imap_test_action = function ( event ) {
5858 $ ( '.imap_folder_data' ) . empty ( ) ;
5959 event . preventDefault ( ) ;
6060 var form = $ ( this ) . closest ( '.imap_connect' ) ;
@@ -394,7 +394,7 @@ var remove_from_cached_imap_pages = function(msg_cache_key) {
394394 } ) ;
395395}
396396
397- async function select_imap_folder ( path , page = 1 , reload , processInTheBackground = false ) {
397+ async function select_imap_folder ( path , page = 1 , reload , processInTheBackground = false ) {
398398 const messages = new Hm_MessagesStore ( path , page , `${ getParam ( 'keyword' ) } _${ getParam ( 'filter' ) } ` , getParam ( 'sort' ) , [ ] ) ;
399399 await messages . load ( reload , processInTheBackground , false , ( ) => {
400400 if ( processInTheBackground ) {
@@ -457,7 +457,7 @@ var setup_imap_folder_page = async function(listPath, listPage = 1) {
457457 select_imap_folder ( listPath , listPage , true ) ;
458458 }
459459 } ) ;
460- $ ( '.imap_filter' ) . on ( "change" , function ( e ) {
460+ $ ( '.imap_filter' ) . on ( "change" , function ( e ) {
461461 e . preventDefault ( ) ;
462462 $ ( '#imap_filter_form' ) . trigger ( 'submit' ) ;
463463 } ) ;
@@ -470,7 +470,8 @@ var setup_imap_folder_page = async function(listPath, listPage = 1) {
470470 $ ( '#imap_filter_form' ) . trigger ( 'submit' ) ;
471471 } ) ;
472472
473- await select_imap_folder ( listPath , listPage ) ;
473+ // try to fetch from cache but also reload messages, so user don't wait 60 seconds to see the new list (useful for read/unread UI and other updates)
474+ await select_imap_folder ( listPath , listPage , true ) ;
474475 handleMessagesDragAndDrop ( ) ;
475476
476477 // Refresh in the background each 60 seconds
@@ -484,13 +485,13 @@ var setup_imap_folder_page = async function(listPath, listPage = 1) {
484485 } ;
485486} ;
486487
487- $ ( document ) . on ( 'submit' , '#imap_filter_form' , async function ( event ) {
488+ $ ( document ) . on ( 'submit' , '#imap_filter_form' , async function ( event ) {
488489 event . preventDefault ( ) ;
489490 const url = new URL ( location . href ) ;
490491 url . search = $ ( this ) . serialize ( ) ;
491492 history . pushState ( history . state , "" , url . toString ( ) ) ;
492493 location . next = url . search ;
493- try {
494+ try {
494495 const messages = new Hm_MessagesStore ( getListPathParam ( ) , Hm_Utils . get_url_page_number ( ) , `${ getParam ( 'keyword' ) } _${ getParam ( 'filter' ) } ` , getParam ( 'sort' ) ) ;
495496 await messages . load ( ! messages . hasLocalData ( ) , false , false , ( ) => {
496497 display_imap_mailbox ( messages . rows , messages . list , messages ) ;
@@ -535,14 +536,14 @@ function getMessageStorageKey(uid) {
535536async function markPrefetchedMessagesAsRead ( uid ) {
536537 const listPath = getListPathParam ( ) ;
537538 const detail = Hm_Utils . parse_folder_path ( listPath , 'imap' ) ;
538- const msgId = `${ detail . type } _${ detail . server_id } _${ uid } _${ detail . folder } ` ;
539+ const msgId = `${ detail . type } _${ detail . server_id } _${ uid } _${ detail . folder } ` ;
539540
540541 const messages = new Hm_MessagesStore ( listPath , Hm_Utils . get_url_page_number ( ) , `${ getParam ( 'keyword' ) } _${ getParam ( 'filter' ) } ` , getParam ( 'sort' ) ) ;
541542 await messages . load ( false , true ) ;
542543 if ( ! messages . flagAsReadOnOpen ) {
543544 return ;
544545 }
545-
546+
546547 if ( messages . markRowAsRead ( uid ) ) {
547548 const folderId = `${ detail . type } _${ detail . server_id } _${ detail . folder } ` ;
548549 Hm_Folders . unread_counts [ folderId ] -= 1 ;
@@ -584,8 +585,8 @@ var prefetch_imap_folders = function() {
584585 { 'name' : 'imap_server_id' , 'value' : id } ,
585586 { 'name' : 'imap_prefetch' , 'value' : true } ,
586587 { 'name' : 'folder' , 'value' : '' } ] ,
587- function ( res ) {
588- $ ( '#imap_prefetch_ids' ) . val ( ids . join ( ',' ) ) ;
588+ function ( res ) {
589+ $ ( '#imap_prefetch_ids' ) . val ( ids . join ( ',' ) ) ;
589590 prefetch_imap_folders ( ) ;
590591 if ( $ ( '.email_folders ul.folders li' ) . length == 1 ) {
591592 expand_imap_mailbox ( res ) ;
@@ -655,7 +656,7 @@ var get_message_content = function(msg_part, uid, list_path, listParent, detail,
655656 }
656657 globals . auto_advance_email_enabled = Boolean ( res . auto_advance_email_enabled ) ;
657658 } ;
658-
659+
659660 if ( ! msg_part ) {
660661 var msgContent = get_local_message_content ( uid , list_path ) ;
661662 if ( msgContent ) {
@@ -666,38 +667,40 @@ var get_message_content = function(msg_part, uid, list_path, listParent, detail,
666667 }
667668 }
668669
669- Hm_Ajax . request (
670- [ { 'name' : 'hm_ajax_hook' , 'value' : 'ajax_imap_message_content' } ,
671- { 'name' : 'imap_msg_uid' , 'value' : uid } ,
672- { 'name' : 'imap_msg_part' , 'value' : msg_part } ,
673- { 'name' : 'imap_server_id' , 'value' : detail . server_id } ,
674- { 'name' : 'folder' , 'value' : detail . folder } ] ,
675- function ( res ) {
676- if ( res . msg_text === '<div class="msg_text_inner"></div>' && noupdate ) {
677- const modal = new Hm_Modal ( {
678- title : 'Message not found' ,
679- modalId : 'messageNotFoundModal' ,
680- } )
681- modal . setContent ( "The email you're looking for isn't here.<br>It may have been deleted, moved." ) ;
682- modal . addFooterBtn ( 'Go to message list' , 'btn-success' , function ( ) {
683- Hm_Utils . redirect ( "?page=message_list&list_path=" + listParent ) ;
684- } ) ;
685- modal . addFooterBtn ( 'Search mail' , 'btn-success' , function ( ) {
686- Hm_Utils . redirect ( "?page=search" ) ;
687- } ) ;
688- modal . open ( ) ;
689- }
690- if ( ! noupdate ) {
691- onSuccess ( res ) ;
692- }
693- if ( ! noupdate && ! msg_part ) {
694- Hm_Utils . save_to_local_storage ( getMessageStorageKey ( uid ) , JSON . stringify ( res ) ) ;
695- }
696- } ,
697- [ ] ,
698- false ,
699- callback
700- ) ;
670+ if ( detail . type == 'imap' ) {
671+ Hm_Ajax . request (
672+ [ { 'name' : 'hm_ajax_hook' , 'value' : 'ajax_imap_message_content' } ,
673+ { 'name' : 'imap_msg_uid' , 'value' : uid } ,
674+ { 'name' : 'imap_msg_part' , 'value' : msg_part } ,
675+ { 'name' : 'imap_server_id' , 'value' : detail . server_id } ,
676+ { 'name' : 'folder' , 'value' : detail . folder } ] ,
677+ function ( res ) {
678+ if ( res . msg_text === '<div class="msg_text_inner"></div>' && noupdate ) {
679+ const modal = new Hm_Modal ( {
680+ title : 'Message not found' ,
681+ modalId : 'messageNotFoundModal' ,
682+ } )
683+ modal . setContent ( "You are looking at a cached version of a message that might have been deleted or moved from the server." ) ;
684+ modal . addFooterBtn ( 'Go to message list' , 'btn-success' , function ( ) {
685+ Hm_Utils . redirect ( "?page=message_list&list_path=" + listParent ) ;
686+ } ) ;
687+ modal . addFooterBtn ( 'Search mail' , 'btn-success' , function ( ) {
688+ Hm_Utils . redirect ( "?page=search" ) ;
689+ } ) ;
690+ modal . open ( ) ;
691+ }
692+ if ( ! noupdate ) {
693+ onSuccess ( res ) ;
694+ }
695+ if ( ! noupdate && ! msg_part ) {
696+ Hm_Utils . save_to_local_storage ( getMessageStorageKey ( uid ) , JSON . stringify ( res ) ) ;
697+ }
698+ } ,
699+ [ ] ,
700+ false ,
701+ callback
702+ ) ;
703+ }
701704 }
702705 return false ;
703706} ;
@@ -852,7 +855,7 @@ var imap_setup_message_view_page = function(uid, details, list_path, listParent,
852855 if ( ! uid ) {
853856 uid = getMessageUidParam ( ) ;
854857 }
855-
858+
856859 const msg_content = get_local_message_content ( uid , list_path ) ;
857860 const noupdate = Boolean ( msg_content ) ;
858861 get_message_content ( false , uid , list_path , listParent , details , callback , noupdate ) ;
@@ -988,7 +991,7 @@ var imap_perform_move_copy = function(dest_id, context, action = null) {
988991 { 'name' : 'imap_move_page' , 'value' : page } ,
989992 { 'name' : 'imap_move_action' , 'value' : action } ] ,
990993 async function ( res ) {
991-
994+
992995 var index ;
993996 const store = new Hm_MessagesStore ( getListPathParam ( ) , Hm_Utils . get_url_page_number ( ) , `${ getParam ( 'keyword' ) } _${ getParam ( 'filter' ) } ` , getParam ( 'sort' ) ) ;
994997 await store . load ( false , true , true ) ;
@@ -1191,7 +1194,7 @@ var imap_setup_snooze = function() {
11911194 const path = getParam ( "list_parent" ) || getListPathParam ( ) ;
11921195 const store = new Hm_MessagesStore ( path , Hm_Utils . get_url_page_number ( ) , `${ getParam ( 'keyword' ) } _${ getParam ( 'filter' ) } ` , getParam ( 'sort' ) ) ;
11931196 await store . load ( false , true , true ) ;
1194-
1197+
11951198 snoozedMessages . forEach ( ( msg ) => {
11961199 store . removeRow ( msg ) ;
11971200 } ) ;
0 commit comments