- if (item->use_cache && time(NULL) - item->use_cache < 2) {
- exists = item->c_messages;
- uid_next = item->c_uid_next;
- uid_val = item->c_uid_validity;
- ok = IMAP_SUCCESS;
- debug_print("using cache %d %d %d\n", exists, uid_next, uid_val);
- } else {
- ok = imap_status(session, IMAP_FOLDER(folder), item->item.path, item,
- &exists, &uid_next, &uid_val, NULL, FALSE);
- }
- item->item.last_num = uid_next - 1;
-
- item->use_cache = (time_t)0;
- if (ok != IMAP_SUCCESS) {
- statusbar_pop_all();
- unlock_session(session);
- return -1;
- }
- if(item->item.mtime == uid_val)
- *old_uids_valid = TRUE;
- else {
- *old_uids_valid = FALSE;
-
- debug_print("Freeing imap uid cache (%d != %d)\n",
- (int)item->item.mtime, uid_val);
- item->lastuid = 0;
- g_slist_free(item->uid_list);
- item->uid_list = NULL;
-
- item->item.mtime = uid_val;
-
- imap_delete_all_cached_messages((FolderItem *)item);
- }
- }
-
- /* If old uid_next matches new uid_next we can be sure no message
- was added to the folder */
- debug_print("uid_next is %d and item->uid_next %d \n",
- uid_next, item->uid_next);
- if (uid_next == item->uid_next) {
- nummsgs = g_slist_length(item->uid_list);
-
- /* If number of messages is still the same we
- know our caches message numbers are still valid,
- otherwise if the number of messages has decrease
- we discard our cache to start a new scan to find
- out which numbers have been removed */
- if (exists == nummsgs) {
- debug_print("exists == nummsgs\n");
- *msgnum_list = g_slist_copy(item->uid_list);
- statusbar_pop_all();
- unlock_session(session);
- return nummsgs;
- } else if (exists < nummsgs) {
- debug_print("Freeing imap uid cache");
- item->lastuid = 0;
- g_slist_free(item->uid_list);
- item->uid_list = NULL;
- }
- }
-
- if (exists == 0) {
- *msgnum_list = NULL;
- statusbar_pop_all();
- unlock_session(session);
- return 0;