change English used in Alert when entry is not used
[claws.git] / src / prefs_filtering.c
index 0abc38e556a8c8250eb8d1864d76ead20926db25..24950e47bcbcce1f3aa4938116a99dbd949010a7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto and the Sylpheed-Claws team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@
 
 #include "intl.h"
 #include "main.h"
-#include "prefs.h"
+#include "prefs_gtk.h"
 #include "prefs_matcher.h"
 #include "prefs_filtering.h"
 #include "prefs_common.h"
 #include "folder.h"
 #include "filtering.h"
 #include "addr_compl.h"
-#include "labelcolors.h"
+#include "colorlabel.h"
+
+#include "matcher_parser.h"
+#include "matcher.h"
 
 static struct Filtering {
        GtkWidget *window;
@@ -57,6 +60,7 @@ static struct Filtering {
        GtkWidget *cond_entry;
        GtkWidget *action_list;
        GtkWidget *action_combo;
+       GtkWidget *account_label;
        GtkWidget *account_list;
        GtkWidget *account_combo;
        GtkWidget *dest_entry;
@@ -74,15 +78,11 @@ static struct Filtering {
        gint current_action;
 } filtering;
 
-#define VSPACING               12
-#define VSPACING_NARROW                4
-#define DEFAULT_ENTRY_WIDTH    80
-#define PREFSBUFSIZE           1024
-
 /* widget creating functions */
 static void prefs_filtering_create             (void);
 
-static void prefs_filtering_set_dialog (void);
+static void prefs_filtering_set_dialog (const gchar *header,
+                                        const gchar *key);
 static void prefs_filtering_set_list   (void);
 
 /* callback functions */
@@ -116,6 +116,10 @@ static void prefs_filtering_action_selection_changed(GtkList *list,
                                                     gpointer user_data);
                                          
 static void prefs_filtering_reset_dialog(void);
+static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data);
+static gboolean prefs_filtering_delete_path_func(GNode *node, gpointer data);
+
+static FolderItem * cur_item = NULL;
 
 enum {
        ACTION_MOVE = 0,
@@ -127,8 +131,10 @@ enum {
        ACTION_MARK_AS_UNREAD = 6,
        ACTION_FORWARD = 7,
        ACTION_FORWARD_AS_ATTACHMENT = 8,
-       ACTION_EXECUTE = 9,
-       ACTION_COLOR = 10
+       ACTION_REDIRECT = 9,
+       ACTION_EXECUTE = 10,
+       ACTION_COLOR = 11,
+       ACTION_DELETE_ON_SERVER = 12,
 };
 
 static gint get_sel_from_list(GtkList * list)
@@ -186,27 +192,31 @@ static gint prefs_filtering_get_matching_from_action(gint action_id)
 {
        switch(action_id) {
        case ACTION_MOVE:
-               return MATCHING_ACTION_MOVE;
+               return MATCHACTION_MOVE;
        case ACTION_COPY:
-               return MATCHING_ACTION_COPY;
+               return MATCHACTION_COPY;
        case ACTION_DELETE:
-               return MATCHING_ACTION_DELETE;
+               return MATCHACTION_DELETE;
        case ACTION_MARK:
-               return MATCHING_ACTION_MARK;
+               return MATCHACTION_MARK;
        case ACTION_UNMARK:
-               return MATCHING_ACTION_UNMARK;
+               return MATCHACTION_UNMARK;
        case ACTION_MARK_AS_READ:
-               return MATCHING_ACTION_MARK_AS_READ;
+               return MATCHACTION_MARK_AS_READ;
        case ACTION_MARK_AS_UNREAD:
-               return MATCHING_ACTION_MARK_AS_UNREAD;
+               return MATCHACTION_MARK_AS_UNREAD;
        case ACTION_FORWARD:
-               return MATCHING_ACTION_FORWARD;
+               return MATCHACTION_FORWARD;
        case ACTION_FORWARD_AS_ATTACHMENT:
-               return MATCHING_ACTION_FORWARD_AS_ATTACHMENT;
+               return MATCHACTION_FORWARD_AS_ATTACHMENT;
+       case ACTION_REDIRECT:
+               return MATCHACTION_REDIRECT;
        case ACTION_EXECUTE:
-               return MATCHING_EXECUTE;
+               return MATCHACTION_EXECUTE;
        case ACTION_COLOR:
-               return MATCHING_ACTION_COLOR;
+               return MATCHACTION_COLOR;
+       case ACTION_DELETE_ON_SERVER:
+               return MATCHACTION_DELETE_ON_SERVER;
        default:
                return -1;
        }
@@ -222,16 +232,22 @@ static gchar * action_text [] = {
        N_("Mark as unread"),
        N_("Forward"), 
        N_("Forward as attachment"), 
+       N_("Redirect"), 
        N_("Execute"),
-       N_("Color")
+       N_("Color"),
+       N_("Delete on Server")
 };
 
-void prefs_filtering_open(void)
+void prefs_filtering_open(FolderItem * item,
+                         const gchar *header,
+                         const gchar *key)
 {
+       gchar *esckey;
+
        if (prefs_rc_is_readonly(FILTERING_RC))
                return;
 
-       inc_autocheck_timer_remove();
+       inc_lock();
 
        if (!filtering.window) {
                prefs_filtering_create();
@@ -240,7 +256,11 @@ void prefs_filtering_open(void)
        manage_window_set_transient(GTK_WINDOW(filtering.window));
        gtk_widget_grab_focus(filtering.ok_btn);
 
-       prefs_filtering_set_dialog();
+       cur_item = item;
+
+       esckey = matcher_escape_str(key);
+       prefs_filtering_set_dialog(header, esckey);
+       g_free(esckey);
 
        gtk_widget_show(filtering.window);
 
@@ -253,6 +273,7 @@ static void prefs_filtering_close(void)
        end_address_completion();
        
        gtk_widget_hide(filtering.window);
+       inc_unlock();
 }
 
 static void prefs_filtering_create(void)
@@ -298,7 +319,6 @@ static void prefs_filtering_create(void)
        GtkWidget *up_btn;
        GtkWidget *down_btn;
 
-       GtkWidget *dummy;
 
        GList *combo_items;
        gint i;
@@ -306,9 +326,9 @@ static void prefs_filtering_create(void)
        GList *accounts;
        GList * cur;
 
-       gchar *title[] = {_("Registered rules")};
+       gchar *title[1];
 
-       debug_print(_("Creating filtering setting window...\n"));
+       debug_print("Creating filtering configuration window...\n");
 
        window = gtk_window_new (GTK_WINDOW_DIALOG);
        gtk_container_set_border_width (GTK_CONTAINER (window), 8);
@@ -327,15 +347,13 @@ static void prefs_filtering_create(void)
        gtk_widget_grab_default (ok_btn);
 
        gtk_window_set_title (GTK_WINDOW(window),
-                             _("Filtering setting"));
+                                   _("Filtering/Processing configuration"));
+
        gtk_signal_connect (GTK_OBJECT(window), "delete_event",
                            GTK_SIGNAL_FUNC(prefs_filtering_deleted), NULL);
        gtk_signal_connect (GTK_OBJECT(window), "key_press_event",
                            GTK_SIGNAL_FUNC(prefs_filtering_key_pressed), NULL);
-       gtk_signal_connect (GTK_OBJECT(window), "focus_in_event",
-                           GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
-       gtk_signal_connect (GTK_OBJECT(window), "focus_out_event",
-                           GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
+       MANAGE_WINDOW_SIGNALS_CONNECT (window);
        gtk_signal_connect (GTK_OBJECT(ok_btn), "clicked",
                            GTK_SIGNAL_FUNC(prefs_filtering_ok), NULL);
        gtk_signal_connect (GTK_OBJECT(cancel_btn), "clicked",
@@ -358,7 +376,6 @@ static void prefs_filtering_create(void)
 
        cond_entry = gtk_entry_new ();
        gtk_widget_show (cond_entry);
-//     gtk_widget_set_usize (cond_entry, 200, -1);
        gtk_box_pack_start (GTK_BOX (hbox1), cond_entry, TRUE, TRUE, 0);
 
        cond_btn = gtk_button_new_with_label (_("Define ..."));
@@ -380,7 +397,6 @@ static void prefs_filtering_create(void)
 
        action_combo = gtk_combo_new ();
        gtk_widget_show (action_combo);
-//     gtk_widget_set_usize (action_combo, 200, -1);
        gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(action_combo)->entry),
                               FALSE);
 
@@ -470,13 +486,11 @@ static void prefs_filtering_create(void)
 
        dest_entry = gtk_entry_new ();
        gtk_widget_show (dest_entry);
-//     gtk_widget_set_usize (dest_entry, 200, -1);
        gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
        
        color_optmenu = gtk_option_menu_new();
-       gtk_option_menu_set_menu(GTK_OPTION_MENU(color_optmenu), 
-                                labelcolors_create_color_menu());
-//     gtk_widget_set_usize(color_optmenu, -1, -1);
+       gtk_option_menu_set_menu(GTK_OPTION_MENU(color_optmenu),
+                                colorlabel_create_color_menu());
        gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, TRUE, TRUE, 0);
 
        dest_btn = gtk_button_new_with_label (_("Select ..."));
@@ -493,11 +507,6 @@ static void prefs_filtering_create(void)
                            GTK_SIGNAL_FUNC (prefs_matcher_exec_info),
                            NULL);
 
-//     dummy = gtk_label_new("");
-//     gtk_widget_show (dummy);
-//     gtk_box_pack_start(GTK_BOX (hbox1), dummy, FALSE, FALSE, 0);
-       
-
        /* register / substitute / delete */
 
        reg_hbox = gtk_hbox_new (FALSE, 4);
@@ -513,13 +522,13 @@ static void prefs_filtering_create(void)
        gtk_widget_show (btn_hbox);
        gtk_box_pack_start (GTK_BOX (reg_hbox), btn_hbox, FALSE, FALSE, 0);
 
-       reg_btn = gtk_button_new_with_label (_("Register"));
+       reg_btn = gtk_button_new_with_label (_("Add"));
        gtk_widget_show (reg_btn);
        gtk_box_pack_start (GTK_BOX (btn_hbox), reg_btn, FALSE, TRUE, 0);
        gtk_signal_connect (GTK_OBJECT (reg_btn), "clicked",
                            GTK_SIGNAL_FUNC (prefs_filtering_register_cb), NULL);
 
-       subst_btn = gtk_button_new_with_label (_(" Substitute "));
+       subst_btn = gtk_button_new_with_label (_("  Replace  "));
        gtk_widget_show (subst_btn);
        gtk_box_pack_start (GTK_BOX (btn_hbox), subst_btn, FALSE, TRUE, 0);
        gtk_signal_connect (GTK_OBJECT (subst_btn), "clicked",
@@ -545,6 +554,7 @@ static void prefs_filtering_create(void)
                                        GTK_POLICY_AUTOMATIC,
                                        GTK_POLICY_AUTOMATIC);
 
+       title[0] = _("Current filtering/processing rules");
        cond_clist = gtk_clist_new_with_titles(1, title);
        gtk_widget_show (cond_clist);
        gtk_container_add (GTK_CONTAINER (cond_scrolledwin), cond_clist);
@@ -582,6 +592,7 @@ static void prefs_filtering_create(void)
        filtering.cond_entry = cond_entry;
        filtering.action_list = action_list;
        filtering.action_combo = action_combo;
+       filtering.account_label = account_label;
        filtering.account_list = account_list;
        filtering.account_combo = account_combo;
        filtering.dest_entry = dest_entry;
@@ -602,25 +613,232 @@ static void prefs_filtering_update_hscrollbar(void)
        gtk_clist_set_column_width(GTK_CLIST(filtering.cond_clist), 0, optwidth);
 }
 
-static void prefs_filtering_set_dialog(void)
+void prefs_filtering_rename_path(const gchar *old_path, const gchar *new_path)
+{
+       GList * cur;
+       gchar *paths[2] = {NULL, NULL};
+       paths[0] = (gchar*)old_path;
+       paths[1] = (gchar*)new_path;
+       for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
+               Folder *folder;
+               folder = (Folder *) cur->data;
+               g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+                               prefs_filtering_rename_path_func, paths);
+       }
+       prefs_filtering_rename_path_func(NULL, paths);
+}
+
+static gboolean prefs_filtering_rename_path_func(GNode *node, gpointer data)
+{
+       GSList *cur;
+       gchar *old_path, *new_path;
+       gchar *base;
+       gchar *prefix;
+       gchar *suffix;
+       gchar *dest_path;
+       gchar *old_path_with_sep;
+       gint destlen;
+       gint prefixlen;
+       gint oldpathlen;
+       FolderItem *item;
+
+       old_path = ((gchar **)data)[0];
+       new_path = ((gchar **)data)[1];
+
+       g_return_val_if_fail(old_path != NULL, FALSE);
+       g_return_val_if_fail(new_path != NULL, FALSE);
+
+       oldpathlen = strlen(old_path);
+       old_path_with_sep = g_strconcat(old_path,G_DIR_SEPARATOR_S,NULL);
+       if (node == NULL)
+               cur = global_processing;
+       else {
+               item = node->data;
+               if (!item || !item->prefs) 
+                       return FALSE;
+               cur = item->prefs->processing;
+       }
+
+       for (; cur != NULL; cur = cur->next) {
+               FilteringProp   *filtering = (FilteringProp *)cur->data;
+               FilteringAction *action = filtering->action;
+
+               if (!action->destination) continue;
+
+               destlen = strlen(action->destination);
+
+               if (destlen > oldpathlen) {
+                       prefixlen = destlen - oldpathlen;
+                       suffix = action->destination + prefixlen;
+
+                       if (!strncmp(old_path, suffix, oldpathlen)) {
+                               prefix = g_malloc0(prefixlen + 1);
+                               strncpy2(prefix, action->destination, prefixlen);
+
+                               base = suffix + oldpathlen;
+                               while (*base == G_DIR_SEPARATOR) base++;
+                               if (*base == '\0')
+                                       dest_path = g_strconcat(prefix,
+                                                               G_DIR_SEPARATOR_S,
+                                                               new_path, NULL);
+                               else
+                                       dest_path = g_strconcat(prefix,
+                                                               G_DIR_SEPARATOR_S,
+                                                               new_path,
+                                                               G_DIR_SEPARATOR_S,
+                                                               base, NULL);
+
+                               g_free(prefix);
+                               g_free(action->destination);
+                               action->destination = dest_path;
+                       } else { /* for non-leaf folders */
+                               /* compare with trailing slash */
+                               if (!strncmp(old_path_with_sep, action->destination, oldpathlen+1)) {
+                                       
+                                       suffix = action->destination + oldpathlen + 1;
+                                       dest_path = g_strconcat(new_path,
+                                                               G_DIR_SEPARATOR_S,
+                                                               suffix, NULL);
+                                       g_free(action->destination);
+                                       action->destination = dest_path;
+                               }
+                       }
+               } else {
+                       /* folder-moving a leaf */
+                       if (!strcmp(old_path, action->destination)) {           
+                               dest_path = g_strdup(new_path);
+                               g_free(action->destination);
+                               action->destination = dest_path;
+                       }
+               }
+       }
+       g_free(old_path_with_sep);
+       prefs_matcher_write_config();
+
+       return FALSE;
+}
+
+void prefs_filtering_delete_path(const gchar *path)
+{
+       GList * cur;
+       for (cur = folder_get_list() ; cur != NULL ; cur = g_list_next(cur)) {
+               Folder *folder;
+               folder = (Folder *) cur->data;
+               g_node_traverse(folder->node, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
+                               prefs_filtering_delete_path_func, (gchar *)path);
+       }
+       prefs_filtering_delete_path_func(NULL, (gchar *)path);
+}
+
+static gboolean prefs_filtering_delete_path_func(GNode *node, gpointer data)
+{
+       GSList *cur, *orig;
+       GSList *next;
+       gchar *path = (gchar *)data;
+       gchar *suffix;
+       gint destlen;
+       gint prefixlen;
+       gint pathlen;
+       FolderItem *item;
+       
+       g_return_val_if_fail(path != NULL, FALSE);
+
+       pathlen = strlen(path);
+       if (node == NULL)
+               cur = global_processing;
+       else {
+               item = node->data;
+               if (!item || !item->prefs)
+                       return FALSE;
+               cur = item->prefs->processing;
+       }
+       orig = cur;
+       
+       for (; cur != NULL; cur = cur->next) {
+               FilteringProp *filtering = (FilteringProp *)cur->data;
+               FilteringAction *action;
+               if (!cur->data)
+                       break;
+               
+               action = filtering->action;
+               next = cur->next;
+
+               if (!action->destination) continue;
+
+               destlen = strlen(action->destination);
+
+               if (destlen > pathlen) {
+                       prefixlen = destlen - pathlen;
+                       suffix = action->destination + prefixlen;
+
+                       if (suffix && !strncmp(path, suffix, pathlen)) {
+                               filteringprop_free(filtering);
+                               orig = g_slist_remove(orig, filtering);
+                       }
+               } else if (strcmp(action->destination, path) == 0) {
+                       filteringprop_free(filtering);
+                       orig = g_slist_remove(orig, filtering);
+
+               }
+       }
+
+       if (node == NULL)
+               global_processing = orig;
+       else {
+               item = node->data;
+               if (!item || !item->prefs)
+                       return FALSE;
+               item->prefs->processing = orig;
+       }
+
+       prefs_matcher_write_config();
+
+       return FALSE;
+}
+
+static void prefs_filtering_set_dialog(const gchar *header, const gchar *key)
 {
        GtkCList *clist = GTK_CLIST(filtering.cond_clist);
        GSList *cur;
+       GSList * prefs_filtering;
+       gchar *cond_str[1];
+       gint row;
        
        gtk_clist_freeze(clist);
        gtk_clist_clear(clist);
 
-       prefs_filtering_clist_set_row(-1, NULL);
+       cond_str[0] = _("(New)");
+       row = gtk_clist_append(clist, cond_str);
+       gtk_clist_set_row_data(clist, row, NULL);
+
+       if (cur_item == NULL)
+               prefs_filtering = global_processing;
+       else
+               prefs_filtering = cur_item->prefs->processing;
+
        for(cur = prefs_filtering ; cur != NULL ; cur = g_slist_next(cur)) {
                FilteringProp * prop = (FilteringProp *) cur->data;
 
-               prefs_filtering_clist_set_row(-1, prop);
+               cond_str[0] = filteringprop_to_string(prop);
+               subst_char(cond_str[0], '\t', ':');
+               row = gtk_clist_append(clist, cond_str);
+               gtk_clist_set_row_data(clist, row, prop);
+
+               g_free(cond_str[0]);
        }
 
        prefs_filtering_update_hscrollbar();
        gtk_clist_thaw(clist);
 
        prefs_filtering_reset_dialog();
+
+       if (header && key) {
+               gchar *match_str = g_strconcat(header, " ",
+                       get_matchparser_tab_str(MATCHTYPE_MATCHCASE),
+                       " \"", key, "\"", NULL);
+               gtk_entry_set_text(GTK_ENTRY(filtering.cond_entry), match_str);
+               g_free(match_str);
+       }
 }
 
 static void prefs_filtering_reset_dialog(void)
