2007-10-10 [paul] 3.0.2cvs54
[claws.git] / src / prefs_filtering_action.c
index 608f0580b66f8b48b327156a21442359d7dfa72a..79574def3b9c2df1cf58d1222b30089bb667af49 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto
  *
  * 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -47,7 +47,7 @@
 #include "folder.h"
 #include "description_window.h"
 #include "addr_compl.h"
-
+#include "tags.h"
 #include "matcher_parser.h"
 #include "colorlabel.h"
 
@@ -74,6 +74,7 @@ static void prefs_filtering_action_type_selection_changed(GtkList *list,
 static void prefs_filtering_action_type_select(GtkList *list,
     GtkWidget *widget, gpointer user_data);
 static void prefs_filtering_action_select_dest(void);
+static void prefs_filtering_action_select_addressbook(void);
 static void prefs_filtering_action_up(void);
 static void prefs_filtering_action_down(void);
 static void prefs_filtering_action_set_dialog(GSList *action_list);
@@ -115,6 +116,14 @@ static struct FilteringAction_ {
        GtkWidget *color_label;
        GtkWidget *color_optmenu;
        GtkWidget *score_label;
+       GtkWidget *header_label;
+       GtkWidget *header_combo;
+       GtkWidget *header_entry;
+       GtkWidget *addressbook_label;
+       GtkWidget *addressbook_btn;
+       GtkWidget *tags_label;
+       GtkWidget *tags_list;
+       GtkWidget *tags_combo;
 
        gint current_action;
 } filtering_action;
@@ -130,6 +139,8 @@ typedef enum Action_ {
        ACTION_UNLOCK,
        ACTION_MARK_AS_READ,
        ACTION_MARK_AS_UNREAD,
+       ACTION_MARK_AS_SPAM,
+       ACTION_MARK_AS_HAM,
        ACTION_FORWARD,
        ACTION_FORWARD_AS_ATTACHMENT,
        ACTION_REDIRECT,
@@ -137,7 +148,13 @@ typedef enum Action_ {
        ACTION_COLOR,
        ACTION_CHANGE_SCORE,
        ACTION_SET_SCORE,
+       ACTION_SET_TAG,
+       ACTION_UNSET_TAG,
+       ACTION_CLEAR_TAGS,
        ACTION_HIDE,
+       ACTION_IGNORE,
+       ACTION_WATCH,
+       ACTION_ADD_TO_ADDRESSBOOK,
        ACTION_STOP,
        /* add other action constants */
 } Action;
@@ -155,6 +172,8 @@ static struct {
        { N_("Unlock"),                 ACTION_UNLOCK   },
        { N_("Mark as read"),           ACTION_MARK_AS_READ },
        { N_("Mark as unread"),         ACTION_MARK_AS_UNREAD },
+       { N_("Mark as spam"),           ACTION_MARK_AS_SPAM },
+       { N_("Mark as ham"),            ACTION_MARK_AS_HAM },
        { N_("Forward"),                ACTION_FORWARD  },
        { N_("Forward as attachment"),  ACTION_FORWARD_AS_ATTACHMENT },
        { N_("Redirect"),               ACTION_REDIRECT },
@@ -162,7 +181,13 @@ static struct {
        { N_("Color"),                  ACTION_COLOR    },
        { N_("Change score"),           ACTION_CHANGE_SCORE},
        { N_("Set score"),              ACTION_SET_SCORE},
+       { N_("Apply tag"),              ACTION_SET_TAG},
+       { N_("Unset tag"),              ACTION_UNSET_TAG},
+       { N_("Clear tags"),             ACTION_CLEAR_TAGS},
        { N_("Hide"),                   ACTION_HIDE     },
+       { N_("Ignore thread"),          ACTION_IGNORE   },
+       { N_("Watch thread"),           ACTION_WATCH    },
+       { N_("Add to address book"),    ACTION_ADD_TO_ADDRESSBOOK       },
        { N_("Stop filter"),            ACTION_STOP     },
 };
 
@@ -212,6 +237,10 @@ void prefs_filtering_action_open(GSList *action_list,
 
        if (!filtering_action.window) {
                prefs_filtering_action_create();
+       } else {
+               /* update color label menu */
+               gtk_option_menu_set_menu(GTK_OPTION_MENU(filtering_action.color_optmenu),
+                               colorlabel_create_color_menu());
        }
 
        manage_window_set_transient(GTK_WINDOW(filtering_action.window));
@@ -224,6 +253,18 @@ void prefs_filtering_action_open(GSList *action_list,
        gtk_widget_show(filtering_action.window);
 }
 
+/*!
+ *\brief       Save Gtk object size to prefs dataset
+ */
+static void prefs_filtering_action_size_allocate_cb(GtkWidget *widget,
+                                        GtkAllocation *allocation)
+{
+       g_return_if_fail(allocation != NULL);
+
+       prefs_common.filteringactionwin_width = allocation->width;
+       prefs_common.filteringactionwin_height = allocation->height;
+}
+
 /*!
  *\brief       Create the matcher dialog
  */
@@ -250,8 +291,16 @@ static void prefs_filtering_action_create(void)
        GtkWidget *color_label;
        GtkWidget *account_label;
        GtkWidget *account_combo;
+       GtkWidget *header_label;
+       GtkWidget *header_combo;
+       GtkWidget *header_entry;
+       GtkWidget *addressbook_label;
+       GtkWidget *addressbook_btn;
        GtkWidget *dest_entry;
        GtkWidget *dest_btn;
+       GtkWidget *tags_label;
+       GtkWidget *tags_list;
+       GtkWidget *tags_combo;
         GList * cur;
 
        GtkWidget *reg_hbox;
@@ -275,12 +324,14 @@ static void prefs_filtering_action_create(void)
 
        GList *combo_items;
        gint i;
+       static GdkGeometry geometry;
 
         GList * accounts;
+       GSList *tmp, *tags;
 
        debug_print("Creating matcher configuration window...\n");
 
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_filtering_action");
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);
@@ -290,8 +341,10 @@ static void prefs_filtering_action_create(void)
        gtk_widget_show(vbox);
        gtk_container_add(GTK_CONTAINER(window), vbox);
 
-       gtkut_stock_button_set_create(&confirm_area, &ok_btn, GTK_STOCK_OK,
-                                     &cancel_btn, GTK_STOCK_CANCEL, NULL, NULL);
+       gtkut_stock_button_set_create(&confirm_area,
+                                     &cancel_btn, GTK_STOCK_CANCEL,
+                                     &ok_btn, GTK_STOCK_OK,
+                                     NULL, NULL);
        gtk_widget_show(confirm_area);
        gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
        gtk_widget_grab_default(ok_btn);
@@ -300,6 +353,8 @@ static void prefs_filtering_action_create(void)
                             _("Filtering action configuration"));
        g_signal_connect(G_OBJECT(window), "delete_event",
                         G_CALLBACK(prefs_filtering_action_deleted), NULL);
+       g_signal_connect(G_OBJECT(window), "size_allocate",
+                        G_CALLBACK(prefs_filtering_action_size_allocate_cb), NULL);
        g_signal_connect(G_OBJECT(window), "key_press_event",
                         G_CALLBACK(prefs_filtering_action_key_pressed), NULL);
        MANAGE_WINDOW_SIGNALS_CONNECT(window);
@@ -390,6 +445,24 @@ static void prefs_filtering_action_create(void)
        gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(account_combo)->entry),
                               FALSE);
 
