more revision of filtering system
[claws.git] / src / folder.c
index ea643a5305b20f204c28dbbbe70521ae33d6834c..ca10f0e70d5444d36a70d94881db9c59b6c0ab0d 100644 (file)
@@ -156,7 +156,7 @@ FolderItem *folder_item_new(const gchar *name, const gchar *path)
        item->no_sub = FALSE;
        item->no_select = FALSE;
        item->collapsed = FALSE;
-       item->threaded  = FALSE;
+       item->threaded  = TRUE;
        item->ret_rcpt  = FALSE;
        item->parent = NULL;
        item->folder = NULL;
@@ -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;
@@ -814,6 +862,23 @@ gint folder_item_remove_msg(FolderItem *item, gint num)
        return ret;
 }
 
+gint folder_item_remove_msgs(FolderItem *item, GSList *msglist)
+{
+       gint ret = 0;
+
+       g_return_val_if_fail(item != NULL, -1);
+
+       while (msglist != NULL) {
+               MsgInfo *msginfo = (MsgInfo *)msglist->data;
+
+               ret = folder_item_remove_msg(item, msginfo->msgnum);
+               if (ret != 0) break;
+               msglist = msglist->next;
+       }
+
+       return ret;
+}
+
 gint folder_item_remove_all_msg(FolderItem *item)
 {
        Folder *folder;
@@ -1042,7 +1107,7 @@ static gboolean folder_build_tree(GNode *node, gpointer data)
        const gchar *path = NULL;
        PrefsAccount *account = NULL;
        gboolean no_sub = FALSE, no_select = FALSE, collapsed = FALSE, 
-                threaded = FALSE, ret_rcpt = FALSE;
+                threaded = TRUE, ret_rcpt = FALSE;
        gint mtime = 0, new = 0, unread = 0, total = 0;
 
        g_return_val_if_fail(node->data != NULL, FALSE);
@@ -1141,7 +1206,7 @@ static gboolean folder_read_folder_func(GNode *node, gpointer data)
        const gchar *name = NULL;
        const gchar *path = NULL;
        PrefsAccount *account = NULL;
-       gboolean collapsed = FALSE, threaded = FALSE, ret_rcpt = FALSE;
+       gboolean collapsed = FALSE, threaded = TRUE, ret_rcpt = FALSE;
 
        if (g_node_depth(node) != 2) return FALSE;
        g_return_val_if_fail(node->data != NULL, FALSE);
@@ -1249,8 +1314,6 @@ static void folder_write_list_recursive(GNode *node, gpointer data)
                                folder->account->account_id);
                if (item->collapsed && node->children)
                        fputs(" collapsed=\"1\"", fp);
-               if (item->threaded)
-                       fputs(" threaded=\"1\"", fp);
                if (item->ret_rcpt) 
                        fputs(" reqretrcpt=\"1\"", fp);
        } else {
@@ -1277,10 +1340,12 @@ static void folder_write_list_recursive(GNode *node, gpointer data)
                        fputs(" collapsed=\"1\"", fp);
                if (item->threaded)
                        fputs(" threaded=\"1\"", fp);
+               else
+                       fputs(" threaded=\"0\"", fp);
                if (item->ret_rcpt)
                        fputs(" reqretrcpt=\"1\"", fp);
                fprintf(fp,
-                       " mtime=\"%ld\" new=\"%d\" unread=\"%d\" total=\"%d\"",
+                       " mtime=\"%lu\" new=\"%d\" unread=\"%d\" total=\"%d\"",
                        item->mtime, item->new, item->unread, item->total);
        }
 
@@ -1407,18 +1472,14 @@ static gchar * folder_item_get_tree_identifier(FolderItem * item)
 
 gchar * folder_item_get_identifier(FolderItem * item)
 {
-       gchar * path;
        gchar * id;
        gchar * folder_str;
 
-       folder_str = folder_get_identifier(item->folder);
-
-       if (item->path == NULL) {
-               g_free(folder_str);
-               return NULL;
-       }
+       g_return_val_if_fail(item->path != NULL, NULL);
 
+       folder_str = folder_get_identifier(item->folder);
        id = g_strconcat(folder_str, "/", item->path, NULL);
+       g_free(folder_str);
 
        return id;
 }
@@ -1447,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 */
 
@@ -1486,3 +1546,51 @@ FolderItem * folder_find_item_from_identifier(const gchar *identifier)
                        folder_item_find_func, d);
        return d[1];
 }
+
+/* CLAWS: temporary local folder for filtering */
+
+static Folder *processing_folder;
+static FolderItem *processing_folder_item;
+
+static void folder_create_processing_folder(void)
+{
+#define PROCESSING_FOLDER ".processing"        
+       Folder     *tmpparent;
+       FolderItem *tmpfolder;
+       gchar      *tmpname;
+
+       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);
+
+       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);
+       }
+       g_free(tmpname);
+}
+
+FolderItem *folder_get_default_processing(void)
+{
+       if (!processing_folder_item) {
+               folder_create_processing_folder();
+       }
+       return processing_folder_item;
+}
+