@@ -637,7 +855,12 @@ static void prefs_filtering_set_list(void)
        FilteringProp *prop;
        GSList * cur;
        gchar * filtering_str;
-       gchar * tmp;
+       GSList * prefs_filtering;
+
+       if (cur_item == NULL)
+               prefs_filtering = global_processing;
+       else
+               prefs_filtering = cur_item->prefs->processing;
 
        for(cur = prefs_filtering ; cur != NULL ; cur = g_slist_next(cur))
                filteringprop_free((FilteringProp *) cur->data);
@@ -647,14 +870,19 @@ static void prefs_filtering_set_list(void)
        while (gtk_clist_get_text(GTK_CLIST(filtering.cond_clist),
                                  row, 0, &filtering_str)) {
                if (strcmp(filtering_str, _("(New)")) != 0) {
-                       tmp = filtering_str;
-                       prop = filteringprop_parse(&tmp);
+                       /* tmp = filtering_str; */
+                       prop = matcher_parser_get_filtering(filtering_str);
                        if (prop != NULL)
-                               prefs_filtering = g_slist_append(prefs_filtering,
-                                                              prop);
+                               prefs_filtering =
+                                       g_slist_append(prefs_filtering, prop);
                }
                row++;
        }
+
+       if (cur_item == NULL)
+               global_processing = prefs_filtering;
+       else
+               cur_item->prefs->processing = prefs_filtering;
 }
 
 static gint prefs_filtering_clist_set_row(gint row, FilteringProp * prop)
