Use the summary's last uid as the one to fetch from, ignoring the cache.
authorNot Zed <NotZed@Ximian.com>
Fri, 27 Sep 2002 05:34:05 +0000 (05:34 +0000)
committerMichael Zucci <zucchi@src.gnome.org>
Fri, 27 Sep 2002 05:34:05 +0000 (05:34 +0000)
2002-09-27  Not Zed  <NotZed@Ximian.com>

        * providers/imap/camel-imap-folder.c (imap_update_summary): Use
        the summary's last uid as the one to fetch from, ignoring the
        cache.  Use strotul instead of atoi as well.

        * providers/imap/camel-imap-store.c (get_folder_counts): If we
        have the folder open, and the unread count has changed, refresh
        it.  Should fix #30399 enough.  Also in non-check-all mode, if we
        have the folder open, use it anyway.

camel/ChangeLog
camel/providers/imap/camel-imap-folder.c
camel/providers/imap/camel-imap-store.c

index db2bf38..6771d23 100644 (file)
@@ -1,3 +1,14 @@
+2002-09-27  Not Zed  <NotZed@Ximian.com>
+
+       * providers/imap/camel-imap-folder.c (imap_update_summary): Use
+       the summary's last uid as the one to fetch from, ignoring the
+       cache.  Use strotul instead of atoi as well.
+
+       * providers/imap/camel-imap-store.c (get_folder_counts): If we
+       have the folder open, and the unread count has changed, refresh
+       it.  Should fix #30399 enough.  Also in non-check-all mode, if we
+       have the folder open, use it anyway.
+
 2002-09-26  Not Zed  <NotZed@Ximian.com>
 
        * tests/folder/test2.c (main): Treat spool as a local folder, so
index 51c46d6..1365c72 100644 (file)
@@ -2055,7 +2055,7 @@ imap_update_summary (CamelFolder *folder, int exists,
        CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store);
        CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
        GPtrArray *fetch_data = NULL, *messages = NULL, *needheaders;
-       guint32 flags, uidval, maxuid;
+       guint32 flags, uidval;
        int i, seq, first, size, got;
        CamelImapResponseType type;
        const char *header_spec;
@@ -2079,30 +2079,18 @@ imap_update_summary (CamelFolder *folder, int exists,
        first = seq + 1;
        if (seq > 0) {
                mi = camel_folder_summary_index (folder->summary, seq - 1);
-               uidval = atoi (camel_message_info_uid (mi));
+               uidval = strtoul(camel_message_info_uid (mi), NULL, 10);
                camel_folder_summary_info_free (folder->summary, mi);
        } else
                uidval = 0;
        
-       size = (exists - seq) * (IMAP_PRETEND_SIZEOF_FLAGS + IMAP_PRETEND_SIZEOF_SIZE);
+       size = (exists - seq) * (IMAP_PRETEND_SIZEOF_FLAGS + IMAP_PRETEND_SIZEOF_SIZE + IMAP_PRETEND_SIZEOF_HEADERS);
        got = 0;
-       
-       maxuid = camel_imap_message_cache_max_uid (imap_folder->cache);
-       if (uidval >= maxuid) {
-               /* None of the new messages are cached */
-               size += (exists - seq) * IMAP_PRETEND_SIZEOF_HEADERS;
-               if (!camel_imap_command_start (store, folder, ex,
-                                              "UID FETCH %d:* (FLAGS RFC822.SIZE INTERNALDATE BODY.PEEK[%s])",
-                                              maxuid + 1, header_spec))
-                       return;
-               camel_operation_start (NULL, _("Fetching summary information for new messages"));
-       } else {
-               if (!camel_imap_command_start (store, folder, ex,
-                                              "UID FETCH %d:* (FLAGS RFC822.SIZE)",
-                                              uidval + 1))
-                       return;
-               camel_operation_start (NULL, _("Scanning for new messages"));
-       }
+       if (!camel_imap_command_start (store, folder, ex,
+                                      "UID FETCH %d:* (FLAGS RFC822.SIZE INTERNALDATE BODY.PEEK[%s])",
+                                      uidval + 1, header_spec))
+               return;
+       camel_operation_start (NULL, _("Fetching summary information for new messages"));
        
        /* Parse the responses. We can't add a message to the summary
         * until we've gotten its headers, and there's no guarantee
index b23be5f..fbc1e20 100644 (file)
@@ -2131,6 +2131,7 @@ static void
 get_folder_counts(CamelImapStore *imap_store, CamelFolderInfo *fi, CamelException *ex)
 {
        GSList *q;
+       CamelFolder *folder;
 
        /* non-recursive breath first search */
 
@@ -2156,12 +2157,33 @@ get_folder_counts(CamelImapStore *imap_store, CamelFolderInfo *fi, CamelExceptio
                                           any operations anyway so this is 'safe'.  See comment above imap_store_refresh_folders() for info */
                                        CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(imap_store->current_folder))->refresh_info(imap_store->current_folder, ex);
                                        fi->unread_message_count = camel_folder_get_unread_message_count (imap_store->current_folder);
-                               } else
+                               } else {
                                        fi->unread_message_count = get_folder_status (imap_store, fi->full_name, "UNSEEN");
+                                       /* if we have this folder open, and the unread count has changed, update */
+                                       CAMEL_STORE_LOCK(imap_store, cache_lock);
+                                       folder = g_hash_table_lookup(CAMEL_STORE(imap_store)->folders, fi->full_name);
+                                       if (folder && fi->unread_message_count != camel_folder_get_unread_message_count(folder))
+                                               camel_object_ref(folder);
+                                       else
+                                               folder = NULL;
+                                       CAMEL_STORE_UNLOCK(imap_store, cache_lock);
+                                       if (folder) {
+                                               CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(folder))->refresh_info(folder, ex);
+                                               fi->unread_message_count = camel_folder_get_unread_message_count(folder);
+                                               camel_object_unref(folder);
+                                       }
+                               }
                
                                CAMEL_SERVICE_UNLOCK (imap_store, connect_lock);
                        } else {
-                               fi->unread_message_count = -1;
+                               /* since its cheap, get it if they're open */
+                               CAMEL_STORE_LOCK(imap_store, cache_lock);
+                               folder = g_hash_table_lookup(CAMEL_STORE(imap_store)->folders, fi->full_name);
+                               if (folder)
+                                       fi->unread_message_count = camel_folder_get_unread_message_count(folder);
+                               else
+                                       fi->unread_message_count = -1;
+                               CAMEL_STORE_UNLOCK(imap_store, cache_lock);
                        }
 
                        if (fi->child)