+       /* header */
+
+       header_label = gtk_label_new(_("Header name"));
+       gtk_widget_show(header_label);
+       gtk_misc_set_alignment(GTK_MISC(header_label), 0, 0.5);
+       gtk_box_pack_start (GTK_BOX (hbox1), header_label, FALSE, FALSE, 0);
+
+       header_combo = gtk_combo_new();
+       gtk_widget_show(header_combo);
+       gtk_widget_set_size_request(header_combo, 120, -1);
+       gtkut_combo_set_items(GTK_COMBO (header_combo),
+                             "From", "To", "Cc", "Reply-To", "Sender",
+                             NULL);
+       gtk_box_pack_start (GTK_BOX (hbox1), header_combo,
+                           TRUE, TRUE, 0);
+       header_entry = GTK_COMBO(header_combo)->entry;
+       gtk_entry_set_editable(GTK_ENTRY(header_entry), TRUE);
+
        /* destination */
 
        hbox1 = gtk_hbox_new (FALSE, VSPACING);
@@ -422,6 +495,16 @@ static void prefs_filtering_action_create(void)
        gtk_misc_set_alignment (GTK_MISC (score_label), 0, 0.5);
        gtk_box_pack_start (GTK_BOX (hbox1), score_label, FALSE, FALSE, 0);
 
+       addressbook_label = gtk_label_new (_("Book/folder"));
+       gtk_widget_show(addressbook_label);
+       gtk_misc_set_alignment(GTK_MISC(addressbook_label), 0, 0.5);
+       gtk_box_pack_start(GTK_BOX(hbox1), addressbook_label, FALSE, FALSE, 0);
+
+       tags_label = gtk_label_new (_("Tag"));
+       gtk_widget_show (tags_label);
+       gtk_misc_set_alignment (GTK_MISC (tags_label), 0, 0.5);
+       gtk_box_pack_start (GTK_BOX (hbox1), tags_label, FALSE, FALSE, 0);
+
        dest_entry = gtk_entry_new ();
        gtk_widget_set_size_request (dest_entry, 150, -1);
        gtk_widget_show (dest_entry);
@@ -432,6 +515,31 @@ static void prefs_filtering_action_create(void)
                                 colorlabel_create_color_menu());
        gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, TRUE, TRUE, 0);
 