@@ -706,12 +934,9 @@ static void prefs_filtering_condition_define(void)
        cond_str = gtk_entry_get_text(GTK_ENTRY(filtering.cond_entry));
 
        if (*cond_str != '\0') {
-               gchar * tmp;
-               
-               tmp = cond_str;
-               matchers = matcherlist_parse(&tmp);
-               if (tmp == NULL)
-                       alertpanel_error(_("Match string is not valid."));
+               matchers = matcher_parser_get_cond(cond_str);
+               if (matchers == NULL)
+                       alertpanel_error(_("Condition string is not valid."));
        }
 
        prefs_matcher_open(matchers, prefs_filtering_condition_define_done);
@@ -724,23 +949,22 @@ static void prefs_filtering_condition_define(void)
 /* register / substitute delete buttons */
 
 
-static FilteringProp * prefs_filtering_dialog_to_filtering(void)
+static FilteringProp * prefs_filtering_dialog_to_filtering(gboolean alert)
 {
        MatcherList * cond;
        gchar * cond_str;
        FilteringProp * prop;
        FilteringAction * action;
-       gchar * tmp;
        gint list_id;
        gint action_id;
        gint action_type;
        gint account_id;
        gchar * destination;
-       gint labelcolor;
+       gint labelcolor = 0;
        
        cond_str = gtk_entry_get_text(GTK_ENTRY(filtering.cond_entry));
        if (*cond_str == '\0') {
-               alertpanel_error(_("Score is not set."));
+               if(alert == TRUE) alertpanel_error(_("Condition string is empty."));
                return NULL;
        }
 
@@ -754,18 +978,22 @@ static FilteringProp * prefs_filtering_dialog_to_filtering(void)
        case ACTION_COPY:
        case ACTION_FORWARD:
        case ACTION_FORWARD_AS_ATTACHMENT:
+       case ACTION_REDIRECT:
        case ACTION_EXECUTE:
                destination = gtk_entry_get_text(GTK_ENTRY(filtering.dest_entry));
                if (*destination == '\0') {
-                       alertpanel_error(_("Destination is not set."));
+                       if(alert == TRUE) alertpanel_error(_("Destination is not set."));
                        return NULL;
                }
                break;
        case ACTION_COLOR:
-               labelcolor = labelcolors_get_color_menu_active_item(
+               labelcolor = colorlabel_get_color_menu_active_item(
                        gtk_option_menu_get_menu(GTK_OPTION_MENU(filtering.color_optmenu)));
                destination = NULL;     
                break;
+       case ACTION_DELETE_ON_SERVER:
+               destination = NULL;
+               break;
        default:
                destination = NULL;
                break;
@@ -773,11 +1001,10 @@ static FilteringProp * prefs_filtering_dialog_to_filtering(void)
        
        action = filteringaction_new(action_type, account_id, destination, labelcolor);
 
-       tmp = cond_str;
-       cond = matcherlist_parse(&tmp);
+       cond = matcher_parser_get_cond(cond_str);
 
-       if (tmp == NULL) {
-               alertpanel_error(_("Match string is not valid."));
+       if (cond == NULL) {
+               if(alert == TRUE) alertpanel_error(_("Condition string is not valid."));
                filteringaction_free(action);
                return NULL;
        }
@@ -791,7 +1018,7 @@ static void prefs_filtering_register_cb(void)
 {
        FilteringProp * prop;
        
-       prop = prefs_filtering_dialog_to_filtering();
+       prop = prefs_filtering_dialog_to_filtering(TRUE);
        if (prop == NULL)
                return;
        prefs_filtering_clist_set_row(-1, prop);
@@ -812,7 +1039,7 @@ static void prefs_filtering_substitute_cb(void)
        row = GPOINTER_TO_INT(clist->selection->data);
        if (row == 0) return;
 
-       prop = prefs_filtering_dialog_to_filtering();
+       prop = prefs_filtering_dialog_to_filtering(TRUE);
        if (prop == NULL)
                return;
        prefs_filtering_clist_set_row(row, prop);
@@ -851,6 +1078,9 @@ static void prefs_filtering_up(void)
        row = GPOINTER_TO_INT(clist->selection->data);
        if (row > 1) {
                gtk_clist_row_move(clist, row, row - 1);
+               if(gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL) {
+                       gtk_clist_moveto(clist, row - 1, 0, 0, 0);
+               } 
        }
 }
 
@@ -864,6 +1094,9 @@ static void prefs_filtering_down(void)
        row = GPOINTER_TO_INT(clist->selection->data);
        if (row > 0 && row < clist->rows - 1) {
                gtk_clist_row_move(clist, row, row + 1);
+               if(gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL) {
+                       gtk_clist_moveto(clist, row + 1, 0, 1, 0);
+               } 
        }
 }
 
@@ -891,57 +1124,68 @@ static void prefs_filtering_select_set(FilteringProp * prop)
                gtk_entry_set_text(GTK_ENTRY(filtering.dest_entry), "");
 
        switch(action->type) {
-       case MATCHING_ACTION_MOVE:
+       case MATCHACTION_MOVE:
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_MOVE);
                break;
-       case MATCHING_ACTION_COPY:
+       case MATCHACTION_COPY:
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_COPY);
                break;
-       case MATCHING_ACTION_DELETE:
+       case MATCHACTION_DELETE:
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_DELETE);
                break;
