* src/folder.[ch]
authorChristoph Hohmann <reboot@gmx.ch>
Fri, 18 Oct 2002 10:02:51 +0000 (10:02 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Fri, 18 Oct 2002 10:02:51 +0000 (10:02 +0000)
* src/imap.c
* src/mbox_folder.c
* src/mh.c
* src/news.c
        folder->get_num_list now returns an error code
        (closes bug [ 609424 ] News cache cleared on failure)

ChangeLog.claws
configure.in
src/folder.c
src/folder.h
src/imap.c
src/mbox_folder.c
src/mh.c
src/news.c

index e350646..c8c8341 100644 (file)
@@ -1,3 +1,13 @@
+2002-10-18 [christoph] 0.8.5claws43
+
+       * src/folder.[ch]
+       * src/imap.c
+       * src/mbox_folder.c
+       * src/mh.c
+       * src/news.c
+               folder->get_num_list now returns an error code
+               (closes bug [ 609424 ] News cache cleared on failure)
+               
 2002-10-17 [colin]     0.8.5claws42
        
        * src/news.c
index e67866e..36f9cea 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=5
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws42
+EXTRA_VERSION=claws43
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index e5d9f89..675a43f 100644 (file)
@@ -938,7 +938,7 @@ static gint folder_sort_folder_list(gconstpointer a, gconstpointer b)
 gint folder_item_scan(FolderItem *item)
 {
        Folder *folder;
-       GSList *folder_list, *cache_list, *folder_list_cur, *cache_list_cur, *new_list = NULL;
+       GSList *folder_list = NULL, *cache_list = NULL, *folder_list_cur, *cache_list_cur, *new_list = NULL;
        guint newcnt = 0, unreadcnt = 0, totalcnt = 0;
        guint cache_max_num, folder_max_num, cache_cur_num, folder_cur_num;
 
@@ -953,8 +953,13 @@ gint folder_item_scan(FolderItem *item)
        debug_print("Scanning folder %s for cache changes.\n", item->path);
 
        /* Get list of messages for folder and cache */
+       if (folder->get_num_list(item->folder, item, &folder_list) < 0) {
+               debug_print("Error fetching list of message numbers\n");
+               return(-1);
+       }
+
        if (!folder->check_msgnum_validity || 
-          folder->check_msgnum_validity(folder, item)) {
+           folder->check_msgnum_validity(folder, item)) {
                if (!item->cache)
                        folder_item_read_cache(item);
                cache_list = msgcache_get_msg_list(item->cache);
@@ -964,7 +969,6 @@ gint folder_item_scan(FolderItem *item)
                item->cache = msgcache_new();
                cache_list = NULL;
        }
-       folder_list = folder->get_num_list(item->folder, item);
 
        /* Sort both lists */
        cache_list = g_slist_sort(cache_list, folder_sort_cache_list_by_msgnum);
index 2620c89..e95cd0a 100644 (file)
@@ -173,8 +173,9 @@ struct _Folder
                                         FolderItem     *item,
                                         MsgInfo        *msginfo);
        gint     (*scan)                (Folder         *folder);
-       GSList  * (*get_num_list)       (Folder         *folder,
-                                        FolderItem     *item);
+       gint     (*get_num_list)        (Folder         *folder,
+                                        FolderItem     *item,
+                                        GSList        **list);
        void     (*scan_tree)           (Folder         *folder);
 
        gint     (*create_tree)         (Folder         *folder);
index 2024a5a..a193a3d 100644 (file)
@@ -283,8 +283,9 @@ static gchar *imap_locale_to_modified_utf7  (const gchar    *from);
 
 static gboolean imap_rename_folder_func                (GNode          *node,
                                                 gpointer        data);
-GSList *imap_get_num_list                      (Folder         *folder,
-                                                FolderItem     *item);
+gint imap_get_num_list                         (Folder         *folder,
+                                                FolderItem     *item,
+                                                GSList        **list);
 MsgInfo *imap_fetch_msginfo                    (Folder         *folder,
                                                 FolderItem     *item,
                                                 gint            num);
@@ -3201,31 +3202,30 @@ static gboolean imap_rename_folder_func(GNode *node, gpointer data)
        return FALSE;
 }
 