+       tags_combo = gtk_combo_new ();
+       gtk_widget_set_size_request (tags_combo, 150, -1);
+       gtk_widget_show (tags_combo);
+
+       combo_items = NULL;
+       for (tmp = tags = tags_get_list() ; tmp != NULL;
+            tmp = tmp->next) {
+               gchar *name = g_strdup(tags_get_tag(GPOINTER_TO_INT(tmp->data)));
+
+               combo_items = g_list_append(combo_items, (gpointer) name);
+       }
+
+       gtk_combo_set_popdown_strings(GTK_COMBO(tags_combo), combo_items);
+
+       for(cur = g_list_first(combo_items) ; cur != NULL ;
+           cur = g_list_next(cur))
+               g_free(cur->data);
+       g_list_free(combo_items);
+       g_slist_free(tags);
+
+       gtk_box_pack_start (GTK_BOX (hbox1), tags_combo,
+                           TRUE, TRUE, 0);
+       tags_list = GTK_COMBO(tags_combo)->list;
+       gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(tags_combo)->entry),
+                              FALSE);
        dest_btn = gtk_button_new_with_label (_("Select ..."));
        gtk_widget_show (dest_btn);
        gtk_box_pack_start (GTK_BOX (hbox1), dest_btn, FALSE, FALSE, 0);
@@ -439,7 +547,18 @@ static void prefs_filtering_action_create(void)
                          G_CALLBACK(prefs_filtering_action_select_dest),
                          NULL);
 
-       exec_btn = gtk_button_new_with_label (_("Info ..."));
+       addressbook_btn = gtk_button_new_with_label (_("Select ..."));
+       gtk_widget_show (addressbook_btn);
+       gtk_box_pack_start (GTK_BOX (hbox1), addressbook_btn, FALSE, FALSE, 0);
+       g_signal_connect (G_OBJECT (addressbook_btn), "clicked",
+                         G_CALLBACK(prefs_filtering_action_select_addressbook),
+                         NULL);
+
+#if GTK_CHECK_VERSION(2, 8, 0)
+       exec_btn = gtk_button_new_from_stock(GTK_STOCK_INFO);
+#else
+       exec_btn = gtk_button_new_with_label (_("Info..."));
+#endif
        gtk_widget_show (exec_btn);
        gtk_box_pack_start (GTK_BOX (hbox1), exec_btn, FALSE, FALSE, 0);
        g_signal_connect (G_OBJECT (exec_btn), "clicked",
@@ -467,7 +586,7 @@ static void prefs_filtering_action_create(void)
        g_signal_connect(G_OBJECT(reg_btn), "clicked",
                         G_CALLBACK(prefs_filtering_action_register_cb), NULL);
 
-       subst_btn = gtk_button_new_with_label(_("  Replace  "));
+       subst_btn = gtkut_get_replace_btn(_("Replace"));
        gtk_widget_show(subst_btn);
        gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
        g_signal_connect(G_OBJECT(subst_btn), "clicked",
@@ -513,6 +632,16 @@ static void prefs_filtering_action_create(void)
        g_signal_connect(G_OBJECT(down_btn), "clicked",
                         G_CALLBACK(prefs_filtering_action_down), NULL);
 
+       if (!geometry.min_height) {
+               geometry.min_width = 490;
+               geometry.min_height = 328;
+       }
+
+       gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
+                                     GDK_HINT_MIN_SIZE);
+       gtk_widget_set_size_request(window, prefs_common.filteringactionwin_width,
+                                   prefs_common.filteringactionwin_height);
+
        gtk_widget_show_all(window);
 
        filtering_action.window    = window;
@@ -521,6 +650,9 @@ static void prefs_filtering_action_create(void)
        filtering_action.account_label = account_label;
        filtering_action.account_list = account_list;
        filtering_action.account_combo = account_combo;
+       filtering_action.tags_label = tags_label;
+       filtering_action.tags_list = tags_list;
+       filtering_action.tags_combo = tags_combo;
        filtering_action.dest_entry = dest_entry;
        filtering_action.dest_btn = dest_btn;
        filtering_action.dest_label = dest_label;
@@ -530,6 +662,11 @@ static void prefs_filtering_action_create(void)
        filtering_action.color_label   = color_label;
        filtering_action.color_optmenu = color_optmenu;
        filtering_action.score_label = score_label;
+       filtering_action.header_label = header_label;
+       filtering_action.header_combo = header_combo;
+       filtering_action.header_entry = header_entry;
+       filtering_action.addressbook_label = addressbook_label;
+       filtering_action.addressbook_btn = addressbook_btn;
        filtering_action.ok_btn = ok_btn;
        filtering_action.action_list_view = action_list_view;
 }
@@ -549,7 +686,7 @@ static void prefs_filtering_action_list_view_set_row(GtkTreeIter *row,
        if (row == NULL && action == NULL) {
                prefs_filtering_action_list_view_insert_action
                        (filtering_action.action_list_view,
-                        NULL, _("New"), FALSE);
+                        NULL, _("(New)"), FALSE);
                return;
        }                        
 