-       case MATCHING_ACTION_MARK:
+       case MATCHACTION_MARK:
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_MARK);
                break;
-       case MATCHING_ACTION_UNMARK:
+       case MATCHACTION_UNMARK:
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_UNMARK);
                break;
-       case MATCHING_ACTION_MARK_AS_READ:
+       case MATCHACTION_MARK_AS_READ:
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_MARK_AS_READ);
                break;
-       case MATCHING_ACTION_MARK_AS_UNREAD:
+       case MATCHACTION_MARK_AS_UNREAD:
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_MARK_AS_UNREAD);
                break;
-       case MATCHING_ACTION_FORWARD:
+       case MATCHACTION_FORWARD:
+               list_id = get_list_id_from_account_id(action->account_id);
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_FORWARD);
-               list_id = get_list_id_from_account_id(action->account_id);
                gtk_list_select_item(GTK_LIST(filtering.account_list),
                                     list_id);
                break;
-       case MATCHING_ACTION_FORWARD_AS_ATTACHMENT:
+       case MATCHACTION_FORWARD_AS_ATTACHMENT:
                list_id = get_list_id_from_account_id(action->account_id);
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_FORWARD_AS_ATTACHMENT);
                gtk_list_select_item(GTK_LIST(filtering.account_list),
                                     list_id);
                break;
