handle menu option 'filter messages' / bugfix in mbox folders
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Wed, 30 May 2001 03:05:08 +0000 (03:05 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Wed, 30 May 2001 03:05:08 +0000 (03:05 +0000)
ChangeLog.claws
src/filtering.c
src/filtering.h
src/folder.c
src/folder.h
src/foldersel.c
src/mbox_folder.c
src/summaryview.c

index 9d3a78a..8fe2f07 100644 (file)
@@ -1,3 +1,18 @@
+2001-05-30 [hoa]
+
+       * src/filtering.[ch]
+       * src/summaryview.c
+               handling summary menu / filter messages
+
+       * src/folder.[ch]
+               add some stuff
+
+       * src/foldersel.c
+               imap folders now appears in list
+
+       * src/mbox_folder.c
+               doesn't crash if destination mail is not writeable
+
 2001-05-29 [hoa]
 
        * src/compose.c
index 19aed45..69020d7 100644 (file)
@@ -233,19 +233,21 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
                info->flags = 0;
                filteringaction_update_mark(info);
                
-               val = GPOINTER_TO_INT(g_hash_table_lookup
-                                     (folder_table, dest_folder));
-               if (val == 0) {
-                       folder_item_scan(dest_folder);
-                       g_hash_table_insert(folder_table, dest_folder,
-                                           GINT_TO_POINTER(1));
-               }
-               val = GPOINTER_TO_INT(g_hash_table_lookup
-                                     (folder_table, info->folder));
-               if (val == 0) {
-                       folder_item_scan(info->folder);
-                       g_hash_table_insert(folder_table, info->folder,
-                                           GINT_TO_POINTER(1));
+               if (folder_table) {
+                       val = GPOINTER_TO_INT(g_hash_table_lookup
+                                             (folder_table, dest_folder));
+                       if (val == 0) {
+                               folder_item_scan(dest_folder);
+                               g_hash_table_insert(folder_table, dest_folder,
+                                                   GINT_TO_POINTER(1));
+                       }
+                       val = GPOINTER_TO_INT(g_hash_table_lookup
+                                             (folder_table, info->folder));
+                       if (val == 0) {
+                               folder_item_scan(info->folder);
+                               g_hash_table_insert(folder_table, info->folder,
+                                                   GINT_TO_POINTER(1));
+                       }
                }
 
                return TRUE;
@@ -259,14 +261,16 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info,
                if (folder_item_copy_msg(dest_folder, info) == -1)
                        return FALSE;
 
-               val = GPOINTER_TO_INT(g_hash_table_lookup
-                                     (folder_table, dest_folder));
-               if (val == 0) {
-                       folder_item_scan(dest_folder);
-                       g_hash_table_insert(folder_table, dest_folder,
-                                           GINT_TO_POINTER(1));
+               if (folder_table) {
+                       val = GPOINTER_TO_INT(g_hash_table_lookup
+                                             (folder_table, dest_folder));
+                       if (val == 0) {
+                               folder_item_scan(dest_folder);
+                               g_hash_table_insert(folder_table, dest_folder,
+                                                   GINT_TO_POINTER(1));
+                       }
                }
-
+                       
                return TRUE;
 
        case MATCHING_ACTION_DELETE:
@@ -423,6 +427,28 @@ void filter_msginfo(GSList * filtering_list, MsgInfo * info,
        }
 }
 
+void filter_msginfo_move_or_delete(GSList * filtering_list, MsgInfo * info,
+                                  GHashTable *folder_table)
+{
+       GSList * l;
+
+       if (info == NULL) {
+               g_warning(_("msginfo is not set"));
+               return;
+       }
+       
+       for(l = filtering_list ; l != NULL ; l = g_slist_next(l)) {
+               FilteringProp * filtering = (FilteringProp *) l->data;
+
+               switch (filtering->action->type) {
+               case MATCHING_ACTION_MOVE:
+               case MATCHING_ACTION_DELETE:
+                       if (filteringprop_apply(filtering, info, folder_table))
+                               return;
+               }
+       }
+}
+
 void filter_message(GSList * filtering_list, FolderItem * item,
                    gint msgnum, GHashTable *folder_table)
 {
index f8bf063..d4ef0c0 100644 (file)
@@ -38,6 +38,8 @@ FilteringProp * filteringprop_parse(gchar ** str);
 
 void filter_msginfo(GSList * filtering_list, MsgInfo * info,
                    GHashTable *folder_table);
+void filter_msginfo_move_or_delete(GSList * filtering_list, MsgInfo * info,
+                                  GHashTable *folder_table);
 void filter_message(GSList * filtering_list, FolderItem * item,
                    gint msgnum, GHashTable *folder_table);
 
index 4c148ad..6c1427b 100644 (file)
@@ -780,6 +780,7 @@ gint folder_item_copy_msgs_with_dest(FolderItem *dest, GSList *msglist)
 gint folder_item_remove_msg(FolderItem *item, gint num)
 {
        Folder *folder;
+       gint result;
 
        g_return_val_if_fail(item != NULL, -1);
 
@@ -788,14 +789,25 @@ gint folder_item_remove_msg(FolderItem *item, gint num)
        g_return_val_if_fail(folder->scan != NULL, -1);
        g_return_val_if_fail(folder->remove_msg != NULL, -1);
 
+       if (folder->finished_remove)
+               folder->finished_remove(folder, item);
+
+       result = folder->remove_msg(folder, item, num);
+
        if (item->last_num < 0) folder->scan(folder, item);
 
-       return folder->remove_msg(folder, item, num);
+       if (result == 0){
+               if (folder->finished_remove)
+                       folder->finished_remove(folder, item);
+       }
+
+       return result;
 }
 
 gint folder_item_remove_all_msg(FolderItem *item)
 {
        Folder *folder;
+       gint result;
 
        g_return_val_if_fail(item != NULL, -1);
 
@@ -806,7 +818,14 @@ gint folder_item_remove_all_msg(FolderItem *item)
 
        if (item->last_num < 0) folder->scan(folder, item);
 
-       return folder->remove_all_msg(folder, item);
+       result = folder->remove_all_msg(folder, item);
+
+       if (result == 0){
+               if (folder->finished_remove)
+                       folder->finished_remove(folder, item);
+       }
+
+       return result;
 }
 
 gboolean folder_item_is_msg_changed(FolderItem *item, MsgInfo *msginfo)
@@ -913,7 +932,11 @@ static void folder_init(Folder *folder, FolderType type, const gchar *name)
                folder->remove_all_msg      = imap_remove_all_msg;
                folder->scan                = imap_scan_folder;
                folder->create_folder       = imap_create_folder;
-               folder->remove_folder       = imap_remove_folder;               
+               folder->remove_folder       = imap_remove_folder;
+               /*
+               folder->copy_msg            = imap_copy_msg;
+               folder->finished_remove     = imap_finished_remove;
+               */
                break;
        case F_NEWS:
                folder->get_msg_list        = news_get_article_list;
index 7c7706f..321e068 100644 (file)
@@ -149,6 +149,7 @@ struct _Folder
                                         FolderItem     *item,
                                         MsgInfo        *info);
        void     (*finished_copy)       (Folder * folder, FolderItem * item);
+       void     (*finished_remove)       (Folder * folder, FolderItem * item);
 };
 
 struct _LocalFolder
index 6171869..6182a88 100644 (file)
@@ -232,7 +232,8 @@ static void foldersel_set_tree(void)
                folder = FOLDER(list->data);
                g_return_if_fail(folder != NULL);
 
-               if ((folder->type != F_MH) && (folder->type != F_MBOX))
+               if ((folder->type != F_MH) && (folder->type != F_MBOX) &&
+                   (folder->type != F_IMAP))
                        continue;
 
                node = gtk_ctree_insert_gnode(GTK_CTREE(ctree), NULL, NULL,
index d536923..0ee5e62 100644 (file)
@@ -1608,6 +1608,9 @@ gint mbox_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
        g_free(mbox_path);
        */
 
+       if (num == -1)
+               return -1;
+
        flags_info = g_new0(CopyFlagsInfo, 1);
        flags_info->num = num;
        flags_info->flags = msginfo->flags;
index 4b543cc..aceea41 100644 (file)
@@ -74,6 +74,7 @@
 #include "addr_compl.h"
 #include "scoring.h"
 #include "prefs_folder_item.h"
+#include "filtering.h"
 
 #include "pixmaps/dir-open.xpm"
 #include "pixmaps/mark.xpm"
@@ -2686,16 +2687,35 @@ void summary_filter(SummaryView *summaryview)
 
        gtk_clist_freeze(GTK_CLIST(summaryview->ctree));
 
-       gtk_ctree_pre_recursive(GTK_CTREE(summaryview->ctree), NULL,
-                               GTK_CTREE_FUNC(summary_filter_func),
-                               summaryview);
+       if (prefs_filtering == NULL) {
+               gtk_ctree_pre_recursive(GTK_CTREE(summaryview->ctree), NULL,
+                                       GTK_CTREE_FUNC(summary_filter_func),
+                                       summaryview);
+               
+               gtk_clist_thaw(GTK_CLIST(summaryview->ctree));
 
-       gtk_clist_thaw(GTK_CLIST(summaryview->ctree));
+               if (prefs_common.immediate_exec)
+                       summary_execute(summaryview);
+               else
+                       summary_status_show(summaryview);
+       }
+       else {
+               summaryview->folder_table = g_hash_table_new(NULL, NULL);
 
-       if (prefs_common.immediate_exec)
-               summary_execute(summaryview);
-       else
-               summary_status_show(summaryview);
+               gtk_ctree_pre_recursive(GTK_CTREE(summaryview->ctree), NULL,
+                                       GTK_CTREE_FUNC(summary_filter_func),
+                                       summaryview);
+
+               gtk_clist_thaw(GTK_CLIST(summaryview->ctree));
+
+               folder_item_scan_foreach(summaryview->folder_table);
+               folderview_update_item_foreach(summaryview->folder_table);
+
+               g_hash_table_destroy(summaryview->folder_table);
+               summaryview->folder_table = NULL;
+
+               summary_show(summaryview, summaryview->folder_item, FALSE);
+       }
 
        debug_print(_("done.\n"));
        STATUSBAR_POP(summaryview->mainwin);
@@ -2710,13 +2730,19 @@ static void summary_filter_func(GtkCTree *ctree, GtkCTreeNode *node,
        gchar *file;
        FolderItem *dest;
 
-       file = procmsg_get_message_file_path(msginfo);
-       dest = filter_get_dest_folder(prefs_common.fltlist, file);
-       g_free(file);
+       if (prefs_filtering == NULL) {
+               /* old filtering */
+               file = procmsg_get_message_file_path(msginfo);
+               dest = filter_get_dest_folder(prefs_common.fltlist, file);
+               g_free(file);
 
-       if (dest && strcmp2(dest->path, FILTER_NOT_RECEIVE) != 0 &&
-           summaryview->folder_item != dest)
-               summary_move_row_to(summaryview, node, dest);
+               if (dest && strcmp2(dest->path, FILTER_NOT_RECEIVE) != 0 &&
+                   summaryview->folder_item != dest)
+                       summary_move_row_to(summaryview, node, dest);
+       }
+       else
+               filter_msginfo_move_or_delete(prefs_filtering, msginfo,
+                                             summaryview->folder_table);
 }
 
 /* callback functions */