@@ -684,6 +821,12 @@ static gint prefs_filtering_action_get_matching_from_action(Action action_id)
        switch (action_id) {
        case ACTION_MOVE:
                return MATCHACTION_MOVE;
+       case ACTION_SET_TAG:
+               return MATCHACTION_SET_TAG;
+       case ACTION_UNSET_TAG:
+               return MATCHACTION_UNSET_TAG;
+       case ACTION_CLEAR_TAGS:
+               return MATCHACTION_CLEAR_TAGS;
        case ACTION_COPY:
                return MATCHACTION_COPY;
        case ACTION_DELETE:
@@ -700,6 +843,10 @@ static gint prefs_filtering_action_get_matching_from_action(Action action_id)
                return MATCHACTION_MARK_AS_READ;
        case ACTION_MARK_AS_UNREAD:
                return MATCHACTION_MARK_AS_UNREAD;
+       case ACTION_MARK_AS_SPAM:
+               return MATCHACTION_MARK_AS_SPAM;
+       case ACTION_MARK_AS_HAM:
+               return MATCHACTION_MARK_AS_HAM;
        case ACTION_FORWARD:
                return MATCHACTION_FORWARD;
        case ACTION_FORWARD_AS_ATTACHMENT:
@@ -712,12 +859,18 @@ static gint prefs_filtering_action_get_matching_from_action(Action action_id)
                return MATCHACTION_COLOR;
        case ACTION_HIDE:
                return MATCHACTION_HIDE;
+       case ACTION_IGNORE:
+               return MATCHACTION_IGNORE;
+       case ACTION_WATCH:
+               return MATCHACTION_WATCH;
        case ACTION_STOP:
                return MATCHACTION_STOP;
        case ACTION_CHANGE_SCORE:
                return MATCHACTION_CHANGE_SCORE;
        case ACTION_SET_SCORE:
                return MATCHACTION_SET_SCORE;
+       case ACTION_ADD_TO_ADDRESSBOOK:
+               return MATCHACTION_ADD_TO_ADDRESSBOOK;
        default:
                return -1;
        }
@@ -742,6 +895,7 @@ static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
         FilteringAction * action;
         gchar * score_str = NULL;
         gint score;
+       gchar * header = NULL;
         
        action_id = get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
        action_type = prefs_filtering_action_get_matching_from_action(action_id);
@@ -791,8 +945,36 @@ static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
                }
                 score = strtol(score_str, NULL, 10);
                 break;
+       case ACTION_ADD_TO_ADDRESSBOOK:
+               header = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.header_entry), 0, -1);
+               if (*header == '\0') {
+                       if (alert)
+                                alertpanel_error(_("Header is not set."));
+                       g_free(header);
+                       return NULL;
+               }
+               destination = gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1);
+               if (*destination == '\0') {
+                       if (alert)
+                                alertpanel_error(_("Target addressbook/folder is not set."));
+                       g_free(destination);
+                       return NULL;
+               }
+               break;
+       case ACTION_SET_TAG:
+       case ACTION_UNSET_TAG:
+               destination = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(filtering_action.tags_combo)->entry), 0, -1);
+               if (*destination == '\0') {
+                       if (alert)
+                                alertpanel_error(_("Tag name is empty."));
+                       g_free(destination);
+                       return NULL;
+               }
+               break;
        case ACTION_STOP:
        case ACTION_HIDE:
+       case ACTION_IGNORE:
+       case ACTION_WATCH:
         case ACTION_DELETE:
         case ACTION_MARK:
         case ACTION_UNMARK:
@@ -800,12 +982,14 @@ static FilteringAction * prefs_filtering_action_dialog_to_action(gboolean alert)
         case ACTION_UNLOCK:
         case ACTION_MARK_AS_READ:
         case ACTION_MARK_AS_UNREAD:
+        case ACTION_MARK_AS_SPAM:
+        case ACTION_MARK_AS_HAM:
+        case ACTION_CLEAR_TAGS:
        default:
                break;
        }
-       
        action = filteringaction_new(action_type, account_id,
-            destination, labelcolor, score);
+            destination, labelcolor, score, header);
        
        g_free(destination);
        g_free(score_str);
@@ -833,6 +1017,7 @@ static void prefs_filtering_action_register_cb(void)
         * list items to be unselectable)
         * prefs_filtering_action_reset_dialog(); */
        gtk_list_select_item(GTK_LIST(filtering_action.account_list), 0);
+       gtk_list_select_item(GTK_LIST(filtering_action.tags_list), 0);
        gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), "");
 }
 
@@ -899,15 +1084,16 @@ static void prefs_filtering_action_up(void)
        GtkTreePath *prev, *sel, *try;
        GtkTreeIter isel;
        GtkListStore *store = NULL;
+       GtkTreeModel *model = NULL;
        GtkTreeIter iprev;
        
        if (!gtk_tree_selection_get_selected
                (gtk_tree_view_get_selection
                        (GTK_TREE_VIEW(filtering_action.action_list_view)),
-                (GtkTreeModel **)(GtkListStore *) store,       
+                &model,        
                 &isel))
                return;
-
+       store = (GtkListStore *)model;
        sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
        if (!sel)
                return;