-       case MATCHING_EXECUTE:
+       case MATCHACTION_REDIRECT:
+               list_id = get_list_id_from_account_id(action->account_id);
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_REDIRECT);
+               gtk_list_select_item(GTK_LIST(filtering.account_list),
+                                    list_id);
+               break;
+       case MATCHACTION_EXECUTE:
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_EXECUTE);
                break;
-       case MATCHING_ACTION_COLOR:
+       case MATCHACTION_COLOR:
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_COLOR);
                gtk_option_menu_set_history(GTK_OPTION_MENU(filtering.color_optmenu), action->labelcolor);     
                break;
+       case MATCHACTION_DELETE_ON_SERVER:
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_DELETE_ON_SERVER);
+               break;
        }
 
        g_free(matcher_str);
@@ -951,7 +1195,6 @@ static void prefs_filtering_select(GtkCList *clist, gint row, gint column,
                                GdkEvent *event)
 {
        FilteringProp * prop;
-       gchar * tmp;
        gchar * filtering_str;
 
        if (row == 0) {
@@ -963,9 +1206,8 @@ static void prefs_filtering_select(GtkCList *clist, gint row, gint column,
                                row, 0, &filtering_str))
                return;
        
-       tmp = filtering_str;
-       prop = filteringprop_parse(&tmp);
-       if (tmp == NULL)
+       prop = matcher_parser_get_filtering(filtering_str);
+       if (prop == NULL)
                return;
 
        prefs_filtering_select_set(prop);
@@ -978,7 +1220,7 @@ static void prefs_filtering_select_dest(void)
        FolderItem *dest;
        gchar * path;
 
-       dest = foldersel_folder_sel(NULL, NULL);
+       dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
        if (!dest) return;
 
        path = folder_item_get_identifier(dest);
@@ -1018,117 +1260,172 @@ static void prefs_filtering_action_select(GtkList *list,
 
        switch (value) {
        case ACTION_MOVE:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, FALSE);
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
                gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
                gtk_widget_show(filtering.dest_btn);
+               gtk_widget_set_sensitive(filtering.dest_btn, TRUE);
                gtk_widget_show(filtering.dest_label);
+               gtk_widget_set_sensitive(filtering.dest_label, TRUE);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
                gtk_widget_hide(filtering.color_optmenu);
                gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_COPY:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, FALSE);
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
                gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
                gtk_widget_show(filtering.dest_btn);
+               gtk_widget_set_sensitive(filtering.dest_btn, TRUE);
                gtk_widget_show(filtering.dest_label);
+               gtk_widget_set_sensitive(filtering.dest_label, TRUE);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
                gtk_widget_hide(filtering.color_optmenu);
                gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_DELETE:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, FALSE);
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
                gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