-GSList *imap_get_num_list(Folder *folder, FolderItem *_item)
+gint imap_get_num_list(Folder *folder, FolderItem *_item, GSList **msgnum_list)
 {
        IMAPFolderItem *item = (IMAPFolderItem *)_item;
        IMAPSession *session;
-       GSList *msgnum_list = NULL;
-       gint i, lastuid_old;
+       gint i, lastuid_old, nummsgs = 0;
        gint ok, exists = 0, recent = 0, unseen = 0;
        guint32 uid_validity = 0;
        GPtrArray *argbuf;
        gchar *cmdbuf = NULL;
        gchar *dir;
        
-       g_return_val_if_fail(folder != NULL, NULL);
-       g_return_val_if_fail(item != NULL, NULL);
-       g_return_val_if_fail(item->item.path != NULL, NULL);
-       g_return_val_if_fail(folder->type == F_IMAP, NULL);
-       g_return_val_if_fail(folder->account != NULL, NULL);
+       g_return_val_if_fail(folder != NULL, -1);
+       g_return_val_if_fail(item != NULL, -1);
+       g_return_val_if_fail(item->item.path != NULL, -1);
+       g_return_val_if_fail(folder->type == F_IMAP, -1);
+       g_return_val_if_fail(folder->account != NULL, -1);
 
        session = imap_session_get(folder);
-       g_return_val_if_fail(session != NULL, NULL);
+       g_return_val_if_fail(session != NULL, -1);
 
        ok = imap_select(session, IMAP_FOLDER(folder), item->item.path,
                         &exists, &recent, &unseen, &uid_validity);
        if (ok != IMAP_SUCCESS)
-               return NULL;
+               return -1;
 
        argbuf = g_ptr_array_new();
        if(item->lastuid) {
@@ -3239,19 +3239,20 @@ GSList *imap_get_num_list(Folder *folder, FolderItem *_item)
        if (ok != IMAP_SUCCESS) {
                ptr_array_free_strings(argbuf);
                g_ptr_array_free(argbuf, TRUE);
-               return NULL;
+               return -1;
        }
 
        lastuid_old = item->lastuid;
-       msgnum_list = g_slist_copy(item->uid_list);
-       debug_print("Got %d uids from cache\n", g_slist_length(msgnum_list));
+       *msgnum_list = g_slist_copy(item->uid_list);
+       debug_print("Got %d uids from cache\n", g_slist_length(item->uid_list));
        for(i = 0; i < argbuf->len; i++) {
                int ret, msgidx, msgnum;
        
                if((ret = sscanf(g_ptr_array_index(argbuf, i), "%d FETCH (UID %d)", &msgidx, &msgnum)) == 2) {
                        if(msgnum > lastuid_old) {
-                               msgnum_list = g_slist_prepend(msgnum_list, GINT_TO_POINTER(msgnum));
+                               *msgnum_list = g_slist_prepend(*msgnum_list, GINT_TO_POINTER(msgnum));
                                item->uid_list = g_slist_prepend(item->uid_list, GINT_TO_POINTER(msgnum));
+                               nummsgs++;
 
                                if(msgnum > item->lastuid)
                                        item->lastuid = msgnum;
@@ -3261,10 +3262,10 @@ GSList *imap_get_num_list(Folder *folder, FolderItem *_item)
 
        dir = folder_item_get_path((FolderItem *)item);
        debug_print("removing old messages from %s\n", dir);
-       remove_numbered_files_not_in_list(dir, msgnum_list);
+       remove_numbered_files_not_in_list(dir, *msgnum_list);
        g_free(dir);
 
-       return msgnum_list;
+       return nummsgs;
 }
 
 MsgInfo *imap_fetch_msginfo(Folder *_folder, FolderItem *item, gint num)
index 7f786e2..12f1af4 100644 (file)
@@ -47,7 +47,7 @@ static gchar * mbox_get_new_path(FolderItem * parent, gchar * name);
 static gchar * mbox_get_folderitem_name(gchar * name);
 
 MsgInfo *mbox_fetch_msginfo(Folder *folder, FolderItem *item, gint num);
-GSList *mbox_get_num_list(Folder *folder, FolderItem *item);
+gint mbox_get_num_list(Folder *folder, FolderItem *item, GSList **list);
 gboolean mbox_check_msgnum_validity(Folder *folder, FolderItem *item);
 
 Folder *mbox_folder_new(const gchar *name, const gchar *path)
@@ -2248,19 +2248,17 @@ gint mbox_remove_folder(Folder *folder, FolderItem *item)
        return 0;
 }
 
-GSList *mbox_get_num_list(Folder *folder, FolderItem *item)
+gint mbox_get_num_list(Folder *folder, FolderItem *item, GSList **mlist)
 {
-       GSList *mlist;
        GList * l;
        FILE * fp;
        gchar * mbox_path;
-
-       mlist = NULL;
+       gint nummsgs = 0;
 
        mbox_path = mbox_folder_get_path(item);
 
        if (mbox_path == NULL)
-               return NULL;
+               return -1;
 
        mbox_purge_deleted(mbox_path);
 
@@ -2268,7 +2266,7 @@ GSList *mbox_get_num_list(Folder *folder, FolderItem *item)
        
        if (fp == NULL) {
                g_free(mbox_path);
-               return NULL;
+               return -1;
        }
 
        mbox_lockread_file(fp, mbox_path);
@@ -2284,7 +2282,8 @@ GSList *mbox_get_num_list(Folder *folder, FolderItem *item)
                msg = (struct _message *) l->data;
 
                if (MSG_IS_INVALID(msg->flags) || !MSG_IS_REALLY_DELETED(msg->flags)) {
-                       mlist = g_slist_append(mlist, GINT_TO_POINTER(msg->msgnum));
+                       *mlist = g_slist_append(*mlist, GINT_TO_POINTER(msg->msgnum));
+                       nummsgs++;
                } else {
                        MSG_SET_PERM_FLAGS(msg->flags, MSG_REALLY_DELETED);
                }
@@ -2296,7 +2295,7 @@ GSList *mbox_get_num_list(Folder *folder, FolderItem *item)
 
        fclose(fp);
 
-       return mlist;
+       return nummsgs;
 }
 
 MsgInfo *mbox_fetch_msginfo(Folder *folder, FolderItem *item, gint num)
index 6187ca0..f1fa3b3 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -83,8 +83,9 @@ gboolean mh_is_msg_changed    (Folder         *folder,
 
 gint    mh_scan_folder         (Folder         *folder,
                                 FolderItem     *item);
-GSList *mh_get_num_list                (Folder         *folder,
-                                FolderItem     *item);
+gint mh_get_num_list           (Folder         *folder,
+                                FolderItem     *item,
+                                GSList        **list);
 void    mh_scan_tree           (Folder         *folder);
 
 gint    mh_create_tree         (Folder         *folder);
@@ -191,43 +192,43 @@ void mh_get_last_num(Folder *folder, FolderItem *item)
        item->last_num = max;
 }
 
-GSList *mh_get_num_list(Folder *folder, FolderItem *item)
+gint mh_get_num_list(Folder *folder, FolderItem *item, GSList **list)
 {
 
        gchar *path;
        DIR *dp;
        struct dirent *d;
        struct stat s;
-       gint num;
-       GSList *list = NULL;
+       gint num, nummsgs = 0;
 
-       g_return_val_if_fail(item != NULL, NULL);
+       g_return_val_if_fail(item != NULL, -1);
 
        debug_print("mh_get_last_num(): Scanning %s ...\n", item->path);
 
        path = folder_item_get_path(item);
-       g_return_val_if_fail(path != NULL, NULL);
+       g_return_val_if_fail(path != NULL, -1);
        if (change_dir(path) < 0) {
                g_free(path);
-               return NULL;
+               return -1;
        }
        g_free(path);
 
        if ((dp = opendir(".")) == NULL) {
                FILE_OP_ERROR(item->path, "opendir");
-               return NULL;
+               return -1;
        }
 
        while ((d = readdir(dp)) != NULL) {
                if ((num = to_number(d->d_name)) >= 0 &&
                    stat(d->d_name, &s) == 0 &&
                    S_ISREG(s.st_mode)) {
-                       list = g_slist_prepend(list, GINT_TO_POINTER(num));
+                       *list = g_slist_prepend(*list, GINT_TO_POINTER(num));
+                   nummsgs++;
                }
        }
        closedir(dp);
 
-       return list;
+       return nummsgs;
 }
 
 GSList *mh_get_msg_list(Folder *folder, FolderItem *item, gboolean use_cache)
index 9015cbe..d634c66 100644 (file)
@@ -104,8 +104,9 @@ static void news_delete_expired_caches       (GSList        *alist,
 static gint news_remove_msg             (Folder        *folder, 
                                          FolderItem    *item, 
                                          gint           num);
-GSList *news_get_num_list               (Folder        *folder, 
-                                         FolderItem    *item);
+gint news_get_num_list                  (Folder        *folder, 
+                                         FolderItem    *item,
+                                         GSList       **list);
 MsgInfo *news_fetch_msginfo             (Folder        *folder, 
                                          FolderItem    *item,
                                          gint           num);
@@ -1047,33 +1048,34 @@ gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
        return 0;
 }
 
-GSList *news_get_num_list(Folder *folder, FolderItem *item)
+gint news_get_num_list(Folder *folder, FolderItem *item, GSList **msgnum_list)
 {
        NNTPSession *session;
-       gint i, ok, num, first, last;
-       GSList *msgnum_list = NULL;
+       gint i, ok, num, first, last, nummsgs = 0;
        gchar *dir;
 
+       g_return_val_if_fail(item != NULL, -1);
+       g_return_val_if_fail(item->folder != NULL, -1);
+       g_return_val_if_fail(item->folder->type == F_NEWS, -1);
+
        session = news_session_get(folder);
-       g_return_val_if_fail(session != NULL, NULL);
-       g_return_val_if_fail(item != NULL, NULL);
-       g_return_val_if_fail(item->folder != NULL, NULL);
-       g_return_val_if_fail(item->folder->type == F_NEWS, NULL);
+       g_return_val_if_fail(session != NULL, -1);
 
        ok = news_select_group(session, item->path, &num, &first, &last);
        if (ok != NN_SUCCESS) {
                log_warning(_("can't set group: %s\n"), item->path);
-               return NULL;
+               return -1;
        }
 
        if(last < first) {
                log_warning(_("invalid article range: %d - %d\n"),
                            first, last);
-               return NULL;
+               return 0;
        }
 
        for(i = first; i <= last; i++) {
-               msgnum_list = g_slist_prepend(msgnum_list, GINT_TO_POINTER(i));
+               *msgnum_list = g_slist_prepend(*msgnum_list, GINT_TO_POINTER(i));
+               nummsgs++;
        }
 
        dir = folder_item_get_path(item);
@@ -1081,7 +1083,7 @@ GSList *news_get_num_list(Folder *folder, FolderItem *item)
        remove_numbered_files(dir, 1, first - 1);
        g_free(dir);
 
-       return msgnum_list;
+       return nummsgs;
 }
 
 #define READ_TO_LISTEND(hdr) \