@@ -940,16 +1126,17 @@ static void prefs_filtering_action_up(void)
 static void prefs_filtering_action_down(void)
 {
        GtkListStore *store = NULL;
+       GtkTreeModel *model = NULL;
        GtkTreeIter next, sel;
        GtkTreePath *try;
        
        if (!gtk_tree_selection_get_selected
                (gtk_tree_view_get_selection
                        (GTK_TREE_VIEW(filtering_action.action_list_view)),
-                (GtkTreeModel **)(GtkListStore *) store,
+                &model,
                 &sel))
                return;
-
+       store = (GtkListStore *)model;
        try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
        if (!try) 
                return;
@@ -986,7 +1173,8 @@ static gboolean prefs_filtering_action_key_pressed(GtkWidget *widget,
  */
 static void prefs_filtering_action_cancel(void)
 {
-       gtk_widget_hide(filtering_action.window);
+       gtk_widget_destroy(filtering_action.window);
+       filtering_action.window = NULL;
        inc_unlock();
 }
 
@@ -1012,7 +1200,8 @@ static void prefs_filtering_action_ok(void)
         }
         g_slist_free(action_list);
 
-       gtk_widget_hide(filtering_action.window);
+       gtk_widget_destroy(filtering_action.window);
+       filtering_action.window = NULL;
         inc_unlock();
 }
 