-               gtk_widget_hide(filtering.dest_btn);
+               gtk_widget_show(filtering.dest_btn);
+               gtk_widget_set_sensitive(filtering.dest_btn, FALSE);
                gtk_widget_show(filtering.dest_label);
+               gtk_widget_set_sensitive(filtering.dest_label, FALSE);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
                gtk_widget_hide(filtering.color_optmenu);
                gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_MARK:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, FALSE);
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
                gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
-               gtk_widget_hide(filtering.dest_btn);
+               gtk_widget_show(filtering.dest_btn);
+               gtk_widget_set_sensitive(filtering.dest_btn, FALSE);
                gtk_widget_show(filtering.dest_label);
+               gtk_widget_set_sensitive(filtering.dest_label, FALSE);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
                gtk_widget_hide(filtering.color_optmenu);
                gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_UNMARK:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, FALSE);
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
                gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
-               gtk_widget_hide(filtering.dest_btn);
+               gtk_widget_show(filtering.dest_btn);
+               gtk_widget_set_sensitive(filtering.dest_btn, FALSE);
                gtk_widget_show(filtering.dest_label);
+               gtk_widget_set_sensitive(filtering.dest_label, FALSE);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
                gtk_widget_hide(filtering.color_optmenu);
                gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_MARK_AS_READ:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, FALSE);
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
                gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
