more revision of filtering system
[claws.git] / src / folder.c
index 55ea06b74fe32d4ac61fd4af6c3dd0d0b5be7177..ca10f0e70d5444d36a70d94881db9c59b6c0ab0d 100644 (file)
@@ -361,6 +361,54 @@ void folder_write_list(void)
                g_warning("failed to write folder list.\n");
 }
 
+struct TotalMsgCount
+{
+       guint new;
+       guint unread;
+       guint total;
+};
+
+static gboolean folder_count_total_msgs_func(GNode *node, gpointer data)
+{
+       FolderItem *item;
+       struct TotalMsgCount *count = (struct TotalMsgCount *)data;
+
+       g_return_val_if_fail(node->data != NULL, FALSE);
+
+       item = FOLDER_ITEM(node->data);
+       count->new += item->new;
+       count->unread += item->unread;
+       count->total += item->total;
+
+       return FALSE;
+}
+
+void folder_count_total_msgs(guint *new, guint *unread, guint *total)
+{
+       GList *list;
+       Folder *folder;
+       struct TotalMsgCount count;
+
+       count.new = count.unread = count.total = 0;
+
+       debug_print(_("Counting total number of messages...\n"));
+
+       for (list = folder_list; list != NULL; list = list->next) {
+               folder = FOLDER(list->data);
+               if (folder->node)
+                       g_node_traverse(folder->node, G_PRE_ORDER,
+                                       G_TRAVERSE_ALL, -1,
+                                       folder_count_total_msgs_func,
+                                       &count);
+       }
+
+       *new = count.new;
+       *unread = count.unread;
+       *total = count.total;
+
+       return;
+}
+
 Folder *folder_find_from_path(const gchar *path)
 {
        GList *list;
@@ -1460,8 +1508,7 @@ FolderItem * folder_find_item_from_identifier(const gchar *identifier)
        gchar * name;
        gchar * path;
 
-       Xalloca(str, strlen(identifier) + 1, return NULL);
-       strcpy(str, identifier);
+       Xstrdup_a(str, identifier, return NULL);
 
        /* extract box type */
 
@@ -1500,40 +1547,50 @@ FolderItem * folder_find_item_from_identifier(const gchar *identifier)
        return d[1];
 }
 
-static void folder_count_total_newmsgs_func(const GNode *node, guint *newmsgs, 
-                                           guint *unreadmsgs, guint *totalmsgs)
-{
-       if (node->data) {
-               FolderItem *item = node->data;
-               *newmsgs += item->new;
-               *unreadmsgs += item->unread;
-               *totalmsgs += item->total;
-       }
-       if (node->children)
-               folder_count_total_newmsgs_func(node->children, newmsgs, unreadmsgs, totalmsgs);
-       if (node->next)
-               folder_count_total_newmsgs_func(node->next, newmsgs, unreadmsgs, totalmsgs);
-}
+/* CLAWS: temporary local folder for filtering */
+
+static Folder *processing_folder;
+static FolderItem *processing_folder_item;
 
-void folder_count_total_msgs(guint *newmsgs, guint *unreadmsgs, guint *totalmsgs)
+static void folder_create_processing_folder(void)
 {
-       GList *list;
-       Folder *folder;
+#define PROCESSING_FOLDER ".processing"        
+       Folder     *tmpparent;
+       FolderItem *tmpfolder;
+       gchar      *tmpname;
 
-       *newmsgs = 0;
-       *unreadmsgs = 0;
-       *totalmsgs = 0;
+       tmpparent = folder_get_default_folder();
+       g_assert(tmpparent);
+       debug_print("tmpparentroot %s\n", LOCAL_FOLDER(tmpparent)->rootpath);
+       tmpname = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
+                             LOCAL_FOLDER(tmpparent)->rootpath,
+                             G_DIR_SEPARATOR_S, PROCESSING_FOLDER,
+                             NULL);
 
-       debug_print(_("Counting total number of messages...\n"));
-       list = folder_get_list();
-       for (; list != NULL; list = list->next) {
-               folder = FOLDER(list->data);
-               if (folder->node)
-                       folder_count_total_newmsgs_func(folder->node, newmsgs, unreadmsgs, totalmsgs);
+       processing_folder = folder_new(F_MH, "PROCESSING", LOCAL_FOLDER(tmpparent)->rootpath);
+       g_assert(processing_folder);
+                             
+       if (!is_dir_exist(tmpname)) {
+               debug_print("*TMP* creating %s\n", tmpname);
+               processing_folder_item = processing_folder->create_folder(processing_folder,
+                                                                         processing_folder->node->data,
+                                                                         PROCESSING_FOLDER);
+               g_assert(processing_folder_item);                                                                         
+       }
+       else {
+               debug_print("*TMP* already created\n");
+               processing_folder_item = folder_item_new(".processing", ".processing");
+               g_assert(processing_folder_item);
+               folder_item_append(processing_folder->node->data, processing_folder_item);
        }
-       debug_print(_("  New: %d\n"), *newmsgs);
-       debug_print(_("  Unread: %d\n"), *unreadmsgs);
-       debug_print(_("  Total: %d\n"), *totalmsgs);
+       g_free(tmpname);
+}
 
-       return;
+FolderItem *folder_get_default_processing(void)
+{
+       if (!processing_folder_item) {
+               folder_create_processing_folder();
+       }
+       return processing_folder_item;
 }
+