@@ -1038,7 +1227,7 @@ static gint prefs_filtering_action_deleted(GtkWidget *widget,
  * When adding new lines, remember to put 2 strings for each line
  */
 static gchar *exec_desc_strings[] = {
-       "%%",   "%",
+       "%%",   N_("literal %"),
        "%s",   N_("Subject"),
        "%f",   N_("From"),
        "%t",   N_("To"),
@@ -1047,10 +1236,10 @@ static gchar *exec_desc_strings[] = {
        "%i",   N_("Message-ID"),
        "%n",   N_("Newsgroups"),
        "%r",   N_("References"),
-       "%F",   N_("Filename - should not be modified"),
+       "%F",   N_("filename (should not be modified)"),
        "\\n",  N_("new line"),
        "\\",   N_("escape character for quotes"),
-       "\\\"",N_("quote character"),
+       "\\\"", N_("quote character"),
        NULL, NULL
 };
 
@@ -1058,8 +1247,11 @@ static DescriptionWindow exec_desc_win = {
        NULL,
         NULL, 
         2,
-        N_("Description of symbols"),
-        exec_desc_strings
+        N_("Filtering Action: 'Execute'"),
+       N_("'Execute' allows you to send a message or message element "
+          "to an external program or script.\n"
+          "The following symbols can be used:"),
+       exec_desc_strings
 };
 
 /*!
@@ -1084,6 +1276,20 @@ static void prefs_filtering_action_select_dest(void)
        g_free(path);
 }
 
+static void prefs_filtering_action_select_addressbook(void)
+{
+       gchar *folderpath = NULL;
+       gchar *prev = NULL;
+       gboolean ret = FALSE;
+
+       prev = g_strdup(gtk_editable_get_chars(GTK_EDITABLE(filtering_action.dest_entry), 0, -1));
+       folderpath = prev;
+       ret = addressbook_folder_selection(&folderpath);
+       if ( ret != FALSE && folderpath != NULL)
+               gtk_entry_set_text(GTK_ENTRY(filtering_action.dest_entry), folderpath);
+       g_free(prev);
+}
+
 static void prefs_filtering_action_type_selection_changed(GtkList *list,
     gpointer user_data)
 {
@@ -1097,11 +1303,15 @@ static void prefs_filtering_action_type_selection_changed(GtkList *list,
                ||  filtering_action.current_action == ACTION_REDIRECT) {
                        debug_print("unregistering address completion entry\n");
                        address_completion_unregister_entry(GTK_ENTRY(filtering_action.dest_entry));
+                       address_completion_end(filtering_action.window);
                }
                if (value == ACTION_FORWARD || value == ACTION_FORWARD_AS_ATTACHMENT
                ||  value == ACTION_REDIRECT) {
                        debug_print("registering address completion entry\n");
-                       address_completion_register_entry(GTK_ENTRY(filtering_action.dest_entry));
+                       address_completion_start(filtering_action.window);
+                       address_completion_register_entry(
+                                       GTK_ENTRY(filtering_action.dest_entry),
+                                       TRUE);
                }
                filtering_action.current_action = value;
        }
@@ -1118,7 +1328,12 @@ static void prefs_filtering_action_type_select(GtkList *list,
        case ACTION_MOVE:
                gtk_widget_show(filtering_action.account_label);
                gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
+               gtk_widget_show(filtering_action.account_combo);
                gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
+               gtk_widget_hide(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, FALSE);
+               gtk_widget_hide(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, FALSE);
                gtk_widget_show(filtering_action.dest_entry);
                gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
                gtk_widget_show(filtering_action.dest_btn);
@@ -1131,11 +1346,23 @@ static void prefs_filtering_action_type_select(GtkList *list,
                gtk_widget_hide(filtering_action.color_optmenu);
                gtk_widget_hide(filtering_action.color_label);
                gtk_widget_hide(filtering_action.score_label);
+               gtk_widget_hide(filtering_action.addressbook_label);
+               gtk_widget_hide(filtering_action.header_label);
+               gtk_widget_hide(filtering_action.header_combo);
+               gtk_widget_hide(filtering_action.header_entry);
+               gtk_widget_set_sensitive(filtering_action.header_entry, FALSE);
+               gtk_widget_hide(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, FALSE);
                break;
        case ACTION_COPY:
                gtk_widget_show(filtering_action.account_label);
                gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
+               gtk_widget_show(filtering_action.account_combo);
                gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
+               gtk_widget_hide(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, FALSE);
+               gtk_widget_hide(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, FALSE);
                gtk_widget_show(filtering_action.dest_entry);
                gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
                gtk_widget_show(filtering_action.dest_btn);
@@ -1148,11 +1375,23 @@ static void prefs_filtering_action_type_select(GtkList *list,
                gtk_widget_hide(filtering_action.color_optmenu);
                gtk_widget_hide(filtering_action.color_label);
                gtk_widget_hide(filtering_action.score_label);
+               gtk_widget_hide(filtering_action.header_label);
+               gtk_widget_hide(filtering_action.header_combo);
+               gtk_widget_hide(filtering_action.header_entry);
+               gtk_widget_set_sensitive(filtering_action.header_entry, FALSE);
+               gtk_widget_hide(filtering_action.addressbook_label);
+               gtk_widget_hide(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, FALSE);
                break;
        case ACTION_DELETE:
                gtk_widget_show(filtering_action.account_label);
                gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
+               gtk_widget_show(filtering_action.account_combo);
                gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
+               gtk_widget_hide(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, FALSE);
+               gtk_widget_hide(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, FALSE);
                gtk_widget_show(filtering_action.dest_entry);
                gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
                gtk_widget_show(filtering_action.dest_btn);
@@ -1165,6 +1404,13 @@ static void prefs_filtering_action_type_select(GtkList *list,
                gtk_widget_hide(filtering_action.color_optmenu);
                gtk_widget_hide(filtering_action.color_label);
                gtk_widget_hide(filtering_action.score_label);
+               gtk_widget_hide(filtering_action.header_label);
+               gtk_widget_hide(filtering_action.header_combo);
+               gtk_widget_hide(filtering_action.header_entry);
+               gtk_widget_set_sensitive(filtering_action.header_entry, FALSE);
+               gtk_widget_hide(filtering_action.addressbook_label);
+               gtk_widget_hide(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, FALSE);
                break;
        case ACTION_MARK:
        case ACTION_UNMARK:
@@ -1172,11 +1418,21 @@ static void prefs_filtering_action_type_select(GtkList *list,
        case ACTION_UNLOCK:
        case ACTION_MARK_AS_READ:
        case ACTION_MARK_AS_UNREAD:
+       case ACTION_MARK_AS_SPAM:
+       case ACTION_MARK_AS_HAM:
         case ACTION_STOP:
         case ACTION_HIDE:
+       case ACTION_IGNORE:
+       case ACTION_WATCH:
+       case ACTION_CLEAR_TAGS:
                gtk_widget_show(filtering_action.account_label);
                gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
+               gtk_widget_show(filtering_action.account_combo);
                gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
+               gtk_widget_hide(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, FALSE);
+               gtk_widget_hide(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, FALSE);
                gtk_widget_show(filtering_action.dest_entry);
                gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
                gtk_widget_show(filtering_action.dest_btn);
@@ -1189,11 +1445,23 @@ static void prefs_filtering_action_type_select(GtkList *list,
                gtk_widget_hide(filtering_action.color_optmenu);
                gtk_widget_hide(filtering_action.color_label);
                gtk_widget_hide(filtering_action.score_label);
+               gtk_widget_hide(filtering_action.header_label);
+               gtk_widget_hide(filtering_action.header_combo);
+               gtk_widget_hide(filtering_action.header_entry);
+               gtk_widget_set_sensitive(filtering_action.header_entry, FALSE);
+               gtk_widget_hide(filtering_action.addressbook_label);
+               gtk_widget_hide(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, FALSE);
                break;
        case ACTION_FORWARD:
                gtk_widget_show(filtering_action.account_label);
                gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
+               gtk_widget_show(filtering_action.account_combo);
                gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
+               gtk_widget_hide(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, FALSE);
+               gtk_widget_hide(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, FALSE);
                gtk_widget_show(filtering_action.dest_entry);
                gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
                gtk_widget_show(filtering_action.dest_btn);
@@ -1206,11 +1474,23 @@ static void prefs_filtering_action_type_select(GtkList *list,
                gtk_widget_hide(filtering_action.color_optmenu);
                gtk_widget_hide(filtering_action.color_label);
                gtk_widget_hide(filtering_action.score_label);
+               gtk_widget_hide(filtering_action.header_label);
+               gtk_widget_hide(filtering_action.header_combo);
+               gtk_widget_hide(filtering_action.header_entry);
+               gtk_widget_set_sensitive(filtering_action.header_entry, FALSE);
+               gtk_widget_hide(filtering_action.addressbook_label);
+               gtk_widget_hide(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, FALSE);
                break;
        case ACTION_FORWARD_AS_ATTACHMENT:
                gtk_widget_show(filtering_action.account_label);
                gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
+               gtk_widget_show(filtering_action.account_combo);
                gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
+               gtk_widget_hide(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, FALSE);
+               gtk_widget_hide(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, FALSE);
                gtk_widget_show(filtering_action.dest_entry);
                gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
                gtk_widget_show(filtering_action.dest_btn);
@@ -1223,11 +1503,23 @@ static void prefs_filtering_action_type_select(GtkList *list,
                gtk_widget_hide(filtering_action.color_optmenu);
                gtk_widget_hide(filtering_action.color_label);
                gtk_widget_hide(filtering_action.score_label);
+               gtk_widget_hide(filtering_action.header_label);
+               gtk_widget_hide(filtering_action.header_entry);
+               gtk_widget_hide(filtering_action.header_combo);
+               gtk_widget_set_sensitive(filtering_action.header_entry, FALSE);
+               gtk_widget_hide(filtering_action.addressbook_label);
+               gtk_widget_hide(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, FALSE);
                break;
        case ACTION_REDIRECT:
                gtk_widget_show(filtering_action.account_label);
                gtk_widget_set_sensitive(filtering_action.account_label, TRUE);
+               gtk_widget_show(filtering_action.account_combo);
                gtk_widget_set_sensitive(filtering_action.account_combo, TRUE);
+               gtk_widget_hide(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, FALSE);
+               gtk_widget_hide(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, FALSE);
                gtk_widget_show(filtering_action.dest_entry);
                gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
                gtk_widget_show(filtering_action.dest_btn);
@@ -1240,11 +1532,23 @@ static void prefs_filtering_action_type_select(GtkList *list,
                gtk_widget_hide(filtering_action.color_optmenu);
                gtk_widget_hide(filtering_action.color_label);
                gtk_widget_hide(filtering_action.score_label);
+               gtk_widget_hide(filtering_action.header_label);
+               gtk_widget_hide(filtering_action.header_combo);
+               gtk_widget_hide(filtering_action.header_entry);
+               gtk_widget_set_sensitive(filtering_action.header_entry, FALSE);
+               gtk_widget_hide(filtering_action.addressbook_label);
+               gtk_widget_hide(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, FALSE);
                break;
        case ACTION_EXECUTE:
                gtk_widget_show(filtering_action.account_label);
                gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
+               gtk_widget_show(filtering_action.account_combo);
                gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
+               gtk_widget_hide(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, FALSE);
+               gtk_widget_hide(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, FALSE);
                gtk_widget_show(filtering_action.dest_entry);
                gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
                gtk_widget_hide(filtering_action.dest_btn);
@@ -1256,11 +1560,23 @@ static void prefs_filtering_action_type_select(GtkList *list,
                gtk_widget_hide(filtering_action.color_optmenu);
                gtk_widget_hide(filtering_action.color_label);
                gtk_widget_hide(filtering_action.score_label);
+               gtk_widget_hide(filtering_action.header_label);
+               gtk_widget_hide(filtering_action.header_combo);
+               gtk_widget_hide(filtering_action.header_entry);
+               gtk_widget_set_sensitive(filtering_action.header_entry, FALSE);
+               gtk_widget_hide(filtering_action.addressbook_label);
+               gtk_widget_hide(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, FALSE);
                break;
        case ACTION_COLOR:
                gtk_widget_show(filtering_action.account_label);
                gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
+               gtk_widget_show(filtering_action.account_combo);
                gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
+               gtk_widget_hide(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, FALSE);
+               gtk_widget_hide(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, FALSE);
                gtk_widget_hide(filtering_action.dest_entry);
                gtk_widget_hide(filtering_action.dest_btn);
                gtk_widget_hide(filtering_action.dest_label);
@@ -1271,12 +1587,24 @@ static void prefs_filtering_action_type_select(GtkList *list,
                gtk_widget_show(filtering_action.color_optmenu);
                gtk_widget_show(filtering_action.color_label);
                gtk_widget_hide(filtering_action.score_label);
+               gtk_widget_hide(filtering_action.header_label);
+               gtk_widget_hide(filtering_action.header_combo);
+               gtk_widget_hide(filtering_action.header_entry);
+               gtk_widget_set_sensitive(filtering_action.header_entry, FALSE);
+               gtk_widget_hide(filtering_action.addressbook_label);
+               gtk_widget_hide(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, FALSE);
                break;
        case ACTION_CHANGE_SCORE:
        case ACTION_SET_SCORE:
                gtk_widget_show(filtering_action.account_label);
                gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
+               gtk_widget_show(filtering_action.account_combo);
                gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
+               gtk_widget_hide(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, FALSE);
+               gtk_widget_hide(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, FALSE);
                gtk_widget_show(filtering_action.dest_entry);
                gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
                gtk_widget_hide(filtering_action.dest_btn);
@@ -1288,6 +1616,72 @@ static void prefs_filtering_action_type_select(GtkList *list,
                gtk_widget_hide(filtering_action.color_optmenu);
                gtk_widget_hide(filtering_action.color_label);
                gtk_widget_show(filtering_action.score_label);
+               gtk_widget_hide(filtering_action.header_label);
+               gtk_widget_hide(filtering_action.header_combo);
+               gtk_widget_hide(filtering_action.header_entry);
+               gtk_widget_set_sensitive(filtering_action.header_entry, FALSE);
+               gtk_widget_hide(filtering_action.addressbook_label);
+               gtk_widget_hide(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, FALSE);
+               break;
+       case ACTION_ADD_TO_ADDRESSBOOK:
+               gtk_widget_hide(filtering_action.account_label);
+               gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
+               gtk_widget_hide(filtering_action.account_combo);
+               gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
+               gtk_widget_hide(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, FALSE);
+               gtk_widget_hide(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, FALSE);
+               gtk_widget_show(filtering_action.dest_entry);
+               gtk_widget_set_sensitive(filtering_action.dest_entry, TRUE);
+               gtk_widget_hide(filtering_action.dest_btn);
+               gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
+               gtk_widget_hide(filtering_action.dest_label);
+               gtk_widget_set_sensitive(filtering_action.dest_label, FALSE);
+               gtk_widget_hide(filtering_action.recip_label);
+               gtk_widget_hide(filtering_action.exec_label);
+               gtk_widget_hide(filtering_action.exec_btn);
+               gtk_widget_hide(filtering_action.color_optmenu);
+               gtk_widget_hide(filtering_action.color_label);
+               gtk_widget_hide(filtering_action.score_label);
+               gtk_widget_show(filtering_action.header_label);
+               gtk_widget_show(filtering_action.header_combo);
+               gtk_widget_show(filtering_action.header_entry);
+               gtk_widget_set_sensitive(filtering_action.header_entry, TRUE);
+               gtk_widget_show(filtering_action.addressbook_label);
+               gtk_widget_show(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, TRUE);
+               break;
+       case ACTION_SET_TAG:
+       case ACTION_UNSET_TAG:
+               gtk_widget_show(filtering_action.account_label);
+               gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
+               gtk_widget_show(filtering_action.account_combo);
+               gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
+               gtk_widget_show(filtering_action.tags_label);
+               gtk_widget_set_sensitive(filtering_action.tags_label, TRUE);
+               gtk_widget_show(filtering_action.tags_combo);
+               gtk_widget_set_sensitive(filtering_action.tags_combo, TRUE);
+               gtk_widget_hide(filtering_action.dest_entry);
+               gtk_widget_set_sensitive(filtering_action.dest_entry, FALSE);
+               gtk_widget_hide(filtering_action.dest_btn);
+               gtk_widget_set_sensitive(filtering_action.dest_btn, FALSE);
+               gtk_widget_hide(filtering_action.dest_label);
+               gtk_widget_hide(filtering_action.recip_label);
+               gtk_widget_set_sensitive(filtering_action.recip_label, TRUE);
+               gtk_widget_hide(filtering_action.exec_label);
+               gtk_widget_hide(filtering_action.exec_btn);
+               gtk_widget_hide(filtering_action.color_optmenu);
+               gtk_widget_hide(filtering_action.color_label);
+               gtk_widget_hide(filtering_action.score_label);
+               gtk_widget_hide(filtering_action.header_label);
+               gtk_widget_hide(filtering_action.header_combo);
+               gtk_widget_hide(filtering_action.header_entry);
+               gtk_widget_set_sensitive(filtering_action.header_entry, FALSE);
+               gtk_widget_hide(filtering_action.addressbook_label);
+               gtk_widget_hide(filtering_action.addressbook_btn);
+               gtk_widget_set_sensitive(filtering_action.addressbook_btn, FALSE);
                break;
        }
 }
@@ -1339,7 +1733,7 @@ static GtkWidget *prefs_filtering_action_list_view_create(void)
        list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
        g_object_unref(model);  
        
-       gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
+       gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
 
        selector = gtk_tree_view_get_selection(list_view);
        gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
@@ -1450,6 +1844,14 @@ static gboolean prefs_filtering_actions_selected
                gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
                                     ACTION_MARK_AS_UNREAD);
                break;
+       case MATCHACTION_MARK_AS_SPAM:
+               gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
+                                    ACTION_MARK_AS_SPAM);
+               break;
+       case MATCHACTION_MARK_AS_HAM:
+               gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
+                                    ACTION_MARK_AS_HAM);
+               break;
        case MATCHACTION_FORWARD:
                list_id = get_list_id_from_account_id(action->account_id);
                gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
@@ -1496,9 +1898,23 @@ static gboolean prefs_filtering_actions_selected
                gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
                                     ACTION_HIDE);
                break;
+       case MATCHACTION_IGNORE:
+               gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
+                                    ACTION_IGNORE);
+               break;
+       case MATCHACTION_WATCH:
+               gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
+                                    ACTION_WATCH);
+               break;
+       case MATCHACTION_ADD_TO_ADDRESSBOOK:
+               if (action->header)
+                       gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), action->header);
+               else
+                       gtk_entry_set_text(GTK_ENTRY(filtering_action.header_entry), "");
+               gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
+                                    ACTION_ADD_TO_ADDRESSBOOK);
        }
 
        filteringaction_free(action); /* XXX: memleak */
        return TRUE;
 }
-