-               gtk_widget_hide(filtering.dest_btn);
+               gtk_widget_show(filtering.dest_btn);
+               gtk_widget_set_sensitive(filtering.dest_btn, FALSE);
                gtk_widget_show(filtering.dest_label);
+               gtk_widget_set_sensitive(filtering.dest_label, FALSE);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
                gtk_widget_hide(filtering.color_optmenu);
                gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_MARK_AS_UNREAD:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, FALSE);
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
                gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
-               gtk_widget_hide(filtering.dest_btn);
+               gtk_widget_show(filtering.dest_btn);
+               gtk_widget_set_sensitive(filtering.dest_btn, FALSE);
                gtk_widget_show(filtering.dest_label);
+               gtk_widget_set_sensitive(filtering.dest_label, FALSE);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
                gtk_widget_hide(filtering.color_optmenu);
                gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_FORWARD:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, TRUE);
                gtk_widget_set_sensitive(filtering.account_combo, TRUE);
                gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
-               gtk_widget_hide(filtering.dest_btn);
+               gtk_widget_show(filtering.dest_btn);
+               gtk_widget_set_sensitive(filtering.dest_btn, FALSE);
                gtk_widget_show(filtering.dest_label);
+               gtk_widget_set_sensitive(filtering.dest_label, TRUE);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
                gtk_widget_hide(filtering.color_optmenu);
                gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_FORWARD_AS_ATTACHMENT:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, TRUE);
                gtk_widget_set_sensitive(filtering.account_combo, TRUE);
                gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
