* src/folder.c
[claws.git] / src / folder.c
index f81ba2422561c70246026102d9aa996b7596f90c..56f62db9e843a0f7175724a5e7764a5f8fb4eaf4 100644 (file)
@@ -885,7 +885,7 @@ static gint folder_sort_cache_list_by_msgnum(gconstpointer a, gconstpointer b)
 static gint folder_sort_folder_list(gconstpointer a, gconstpointer b)
 {
        guint gint_a = GPOINTER_TO_INT(a);
-       guint gint_b = GPOINTER_TO_INT(a);
+       guint gint_b = GPOINTER_TO_INT(b);
        
        return (gint_a - gint_b);
 }
@@ -894,9 +894,8 @@ gint folder_item_scan(FolderItem *item)
 {
        Folder *folder;
        GSList *folder_list, *cache_list, *folder_list_cur, *cache_list_cur, *new_list = NULL;
-       guint max = 0;
        guint newcnt = 0, unreadcnt = 0, totalcnt = 0;
-       guint cache_max_num, cache_cur_num, folder_cur_num, cache_max;
+       guint cache_max_num, folder_max_num, cache_cur_num, folder_cur_num;
 
        g_return_val_if_fail(item != NULL, -1);
        if (item->path == NULL) return -1;
@@ -935,16 +934,23 @@ gint folder_item_scan(FolderItem *item)
                cache_cur_num = ((MsgInfo *)cache_list_cur->data)->msgnum;
                cache_list_last = g_slist_last(cache_list);
                cache_max_num = ((MsgInfo *)cache_list_last->data)->msgnum;
-       } else
+       } else {
                cache_cur_num = G_MAXINT;
+               cache_max_num = 0;
+       }
 
-       if (folder_list_cur != NULL)
+       if (folder_list_cur != NULL) {
+               GSList *folder_list_last;
+       
                folder_cur_num = GPOINTER_TO_INT(folder_list_cur->data);
-       else
+               folder_list_last = g_slist_last(folder_list);
+               folder_max_num = GPOINTER_TO_INT(folder_list_last->data);
+       } else {
                folder_cur_num = G_MAXINT;
+               folder_max_num = 0;
+       }
 
        while ((cache_cur_num != G_MAXINT) || (folder_cur_num != G_MAXINT)) {
-               printf("%d %d\n", cache_cur_num, folder_cur_num);
                /*
                 *  Message only exists in the folder
                 *  Remember message for fetching
@@ -954,10 +960,16 @@ gint folder_item_scan(FolderItem *item)
 
                        switch(folder->type) {
                                case F_NEWS:
-                                       if ((folder_cur_num > cache_max) && 
-                                          ((prefs_common.max_articles == 0) ||
-                                           (max < prefs_common.max_articles) ||
-                                           (folder_cur_num > (max - prefs_common.max_articles)))) {
+                                       if (folder_cur_num < cache_max_num)
+                                               break;
+                                       
+                                       if (prefs_common.max_articles == 0) {
+                                               add = TRUE;
+                                       }
+
+                                       if (folder_max_num <= prefs_common.max_articles) {
+                                               add = TRUE;
+                                       } else if (folder_cur_num > (folder_max_num - prefs_common.max_articles)) {
                                                add = TRUE;
                                        }
                                        break;