FolderItem item;
guint lastuid;
+ guint uid_next;
GSList *uid_list;
};
item = g_new0(IMAPFolderItem, 1);
item->lastuid = 0;
+ item->uid_next = 0;
item->uid_list = NULL;
return (FolderItem *)item;
IMAPFolderItem *item = (IMAPFolderItem *)node->data;
item->lastuid = 0;
+ item->uid_next = 0;
g_slist_free(item->uid_list);
item->uid_list = NULL;
{
IMAPFolderItem *item = (IMAPFolderItem *)_item;
IMAPSession *session;
- gint ok, lastuid_old, nummsgs = 0, exists, resent, unseen, uid_val;
+ gint ok, lastuid_old, nummsgs = 0, exists, recent, unseen, uid_val, uid_next;
GSList *uidlist, *elem;
gchar *dir, *cmd_buf;
session = imap_session_get(folder);
g_return_val_if_fail(session != NULL, -1);
- ok = imap_select(session, IMAP_FOLDER(folder), item->item.path,
- &exists, &resent, &unseen, &uid_val);
+ ok = imap_status(session, IMAP_FOLDER(folder), item->item.path,
+ &exists, &recent, &uid_next, &uid_val, &unseen);
if (ok != IMAP_SUCCESS)
return -1;
- if (exists == 0)
+ /* If old uid_next matches new uid_next we can be sure no message
+ was added to the folder */
+ 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) {
+ *msgnum_list = g_slist_copy(item->uid_list);
+ 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;
+ }
+ }
+ item->uid_next = uid_next;
+
+ if (exists == 0) {
+ *msgnum_list = NULL;
return 0;
+ }
+
+ ok = imap_select(session, IMAP_FOLDER(folder), item->item.path,
+ &exists, &recent, &unseen, &uid_val);
+ if (ok != IMAP_SUCCESS)
+ return -1;
cmd_buf = g_strdup_printf("UID %d:*", item->lastuid + 1);
ok = imap_cmd_search(SESSION(session)->sock, cmd_buf, &uidlist);
lastuid_old = item->lastuid;
*msgnum_list = g_slist_copy(item->uid_list);
+ nummsgs = g_slist_length(*msgnum_list);
debug_print("Got %d uids from cache\n", g_slist_length(item->uid_list));
for (elem = uidlist; elem != NULL; elem = g_slist_next(elem)) {
}
g_slist_free(uidlist);
- if (g_slist_length(item->uid_list) != exists) {
+ if (nummsgs != exists) {
/* Cache contains more messages then folder, we have cached
- an old UID of a message that was removed */
+ an old UID of a message that was removed and new messages
+ have been added too, otherwise the uid_next check would
+ not have failed */
debug_print("Freeing imap uid cache");
item->lastuid = 0;
g_slist_free(item->uid_list);
messageview_clear(summaryview->messageview);
buf = NULL;
- if (!item || !item->path || !item->parent || item->no_select ||
- (FOLDER_TYPE(item->folder) == F_MH &&
- ((buf = folder_item_get_path(item)) == NULL ||
- change_dir(buf) < 0))) {
+ if (!item || !item->path || !item->parent || item->no_select) {
g_free(buf);
debug_print("empty folder\n\n");
summary_set_hide_read_msgs_menu(summaryview, FALSE);
GSList *cur;
trash = summaryview->folder_item->folder->trash;
- if (FOLDER_TYPE(summaryview->folder_item->folder) == F_MH) {
- g_return_if_fail(trash != NULL);
- }
/* search deleting messages and execute */
gtk_ctree_pre_recursive