-               gtk_widget_hide(filtering.dest_btn);
+               gtk_widget_show(filtering.dest_btn);
+               gtk_widget_set_sensitive(filtering.dest_btn, FALSE);
+               gtk_widget_show(filtering.dest_label);
+               gtk_widget_set_sensitive(filtering.dest_label, TRUE);
+               gtk_widget_hide(filtering.exec_label);
+               gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
+               break;
+       case ACTION_REDIRECT:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, TRUE);
+               gtk_widget_set_sensitive(filtering.account_combo, TRUE);
+               gtk_widget_show(filtering.dest_entry);
+               gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
+               gtk_widget_show(filtering.dest_btn);
+               gtk_widget_set_sensitive(filtering.dest_btn, FALSE);
                gtk_widget_show(filtering.dest_label);
+               gtk_widget_set_sensitive(filtering.dest_label, TRUE);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
                gtk_widget_hide(filtering.color_optmenu);
                gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_EXECUTE:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, FALSE);
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
                gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
                gtk_widget_hide(filtering.dest_btn);
                gtk_widget_hide(filtering.dest_label);
                gtk_widget_show(filtering.exec_label);
-               gtk_widget_set_sensitive(filtering.exec_btn, FALSE);
+               gtk_widget_set_sensitive(filtering.exec_btn, TRUE);
                gtk_widget_show(filtering.exec_btn);
                gtk_widget_hide(filtering.color_optmenu);
                gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_COLOR:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, FALSE);
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
                gtk_widget_hide(filtering.dest_entry);
                gtk_widget_hide(filtering.dest_btn);
@@ -1139,6 +1436,22 @@ static void prefs_filtering_action_select(GtkList *list,
                gtk_widget_show(filtering.color_optmenu);
                gtk_widget_show(filtering.color_label);
                break;
+       case ACTION_DELETE_ON_SERVER:
+               gtk_widget_show(filtering.account_label);
+               gtk_widget_set_sensitive(filtering.account_label, FALSE);
+               gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_show(filtering.dest_entry);
+               gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
+               gtk_widget_show(filtering.dest_btn);
+               gtk_widget_set_sensitive(filtering.dest_btn, FALSE);
+               gtk_widget_show(filtering.dest_label);
+               gtk_widget_set_sensitive(filtering.dest_label, FALSE);
+               gtk_widget_hide(filtering.exec_label);
+               gtk_widget_show(filtering.exec_btn);
+               gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
+               break;
        }
 }
 
@@ -1158,13 +1471,38 @@ static void prefs_filtering_key_pressed(GtkWidget *widget, GdkEventKey *event,
 
 static void prefs_filtering_ok(void)
 {
+       FilteringProp * prop;
+       gchar * str;
+       gchar * filtering_str;
+       gint row = 1;
+        AlertValue val;
+       
+       prop = prefs_filtering_dialog_to_filtering(FALSE);
+       if (prop != NULL) {
+               str = filteringprop_to_string(prop);
+               while (gtk_clist_get_text(GTK_CLIST(filtering.cond_clist),
+                                         row, 0, &filtering_str)) {
+                       if (strcmp(filtering_str, str) == 0) break;
+                       row++;
+               }
+               if (strcmp(filtering_str, str) != 0) {
+                        val = alertpanel(_("Entry not saved"),
+                                        _("The entry was not saved. Close anyway?"),
+                                        _("Yes"), _("No"), NULL);
+                        if (G_ALERTDEFAULT != val) {
+                               g_free(str);
+                               return;
+                        }
+               }
+               g_free(str);
+       }
        prefs_filtering_set_list();
-       prefs_filtering_write_config();
+       prefs_matcher_write_config();
        prefs_filtering_close();
 }
 
 static void prefs_filtering_cancel(void)
 {
-       prefs_filtering_read_config();
+       prefs_matcher_read_config();
        prefs_filtering_close();
 }