revise label colouring, add filter action for label colouring, fix filtering issues
[claws.git] / src / prefs_matcher.c
index 2092b41fddc5a1d9604126ceb0f82dbfa784171d..df2a165d10b97f4092c2eb42a359f44242bc00db 100644 (file)
 static struct Matcher {
        GtkWidget *window;
 
-       GtkWidget *close_btn;
+       GtkWidget *ok_btn;
+
+       GtkWidget *predicate_combo;
+       GtkWidget *predicate_flag_combo;
+       GtkWidget *header_combo;
+
+       GtkWidget *criteria_list;
+
+       GtkWidget *predicate_list;
+       GtkWidget *predicate_label;
+       GtkWidget *predicate_flag_list;
+
+       GtkWidget *bool_op_list;
 
-       GtkWidget *criteria_entry;
        GtkWidget *header_entry;
        GtkWidget *header_label;
        GtkWidget *value_entry;
        GtkWidget *value_label;
-       GtkWidget *predicate_label;
-       GtkWidget *predicate_entry;
        GtkWidget *case_chkbtn;
        GtkWidget *regexp_chkbtn;
-       GtkWidget *bool_op_entry;
+
+       GtkWidget *exec_btn;
 
        GtkWidget *cond_clist;
 } matcher;
@@ -69,75 +79,94 @@ static struct Matcher {
 
 enum {
        CRITERIA_ALL = 0,
+
        CRITERIA_SUBJECT = 1,
        CRITERIA_FROM = 2,
        CRITERIA_TO = 3,
        CRITERIA_CC = 4,
        CRITERIA_TO_OR_CC = 5,
        CRITERIA_NEWSGROUPS = 6,
-       CRITERIA_AGE_GREATER = 7,
-       CRITERIA_AGE_LOWER = 8,
-       CRITERIA_HEADER = 9,
-       CRITERIA_HEADERS_PART = 10,
-       CRITERIA_BODY_PART = 11,
-       CRITERIA_MESSAGE = 12
+       CRITERIA_INREPLYTO = 7,
+       CRITERIA_REFERENCES = 8,
+       CRITERIA_AGE_GREATER = 9,
+       CRITERIA_AGE_LOWER = 10,
+       CRITERIA_HEADER = 11,
+       CRITERIA_HEADERS_PART = 12,
+       CRITERIA_BODY_PART = 13,
+       CRITERIA_MESSAGE = 14,
+
+       CRITERIA_UNREAD = 15,
+       CRITERIA_NEW = 16,
+       CRITERIA_MARKED = 17,
+       CRITERIA_DELETED = 18,
+       CRITERIA_REPLIED = 19,
+       CRITERIA_FORWARDED = 20,
+
+       CRITERIA_SCORE_GREATER = 21,
+       CRITERIA_SCORE_LOWER = 22,
+
+       CRITERIA_EXECUTE = 23
+};
+
+enum {
+       BOOL_OP_OR = 0,
+       BOOL_OP_AND = 1
 };
 
 gchar * bool_op_text [] = {
-       "and", "or"
+       "or", "and"
+};
+
+enum {
+       PREDICATE_CONTAINS = 0,
+       PREDICATE_DOES_NOT_CONTAIN = 1
 };
 
 gchar * predicate_text [] = {
        "contains", "does not contain"
 };
 
+enum {
+       PREDICATE_FLAG_ENABLED = 0,
+       PREDICATE_FLAG_DISABLED = 1
+};
+
+gchar * predicate_flag_text [] = {
+       "yes", "no"
+};
+
 gchar * criteria_text [] = {
        "All messages", "Subject",
        "From", "To", "Cc", "To or Cc",
-       "Newsgroups",
+       "Newsgroups", "In reply to", "References",
        "Age greater than", "Age lower than",
        "Header", "Headers part",
-       "Body part", "Whole message"
+       "Body part", "Whole message",
+       "Unread flag", "New flag",
+       "Marked flag", "Deleted flag",
+       "Replied flag", "Forwarded flag",
+       "Score greater than", "Score lower than",
+       "Execute"
 };
 
-gint criteria_get_from_string(gchar * text)
+static gint get_sel_from_list(GtkList * list)
 {
-       gint i;
-       
-       for(i = 0 ; i < (gint) (sizeof(criteria_text) / sizeof(gchar *)) ;
-           i++) {
-               if (strcmp(_(criteria_text[i]), text) == 0)
-                       return i;
+       gint row = 0;
+       void * sel;
+       GList * child;
+
+       sel = list->selection->data;
+       for(child = list->children ; child != NULL ;
+           child = g_list_next(child)) {
+               if (child->data == sel)
+                       return row;
+               row ++;
        }
-       return -1;
-}
-
-gint predicate_get_from_string(gchar * text)
-{
-       gint i;
        
-       for(i = 0 ; i < (gint) (sizeof(predicate_text) / sizeof(gchar *)) ;
-           i++) {
-               if (strcmp(_(predicate_text[i]), text) == 0)
-                       return i;
-       }
-       return -1;
+       return row;
 }
 
-enum {
-       PREDICATE_CONTAINS = 0,
-       PREDICATE_DOES_NOT_CONTAIN = 1
-};
-
-/* static MatcherList * tmp_list; */
-/* static MatcherProp * tmp_matcher; */
-
-/*
-   parameter name, default value, pointer to the prefs variable, data type,
-   pointer to the widget pointer,
-   pointer to the function for data setting,
-   pointer to the function for widget setting
- */
+static PrefsMatcherSignal * matchers_callback;
 
 #define VSPACING               12
 #define VSPACING_NARROW                4
@@ -147,7 +176,7 @@ enum {
 /* widget creating functions */
 static void prefs_matcher_create       (void);
 
-static void prefs_matcher_set_dialog   (void);
+static void prefs_matcher_set_dialog   (MatcherList * matchers);
 
 /*
 static void prefs_matcher_set_list     (void);
@@ -164,28 +193,25 @@ static void prefs_matcher_substitute_cb   (void);
 static void prefs_matcher_delete_cb    (void);
 static void prefs_matcher_up           (void);
 static void prefs_matcher_down         (void);
-/*
-static void prefs_matcher_select               (GtkCList       *clist,
+static void prefs_matcher_select       (GtkCList       *clist,
                                         gint            row,
                                         gint            column,
                                         GdkEvent       *event);
-*/
-
-/*
-static void prefs_matcher_dest_radio_button_toggled    (void);
-static void prefs_matcher_notrecv_radio_button_toggled (void);
-*/
 
 static void prefs_matcher_key_pressed  (GtkWidget      *widget,
                                         GdkEventKey    *event,
                                         gpointer        data);
-static void prefs_matcher_close                (void);
+static void prefs_matcher_ok           (void);
+static void prefs_matcher_cancel               (void);
 static gint prefs_matcher_deleted(GtkWidget *widget, GdkEventAny *event,
                                  gpointer data);
-static void prefs_matcher_criteria_select(GtkEditable *editable,
+static void prefs_matcher_criteria_select(GtkList *list,
+                                         GtkWidget *widget,
                                          gpointer user_data);
+static MatcherList * prefs_matcher_get_list(void);
+static void prefs_matcher_exec_info_create(void);
 
-void prefs_matcher_open(MatcherList * matchers)
+void prefs_matcher_open(MatcherList * matchers, PrefsMatcherSignal * cb)
 {
        inc_autocheck_timer_remove();
 
@@ -194,10 +220,11 @@ void prefs_matcher_open(MatcherList * matchers)
        }
 
        manage_window_set_transient(GTK_WINDOW(matcher.window));
-       gtk_widget_grab_focus(matcher.close_btn);
+       gtk_widget_grab_focus(matcher.ok_btn);
 
-       /*      tmp_matchers = matchers; */
-       prefs_matcher_set_dialog();
+       matchers_callback = cb;
+
+       prefs_matcher_set_dialog(matchers);
 
        gtk_widget_show(matcher.window);
 }
@@ -206,7 +233,8 @@ static void prefs_matcher_create(void)
 {
        GtkWidget *window;
        GtkWidget *vbox;
-       GtkWidget *close_btn;
+       GtkWidget *ok_btn;
+       GtkWidget *cancel_btn;
        GtkWidget *confirm_area;
 
        GtkWidget *vbox1;
@@ -220,15 +248,17 @@ static void prefs_matcher_create(void)
        GtkWidget *header_entry;
        GtkWidget *header_label;
        GtkWidget *criteria_combo;
-       GtkWidget *criteria_entry;
+       GtkWidget *criteria_list;
        GtkWidget *criteria_label;
        GtkWidget *value_label;
        GtkWidget *value_entry;
        GtkWidget *predicate_combo;
-       GtkWidget *predicate_entry;
+       GtkWidget *predicate_list;
+       GtkWidget *predicate_flag_combo;
+       GtkWidget *predicate_flag_list;
        GtkWidget *predicate_label;
        GtkWidget *bool_op_combo;
-       GtkWidget *bool_op_entry;
+       GtkWidget *bool_op_list;
        GtkWidget *bool_op_label;
 
        GtkWidget *regexp_chkbtn;
@@ -249,6 +279,8 @@ static void prefs_matcher_create(void)
        GtkWidget *up_btn;
        GtkWidget *down_btn;
 
+       GtkWidget *exec_btn;
+
        GList *combo_items;
        gint i;
 
@@ -266,11 +298,11 @@ static void prefs_matcher_create(void)
        gtk_widget_show (vbox);
        gtk_container_add (GTK_CONTAINER (window), vbox);
 
-       gtkut_button_set_create (&confirm_area, &close_btn, _("Close"),
-                                NULL, NULL, NULL, NULL);
+       gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
+                               &cancel_btn, _("Cancel"), NULL, NULL);
        gtk_widget_show (confirm_area);
        gtk_box_pack_end (GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
-       gtk_widget_grab_default (close_btn);
+       gtk_widget_grab_default (ok_btn);
 
        gtk_window_set_title (GTK_WINDOW(window),
                              _("Condition setting"));
@@ -282,18 +314,20 @@ static void prefs_matcher_create(void)
                            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);
-       gtk_signal_connect (GTK_OBJECT(close_btn), "clicked",
-                           GTK_SIGNAL_FUNC(prefs_matcher_close), NULL);
+       gtk_signal_connect (GTK_OBJECT(ok_btn), "clicked",
+                           GTK_SIGNAL_FUNC(prefs_matcher_ok), NULL);
+       gtk_signal_connect (GTK_OBJECT(cancel_btn), "clicked",
+                           GTK_SIGNAL_FUNC(prefs_matcher_cancel), NULL);
 
        vbox1 = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox1);
        gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
        gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
 
-       table1 = gtk_table_new (2, 3, FALSE);
+       table1 = gtk_table_new (2, 4, FALSE);
        gtk_widget_show (table1);
 
-       gtk_box_pack_start (GTK_BOX (vbox1), table1, FALSE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (vbox1), table1, FALSE, FALSE, 0);
        gtk_table_set_row_spacings (GTK_TABLE (table1), 8);
        gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
 
@@ -322,13 +356,13 @@ static void prefs_matcher_create(void)
        gtk_widget_set_usize (criteria_combo, 120, -1);
        gtk_table_attach (GTK_TABLE (table1), criteria_combo, 0, 1, 1, 2,
                          0, 0, 0, 0);
-       criteria_entry = GTK_COMBO(criteria_combo)->entry;
-       gtk_signal_connect (GTK_OBJECT (criteria_entry), "changed",
+       criteria_list = GTK_COMBO(criteria_combo)->list;
+       gtk_signal_connect (GTK_OBJECT (criteria_list), "select-child",
                            GTK_SIGNAL_FUNC (prefs_matcher_criteria_select),
                            NULL);
 
-       criteria_entry = GTK_COMBO (criteria_combo)->entry;
-       gtk_entry_set_editable (GTK_ENTRY (criteria_entry), FALSE);
+       gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(criteria_combo)->entry),
+                              FALSE);
 
        /* header name */
 
@@ -357,24 +391,31 @@ static void prefs_matcher_create(void)
        gtk_widget_show (value_label);
        gtk_misc_set_alignment (GTK_MISC (value_label), 0, 0.5);
        gtk_table_attach (GTK_TABLE (table1), value_label, 2, 3, 0, 1,
-                         GTK_FILL, 0, 0, 0);
+                         GTK_FILL | GTK_SHRINK | GTK_EXPAND, 0, 0, 0);
 
        value_entry = gtk_entry_new ();
        gtk_widget_show (value_entry);
        gtk_widget_set_usize (value_entry, 200, -1);
        gtk_table_attach (GTK_TABLE (table1), value_entry, 2, 3, 1, 2,
-                         0, 0, 0, 0);
-
+                         GTK_FILL | GTK_SHRINK | GTK_EXPAND, 0, 0, 0);
+
+       exec_btn = gtk_button_new_with_label (_("Info ..."));
+       gtk_widget_show (exec_btn);
+       gtk_table_attach (GTK_TABLE (table1), exec_btn, 3, 4, 1, 2,
+                         GTK_FILL | GTK_SHRINK | GTK_EXPAND, 0, 0, 0);
+       gtk_signal_connect (GTK_OBJECT (exec_btn), "clicked",
+                           GTK_SIGNAL_FUNC (prefs_matcher_exec_info),
+                           NULL);
 
        /* predicate */
 
        vbox2 = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox2);
-       gtk_box_pack_start (GTK_BOX (vbox1), vbox2, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
 
        hbox1 = gtk_hbox_new (FALSE, 8);
        gtk_widget_show (hbox1);
-       gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
 
        predicate_label = gtk_label_new (_("Predicate"));
        gtk_widget_show (predicate_label);
@@ -384,8 +425,9 @@ static void prefs_matcher_create(void)
        predicate_combo = gtk_combo_new ();
        gtk_widget_show (predicate_combo);
        gtk_widget_set_usize (predicate_combo, 120, -1);
-       predicate_entry = GTK_COMBO(predicate_combo)->entry;
-       gtk_entry_set_editable (GTK_ENTRY (predicate_entry), FALSE);
+       predicate_list = GTK_COMBO(predicate_combo)->list;
+       gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(predicate_combo)->entry),
+                              FALSE);
 
        combo_items = NULL;
 
@@ -401,9 +443,31 @@ static void prefs_matcher_create(void)
        gtk_box_pack_start (GTK_BOX (hbox1), predicate_combo,
                            FALSE, FALSE, 0);
 
+       /* predicate flag */
+
+       predicate_flag_combo = gtk_combo_new ();
+       gtk_widget_hide (predicate_flag_combo);
+       gtk_widget_set_usize (predicate_flag_combo, 120, -1);
+       predicate_flag_list = GTK_COMBO(predicate_flag_combo)->list;
+       gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(predicate_flag_combo)->entry), FALSE);
+
+       combo_items = NULL;
+
+       for(i = 0 ; i < (gint) (sizeof(predicate_text) / sizeof(gchar *)) ;
+           i++) {
+               combo_items = g_list_append(combo_items, (gpointer) _(predicate_flag_text[i]));
+       }
+       gtk_combo_set_popdown_strings(GTK_COMBO(predicate_flag_combo),
+                                     combo_items);
+
+       g_list_free(combo_items);
+
+       gtk_box_pack_start (GTK_BOX (hbox1), predicate_flag_combo,
+                           FALSE, FALSE, 0);
+
        vbox3 = gtk_vbox_new (FALSE, 0);
        gtk_widget_show (vbox3);
-       gtk_box_pack_start (GTK_BOX (hbox1), vbox3, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (hbox1), vbox3, FALSE, FALSE, 0);
 
        PACK_CHECK_BUTTON (vbox3, case_chkbtn, _("Case sensitive"));
        PACK_CHECK_BUTTON (vbox3, regexp_chkbtn, _("Use regexp"));
@@ -444,12 +508,6 @@ static void prefs_matcher_create(void)
 
        /* boolean operation */
 
-       /*
-       hbox1 = gtk_hbox_new (TRUE, 4);
-       gtk_widget_show (btn_hbox);
-       gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
-       */
-
        bool_op_label = gtk_label_new (_("Boolean Op"));
        gtk_misc_set_alignment (GTK_MISC (value_label), 0, 0.5);
        gtk_widget_show (bool_op_label);
@@ -459,8 +517,9 @@ static void prefs_matcher_create(void)
        bool_op_combo = gtk_combo_new ();
        gtk_widget_show (bool_op_combo);
        gtk_widget_set_usize (bool_op_combo, 50, -1);
-       bool_op_entry = GTK_COMBO(bool_op_combo)->entry;
-       gtk_entry_set_editable (GTK_ENTRY (bool_op_entry), FALSE);
+       bool_op_list = GTK_COMBO(bool_op_combo)->list;
+       gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(bool_op_combo)->entry),
+                              FALSE);
 
        combo_items = NULL;
 
@@ -474,7 +533,7 @@ static void prefs_matcher_create(void)
        g_list_free(combo_items);
 
        gtk_box_pack_start (GTK_BOX (btn_hbox), bool_op_combo,
-                           FALSE, TRUE, 0);
+                           FALSE, FALSE, 0);
 
        cond_hbox = gtk_hbox_new (FALSE, 8);
        gtk_widget_show (cond_hbox);
@@ -497,10 +556,8 @@ static void prefs_matcher_create(void)
                                      GTK_SELECTION_BROWSE);
        GTK_WIDGET_UNSET_FLAGS (GTK_CLIST (cond_clist)->column[0].button,
                                GTK_CAN_FOCUS);
-       /*
        gtk_signal_connect (GTK_OBJECT (cond_clist), "select_row",
                            GTK_SIGNAL_FUNC (prefs_matcher_select), NULL);
-       */
 
        btn_vbox = gtk_vbox_new (FALSE, 8);
        gtk_widget_show (btn_vbox);
@@ -521,246 +578,223 @@ static void prefs_matcher_create(void)
        gtk_widget_show_all(window);
 
        matcher.window    = window;
-       matcher.close_btn = close_btn;
 
-       matcher.criteria_entry = criteria_entry;
+       matcher.ok_btn = ok_btn;
+
+       matcher.criteria_list = criteria_list;
+       matcher.header_combo = header_combo;
        matcher.header_entry = header_entry;
        matcher.header_label = header_label;
        matcher.value_entry = value_entry;
        matcher.value_label = value_label;
        matcher.predicate_label = predicate_label;
-       matcher.predicate_entry = predicate_entry;
+       matcher.predicate_list = predicate_list;
+       matcher.predicate_combo = predicate_combo;
+       matcher.predicate_flag_list = predicate_flag_list;
+       matcher.predicate_flag_combo = predicate_flag_combo;
        matcher.case_chkbtn = case_chkbtn;
        matcher.regexp_chkbtn = regexp_chkbtn;
+       matcher.bool_op_list = bool_op_list;
+       matcher.exec_btn = exec_btn;
 
        matcher.cond_clist   = cond_clist;
 }
 
-/*
-void prefs_matcher_read_config(void)
+static gint prefs_matcher_clist_set_row(gint row, MatcherProp * prop)
 {
-       gchar *rcpath;
-       FILE *fp;
-       gchar buf[PREFSBUFSIZE];
-       Matcher *flt;
-
-       debug_print(_("Reading matcher configuration...\n"));
-
-       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, FILTER_RC, NULL);
-       if ((fp = fopen(rcpath, "r")) == NULL) {
-               if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
-               g_free(rcpath);
-               return;
-       }
-       g_free(rcpath);
-*/
-
-       /* remove all previous matcher list */
+       GtkCList *clist = GTK_CLIST(matcher.cond_clist);
+       gchar * cond_str[1];
+       gchar * matcher_str;
 
-/*
-       while (prefs_common.fltlist != NULL) {
-               flt = (Matcher *)prefs_common.fltlist->data;
-               filter_free(flt);
-               prefs_common.fltlist = g_slist_remove(prefs_common.fltlist,
-                                                     flt);
+       if (prop == NULL) {
+               cond_str[0] = _("(New)");
+               return gtk_clist_append(clist, cond_str);
        }
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
-               g_strchomp(buf);
-               flt = filter_read_str(buf);
-               if (flt) {
-                       prefs_common.fltlist =
-                               g_slist_append(prefs_common.fltlist, flt);
-               }
-       }
+       matcher_str = matcherprop_to_string(prop);
+       cond_str[0] = matcher_str;
+       if (row < 0)
+               row = gtk_clist_append(clist, cond_str);
+       else
+               gtk_clist_set_text(clist, row, 0, cond_str[0]);
+       g_free(matcher_str);
 
-       fclose(fp);
+       return row;
 }
 
-void prefs_filter_write_config(void)
+static void prefs_matcher_reset_condition(void)
 {
-       gchar *rcpath;
-       PrefFile *pfile;
-       GSList *cur;
-
-       debug_print(_("Writing filter configuration...\n"));
-
-       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, FILTER_RC, NULL);
-       if ((pfile = prefs_write_open(rcpath)) == NULL) {
-               g_warning(_("failed to write configuration to file\n"));
-               g_free(rcpath);
-               return;
-       }
-
-       for (cur = prefs_common.fltlist; cur != NULL; cur = cur->next) {
-               Filter *flt = (Filter *)cur->data;
-               gchar *fstr;
-
-               fstr = filter_get_str(flt);
-               if (fputs(fstr, pfile->fp) == EOF ||
-                   fputc('\n', pfile->fp) == EOF) {
-                       FILE_OP_ERROR(rcpath, "fputs || fputc");
-                       prefs_write_close_revert(pfile);
-                       g_free(rcpath);
-                       g_free(fstr);
-                       return;
-               }
-               g_free(fstr);
-       }
-
-       g_free(rcpath);
+       gtk_list_select_item(GTK_LIST(matcher.criteria_list), 0);
+       gtk_list_select_item(GTK_LIST(matcher.predicate_list), 0);
+       gtk_entry_set_text(GTK_ENTRY(matcher.header_entry), "");
+       gtk_entry_set_text(GTK_ENTRY(matcher.value_entry), "");
+}
 
-       if (prefs_write_close(pfile) < 0) {
-               g_warning(_("failed to write configuration to file\n"));
-               return;
-       }
+static void prefs_matcher_update_hscrollbar(void)
+{
+       gint optwidth = gtk_clist_optimal_column_width(GTK_CLIST(matcher.cond_clist), 0);
+       gtk_clist_set_column_width(GTK_CLIST(matcher.cond_clist), 0, optwidth);
 }
-*/
 
-static void prefs_matcher_set_dialog(void)
+static void prefs_matcher_set_dialog(MatcherList * matchers)
 {
-       /*
-       GtkCList *clist = GTK_CLIST(filter.cond_clist);
-       GSList *cur;
-       gchar *cond_str[1];
-       gint row;
+       GtkCList *clist = GTK_CLIST(matcher.cond_clist);
+       GSList * cur;
+       gboolean bool_op = 1;
 
        gtk_clist_freeze(clist);
        gtk_clist_clear(clist);
 
-       cond_str[0] = _("(New)");
-       row = gtk_clist_append(clist, cond_str);
-       gtk_clist_set_row_data(clist, row, NULL);
-
-       for (cur = prefs_common.fltlist; cur != NULL; cur = cur->next) {
-               Filter *flt = (Filter *)cur->data;
-
-               cond_str[0] = filter_get_str(flt);
-               subst_char(cond_str[0], '\t', ':');
-               row = gtk_clist_append(clist, cond_str);
-               gtk_clist_set_row_data(clist, row, flt);
+       prefs_matcher_clist_set_row(-1, NULL);
+       if (matchers != NULL) {
+               for (cur = matchers->matchers ; cur != NULL ;
+                    cur = g_slist_next(cur)) {
+                       MatcherProp * prop;
+                       prop = (MatcherProp *) cur->data;
+                       prefs_matcher_clist_set_row(-1, prop);
+               }
 
-               g_free(cond_str[0]);
+               bool_op = matchers->bool_and;
        }
+       
+       prefs_matcher_update_hscrollbar();
 
        gtk_clist_thaw(clist);
-       */
 
-       gtk_entry_set_text(GTK_ENTRY(matcher.criteria_entry),
-                          _(criteria_text[0]));
-       gtk_entry_set_text(GTK_ENTRY(matcher.predicate_entry),
-                          _(predicate_text[0]));
-       gtk_entry_set_text(GTK_ENTRY(matcher.header_entry), "");
-}
-/*
-static void prefs_filter_set_list(void)
-{
-       gint row = 1;
-       Filter *flt;
+       gtk_list_select_item(GTK_LIST(matcher.bool_op_list), bool_op);
 
-       g_slist_free(prefs_common.fltlist);
-       prefs_common.fltlist = NULL;
-
-       while ((flt = gtk_clist_get_row_data(GTK_CLIST(filter.cond_clist),
-               row)) != NULL) {
-               prefs_common.fltlist = g_slist_append(prefs_common.fltlist,
-                                                     flt);
-               row++;
-       }
+       prefs_matcher_reset_condition();
 }
 
-#define GET_ENTRY(entry) \
-       entry_text = gtk_entry_get_text(GTK_ENTRY(entry))
-
-static gint prefs_filter_clist_set_row(gint row)
+static MatcherList * prefs_matcher_get_list(void)
 {
-       GtkCList *clist = GTK_CLIST(filter.cond_clist);
-       Filter *flt;
-       gchar *entry_text;
-       gchar *cond_str[1];
-
-       g_return_val_if_fail(row != 0, -1);
-
-       if (GTK_WIDGET_IS_SENSITIVE(filter.dest_entry))
-               GET_ENTRY(filter.dest_entry);
-       else
-               entry_text = FILTER_NOT_RECEIVE;
-       if (entry_text[0] == '\0') {
-               alertpanel_error(_("Destination is not set."));
-               return -1;
-       }
-       GET_ENTRY(filter.hdr_entry1);
-       if (entry_text[0] == '\0') {
-               alertpanel_error(_("Header name is not set."));
-               return -1;
-       }
-
-       flt = g_new0(Filter, 1);
-
-       flt->name1 = g_strdup(entry_text);
-
-       GET_ENTRY(filter.key_entry1);
-       if (entry_text[0] != '\0')
-               flt->body1 = g_strdup(entry_text);
-
-       GET_ENTRY(filter.hdr_entry2);
-       if (entry_text[0] != '\0' && strcmp(entry_text, _("(none)")) != 0) {
-               flt->name2 = g_strdup(entry_text);
-
-               GET_ENTRY(filter.key_entry2);
-               if (entry_text[0] != '\0')
-                       flt->body2 = g_strdup(entry_text);
+       gchar * matcher_str;
+       MatcherProp * prop;
+       gint row = 1;
+       gchar * tmp;
+       gboolean bool_and;
+       GSList * matcher_list;
+       MatcherList * matchers;
+
+       matcher_list = NULL;
+
+       while (gtk_clist_get_text(GTK_CLIST(matcher.cond_clist),
+                                 row, 0, &matcher_str)) {
+
+               if (strcmp(matcher_str, _("(New)")) != 0) {
+                       tmp = matcher_str;
+                       prop = matcherprop_parse(&tmp);
+                       
+                       if (tmp == NULL)
+                               break;
+                       
+                       matcher_list = g_slist_append(matcher_list, prop);
+               }
+               row ++;
        }
 
-       GET_ENTRY(filter.pred_entry1);
-       if (!strcmp(entry_text, _("contains")))
-               flt->flag1 = FLT_CONTAIN;
-       GET_ENTRY(filter.pred_entry2);
-       if (!strcmp(entry_text, _("contains")))
-               flt->flag2 = FLT_CONTAIN;
-
-       GET_ENTRY(filter.op_entry);
-       if (!strcmp(entry_text, "and"))
-               flt->cond = FLT_AND;
-       else
-               flt->cond = FLT_OR;
-
-       if (GTK_WIDGET_IS_SENSITIVE(filter.dest_entry)) {
-               entry_text = gtk_entry_get_text(GTK_ENTRY(filter.dest_entry));
-               flt->dest = g_strdup(entry_text);
-               flt->action = FLT_MOVE;
-       } else
-               flt->action = FLT_NOTRECV;
+       bool_and = get_sel_from_list(GTK_LIST(matcher.bool_op_list));
 
-       cond_str[0] = filter_get_str(flt);
-       subst_char(cond_str[0], '\t', ':');
+       matchers = matcherlist_new(matcher_list, bool_and);
 
-       if (row < 0)
-               row = gtk_clist_append(clist, cond_str);
-       else {
-               Filter *tmpflt;
+       return matchers;
+}
 
-               gtk_clist_set_text(clist, row, 0, cond_str[0]);
-               tmpflt = gtk_clist_get_row_data(clist, row);
-               if (tmpflt)
-                       filter_free(tmpflt);
+static gint prefs_matcher_get_criteria_from_matching(gint matching_id)
+{
+       switch(matching_id) {
+       case MATCHING_ALL:
+               return CRITERIA_ALL;
+       case MATCHING_NOT_UNREAD:
+       case MATCHING_UNREAD:
+               return CRITERIA_UNREAD;
+       case MATCHING_NOT_NEW:
+       case MATCHING_NEW:
+               return CRITERIA_NEW;
+       case MATCHING_NOT_MARKED:
+       case MATCHING_MARKED:
+               return CRITERIA_MARKED;
+       case MATCHING_NOT_DELETED:
+       case MATCHING_DELETED:
+               return CRITERIA_DELETED;
+               break;
+       case MATCHING_NOT_REPLIED:
+       case MATCHING_REPLIED:
+               return CRITERIA_REPLIED;
+       case MATCHING_NOT_FORWARDED:
+       case MATCHING_FORWARDED:
+               return CRITERIA_FORWARDED;
+       case MATCHING_NOT_SUBJECT:
+       case MATCHING_SUBJECT:
+               return CRITERIA_SUBJECT;
+       case MATCHING_NOT_FROM:
+       case MATCHING_FROM:
+               return CRITERIA_FROM;
+       case MATCHING_NOT_TO:
+       case MATCHING_TO:
+               return CRITERIA_TO;
+       case MATCHING_NOT_CC:
+       case MATCHING_CC:
+               return CRITERIA_CC;
+       case MATCHING_NOT_NEWSGROUPS:
+       case MATCHING_NEWSGROUPS:
+               return CRITERIA_NEWSGROUPS;
+       case MATCHING_NOT_INREPLYTO:
+       case MATCHING_INREPLYTO:
+               return CRITERIA_INREPLYTO;
+       case MATCHING_NOT_REFERENCES:
+       case MATCHING_REFERENCES:
+               return CRITERIA_REFERENCES;
+       case MATCHING_NOT_TO_AND_NOT_CC:
+       case MATCHING_TO_OR_CC:
+               return CRITERIA_TO_OR_CC;
+       case MATCHING_NOT_BODY_PART:
+       case MATCHING_BODY_PART:
+               return CRITERIA_BODY_PART;
+       case MATCHING_NOT_MESSAGE:
+       case MATCHING_MESSAGE:
+               return CRITERIA_MESSAGE;
+               break;
+       case MATCHING_NOT_HEADERS_PART:
+       case MATCHING_HEADERS_PART:
+               return CRITERIA_HEADERS_PART;
+       case MATCHING_NOT_HEADER:
+       case MATCHING_HEADER:
+               return CRITERIA_HEADER;
+       case MATCHING_AGE_GREATER:
+               return CRITERIA_AGE_GREATER;
+       case MATCHING_AGE_LOWER:
+               return CRITERIA_AGE_LOWER;
+       case MATCHING_SCORE_GREATER:
+               return CRITERIA_SCORE_GREATER;
+       case MATCHING_SCORE_LOWER:
+               return CRITERIA_SCORE_LOWER;
+       case MATCHING_NOT_EXECUTE:
+       case MATCHING_EXECUTE:
+               return CRITERIA_EXECUTE;
+               break;
+       default:
+               return -1;
        }
-
-       gtk_clist_set_row_data(clist, row, flt);
-
-       g_free(cond_str[0]);
-
-       prefs_filter_set_list();
-
-       return row;
 }
-*/
 
-static gint prefs_matcher_get_scoring_from_criteria(gint criteria_id)
+static gint prefs_matcher_get_matching_from_criteria(gint criteria_id)
 {
        switch (criteria_id) {
        case CRITERIA_ALL:
                return MATCHING_ALL;
+       case CRITERIA_UNREAD:
+               return MATCHING_UNREAD;
+       case CRITERIA_NEW:
+               return MATCHING_NEW;
+       case CRITERIA_MARKED:
+               return MATCHING_MARKED;
+       case CRITERIA_DELETED:
+               return MATCHING_DELETED;
+       case CRITERIA_REPLIED:
+               return MATCHING_REPLIED;
+       case CRITERIA_FORWARDED:
+               return MATCHING_FORWARDED;
        case CRITERIA_SUBJECT:
                return MATCHING_SUBJECT;
        case CRITERIA_FROM:
@@ -773,10 +807,18 @@ static gint prefs_matcher_get_scoring_from_criteria(gint criteria_id)
                return MATCHING_TO_OR_CC;
        case CRITERIA_NEWSGROUPS:
                return MATCHING_NEWSGROUPS;
+       case CRITERIA_INREPLYTO:
+               return MATCHING_INREPLYTO;
+       case CRITERIA_REFERENCES:
+               return MATCHING_REFERENCES;
        case CRITERIA_AGE_GREATER:
                return MATCHING_AGE_GREATER;
        case CRITERIA_AGE_LOWER:
                return MATCHING_AGE_LOWER;
+       case CRITERIA_SCORE_GREATER:
+               return MATCHING_SCORE_GREATER;
+       case CRITERIA_SCORE_LOWER:
+               return MATCHING_SCORE_LOWER;
        case CRITERIA_HEADER:
                return MATCHING_HEADER;
        case CRITERIA_HEADERS_PART:
@@ -785,6 +827,8 @@ static gint prefs_matcher_get_scoring_from_criteria(gint criteria_id)
                return MATCHING_BODY_PART;
        case CRITERIA_MESSAGE:
                return MATCHING_MESSAGE;
+       case CRITERIA_EXECUTE:
+               return MATCHING_EXECUTE;
        default:
                return -1;
        }
@@ -793,6 +837,18 @@ static gint prefs_matcher_get_scoring_from_criteria(gint criteria_id)
 static gint prefs_matcher_not_criteria(gint matcher_criteria)
 {
        switch(matcher_criteria) {
+       case MATCHING_UNREAD:
+               return MATCHING_NOT_UNREAD;
+       case MATCHING_NEW:
+               return MATCHING_NOT_NEW;
+       case MATCHING_MARKED:
+               return MATCHING_NOT_MARKED;
+       case MATCHING_DELETED:
+               return MATCHING_NOT_DELETED;
+       case MATCHING_REPLIED:
+               return MATCHING_NOT_REPLIED;
+       case MATCHING_FORWARDED:
+               return MATCHING_NOT_FORWARDED;
        case MATCHING_SUBJECT:
                return MATCHING_NOT_SUBJECT;
        case MATCHING_FROM:
@@ -805,12 +861,18 @@ static gint prefs_matcher_not_criteria(gint matcher_criteria)
                return MATCHING_NOT_TO_AND_NOT_CC;
        case MATCHING_NEWSGROUPS:
                return MATCHING_NOT_NEWSGROUPS;
+       case MATCHING_INREPLYTO:
+               return MATCHING_NOT_INREPLYTO;
+       case MATCHING_REFERENCES:
+               return MATCHING_NOT_REFERENCES;
        case MATCHING_HEADER:
                return MATCHING_NOT_HEADER;
        case MATCHING_HEADERS_PART:
                return MATCHING_NOT_HEADERS_PART;
        case MATCHING_MESSAGE:
                return MATCHING_NOT_MESSAGE;
+       case MATCHING_EXECUTE:
+               return MATCHING_NOT_EXECUTE;
        case MATCHING_BODY_PART:
                return MATCHING_NOT_BODY_PART;
        default:
@@ -818,29 +880,60 @@ static gint prefs_matcher_not_criteria(gint matcher_criteria)
        }
 }
 
-static MatcherProp * prefs_match_dialog_to_matcher()
+static MatcherProp * prefs_matcher_dialog_to_matcher()
 {
        MatcherProp * matcherprop;
        gint criteria;
        gint matchtype;
        gint value_pred;
+       gint value_pred_flag;
        gint value_criteria;
        gboolean use_regexp;
        gboolean case_sensitive;
        gchar * header;
        gchar * expr;
-       gint age;
+       gint value;
+       gchar * value_str;
 
-       value_criteria = criteria_get_from_string(gtk_entry_get_text(GTK_ENTRY(matcher.criteria_entry)));
-       criteria = prefs_matcher_get_scoring_from_criteria(value_criteria);
+       value_criteria = get_sel_from_list(GTK_LIST(matcher.criteria_list));
 
-       value_pred =  predicate_get_from_string(gtk_entry_get_text(GTK_ENTRY(matcher.predicate_entry)));
+       criteria = prefs_matcher_get_matching_from_criteria(value_criteria);
+
+       value_pred = get_sel_from_list(GTK_LIST(matcher.predicate_list));
+       value_pred_flag = get_sel_from_list(GTK_LIST(matcher.predicate_flag_list));
 
        use_regexp = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(matcher.regexp_chkbtn));
        case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(matcher.case_chkbtn));
 
-       if (value_pred != PREDICATE_CONTAINS)
-               criteria = prefs_matcher_not_criteria(criteria);
+       switch (value_criteria) {
+       case CRITERIA_UNREAD:
+       case CRITERIA_NEW:
+       case CRITERIA_MARKED:
+       case CRITERIA_DELETED:
+       case CRITERIA_REPLIED:
+       case CRITERIA_FORWARDED:
+               if (value_pred_flag == PREDICATE_FLAG_DISABLED)
+                       criteria = prefs_matcher_not_criteria(criteria);
+               break;
+       case CRITERIA_SUBJECT:
+       case CRITERIA_FROM:
+       case CRITERIA_TO:
+       case CRITERIA_CC:
+       case CRITERIA_TO_OR_CC:
+       case CRITERIA_NEWSGROUPS:
+       case CRITERIA_INREPLYTO:
+       case CRITERIA_REFERENCES:
+       case CRITERIA_HEADERS_PART:
+       case CRITERIA_BODY_PART:
+       case CRITERIA_MESSAGE:
+       case CRITERIA_EXECUTE:
+       case CRITERIA_AGE_GREATER:
+       case CRITERIA_AGE_LOWER:
+       case CRITERIA_HEADER:
+               if (value_pred == PREDICATE_DOES_NOT_CONTAIN)
+                       criteria = prefs_matcher_not_criteria(criteria);
+               break;
+       }
 
        if (use_regexp) {
                if (case_sensitive)
@@ -857,10 +950,16 @@ static MatcherProp * prefs_match_dialog_to_matcher()
 
        header = NULL;
        expr = NULL;
-       age = 0;
+       value = 0;
 
        switch (value_criteria) {
        case CRITERIA_ALL:
+       case CRITERIA_UNREAD:
+       case CRITERIA_NEW:
+       case CRITERIA_MARKED:
+       case CRITERIA_DELETED:
+       case CRITERIA_REPLIED:
+       case CRITERIA_FORWARDED:
                break;
 
        case CRITERIA_SUBJECT:
@@ -869,190 +968,305 @@ static MatcherProp * prefs_match_dialog_to_matcher()
        case CRITERIA_CC:
        case CRITERIA_TO_OR_CC:
        case CRITERIA_NEWSGROUPS:
+       case CRITERIA_INREPLYTO:
+       case CRITERIA_REFERENCES:
        case CRITERIA_HEADERS_PART:
        case CRITERIA_BODY_PART:
        case CRITERIA_MESSAGE:
+       case CRITERIA_EXECUTE:
                expr = gtk_entry_get_text(GTK_ENTRY(matcher.value_entry));
+
+               /*
+               if (*expr == '\0') {
+                   alertpanel_error(_("Match string is not set."));
+                   return NULL;
+               }
+               */
                break;
 
        case CRITERIA_AGE_GREATER:
        case CRITERIA_AGE_LOWER:
-               age = atoi(gtk_entry_get_text(GTK_ENTRY(matcher.value_entry)));
+       case CRITERIA_SCORE_GREATER:
+       case CRITERIA_SCORE_LOWER:
+               value_str = gtk_entry_get_text(GTK_ENTRY(matcher.value_entry));
+
+               if (*value_str == '\0') {
+                   alertpanel_error(_("Value is not set."));
+                   return NULL;
+               }
+
+               value = atoi(value_str);
+
                break;
 
        case CRITERIA_HEADER:
+
                header = gtk_entry_get_text(GTK_ENTRY(matcher.header_entry));
                expr = gtk_entry_get_text(GTK_ENTRY(matcher.value_entry));
+
+               if (*header == '\0') {
+                   alertpanel_error(_("Header name is not set."));
+                   return NULL;
+               }
+               /*
+               if (*expr == '\0') {
+                   alertpanel_error(_("Match string is not set."));
+                   return NULL;
+               }
+               */
                break;
        }
 
-       matcherprop =  matcherprop_new(criteria, header, matchtype, expr, age);
-       
+       matcherprop =  matcherprop_new(criteria, header, matchtype,
+                                      expr, value);
+
        return matcherprop;
 }
 
 static void prefs_matcher_register_cb(void)
 {
-       gchar * matcher_str;
        MatcherProp * matcherprop;
-       GtkCList *clist = GTK_CLIST(matcher.cond_clist);
-       gchar * cond_str[1];
-       gint row;
        
-       matcherprop = prefs_match_dialog_to_matcher();
-       matcher_str = matcherprop_to_string(matcherprop);
+       matcherprop = prefs_matcher_dialog_to_matcher();
+       if (matcherprop == NULL)
+               return;
+
+       prefs_matcher_clist_set_row(-1, matcherprop);
+
        matcherprop_free(matcherprop);
 
-       cond_str[0] = matcher_str;
-       row = gtk_clist_append(clist, cond_str);
-       g_free(matcher_str);
+       prefs_matcher_reset_condition();
+       prefs_matcher_update_hscrollbar();
 }
 
 static void prefs_matcher_substitute_cb(void)
 {
-       /*
-       GtkCList *clist = GTK_CLIST(filter.cond_clist);
-       Filter *flt;
+       GtkCList *clist = GTK_CLIST(matcher.cond_clist);
        gint row;
-
-       if (!clist->selection) return;
+       MatcherProp * matcherprop;
 
        row = GPOINTER_TO_INT(clist->selection->data);
-       if (row == 0) return;
+       if (row == 0)
+               return;
+       
+       matcherprop = prefs_matcher_dialog_to_matcher();
+       if (matcherprop == NULL)
+               return;
 
-       flt = gtk_clist_get_row_data(clist, row);
-       if (!flt) return;
+       prefs_matcher_clist_set_row(row, matcherprop);
+
+       matcherprop_free(matcherprop);
 
-       prefs_filter_clist_set_row(row);
-       */
+       prefs_matcher_reset_condition();
+       
+       prefs_matcher_update_hscrollbar();
 }
 
 static void prefs_matcher_delete_cb(void)
 {
-       /*
-       GtkCList *clist = GTK_CLIST(filter.cond_clist);
-       Filter *flt;
+       GtkCList *clist = GTK_CLIST(matcher.cond_clist);
        gint row;
 
        if (!clist->selection) return;
        row = GPOINTER_TO_INT(clist->selection->data);
-       if (row == 0) return;
-
-       if (alertpanel(_("Delete rule"),
-                      _("Do you really want to delete this rule?"),
-                      _("Yes"), _("No"), NULL) == G_ALERTALTERNATE)
+       if (row == 0)
                return;
 
-       flt = gtk_clist_get_row_data(clist, row);
-       filter_free(flt);
        gtk_clist_remove(clist, row);
-       prefs_common.fltlist = g_slist_remove(prefs_common.fltlist, flt);
-       */
+       
+       prefs_matcher_update_hscrollbar();
 }
 
 static void prefs_matcher_up(void)
 {
-       /*
-       GtkCList *clist = GTK_CLIST(filter.cond_clist);
+       GtkCList *clist = GTK_CLIST(matcher.cond_clist);
        gint row;
 
        if (!clist->selection) return;
 
        row = GPOINTER_TO_INT(clist->selection->data);
-       if (row > 1) {
+       if (row > 1)
                gtk_clist_row_move(clist, row, row - 1);
-               prefs_filter_set_list();
-       }
-       */
 }
 
 static void prefs_matcher_down(void)
 {
-       /*
-       GtkCList *clist = GTK_CLIST(filter.cond_clist);
+       GtkCList *clist = GTK_CLIST(matcher.cond_clist);
        gint row;
 
        if (!clist->selection) return;
 
        row = GPOINTER_TO_INT(clist->selection->data);
-       if (row > 0 && row < clist->rows - 1) {
+       if (row >= 1 && row < clist->rows - 1)
                gtk_clist_row_move(clist, row, row + 1);
-               prefs_filter_set_list();
-       }
-       */
 }
 
-/*
-#define ENTRY_SET_TEXT(entry, str) \
-       gtk_entry_set_text(GTK_ENTRY(entry), str ? str : "")
-
-static void prefs_filter_select(GtkCList *clist, gint row, gint column,
-                               GdkEvent *event)
+static void prefs_matcher_select(GtkCList *clist, gint row, gint column,
+                                GdkEvent *event)
 {
-       Filter *flt;
-       Filter default_flt = {"Subject", NULL, _("(none)"), NULL,
-                             FLT_CONTAIN, FLT_CONTAIN, FLT_AND,
-                             NULL, FLT_MOVE};
-
-       flt = gtk_clist_get_row_data(clist, row);
-       if (!flt)
-               flt = &default_flt;
-
-       ENTRY_SET_TEXT(filter.dest_entry, flt->dest);
-       ENTRY_SET_TEXT(filter.hdr_entry1, flt->name1);
-       ENTRY_SET_TEXT(filter.key_entry1, flt->body1);
-       ENTRY_SET_TEXT(filter.hdr_entry2,
-                      flt->name2 ? flt->name2 : _("(none)"));
-       ENTRY_SET_TEXT(filter.key_entry2, flt->body2);
-
-       ENTRY_SET_TEXT(filter.pred_entry1,
-                      FLT_IS_CONTAIN(flt->flag1)
-                      ? _("contains") : _("not contain"));
-       ENTRY_SET_TEXT(filter.pred_entry2,
-                      FLT_IS_CONTAIN(flt->flag2)
-                      ? _("contains") : _("not contain"));
-
-       gtk_entry_set_text(GTK_ENTRY(filter.op_entry),
-                          flt->cond == FLT_OR ? "or" : "and");
-       if (flt->action == FLT_NOTRECV)
-               gtk_toggle_button_set_active
-                       (GTK_TOGGLE_BUTTON(filter.notrecv_radiobtn), TRUE);
+       gchar * matcher_str;
+       gchar * tmp;
+       MatcherProp * prop;
+       gboolean negative_cond;
+       gint criteria;
+
+       if (!gtk_clist_get_text(GTK_CLIST(matcher.cond_clist),
+                               row, 0, &matcher_str))
+               return;
+
+       negative_cond = FALSE;
+
+       if (row == 0) {
+               prefs_matcher_reset_condition();
+               return;
+       }
+
+       tmp = matcher_str;
+       prop = matcherprop_parse(&tmp);
+       if (tmp == NULL)
+               return;
+
+       criteria = prefs_matcher_get_criteria_from_matching(prop->criteria);
+       if (criteria != -1)
+               gtk_list_select_item(GTK_LIST(matcher.criteria_list),
+                                    criteria);
+
+       switch(prop->criteria) {
+       case MATCHING_NOT_UNREAD:
+       case MATCHING_NOT_NEW:
+       case MATCHING_NOT_MARKED:
+       case MATCHING_NOT_DELETED:
+       case MATCHING_NOT_REPLIED:
+       case MATCHING_NOT_FORWARDED:
+       case MATCHING_NOT_SUBJECT:
+       case MATCHING_NOT_FROM:
+       case MATCHING_NOT_TO:
+       case MATCHING_NOT_CC:
+       case MATCHING_NOT_NEWSGROUPS:
+       case MATCHING_NOT_INREPLYTO:
+       case MATCHING_NOT_REFERENCES:
+       case MATCHING_NOT_TO_AND_NOT_CC:
+       case MATCHING_NOT_BODY_PART:
+       case MATCHING_NOT_MESSAGE:
+       case MATCHING_NOT_HEADERS_PART:
+       case MATCHING_NOT_HEADER:
+               negative_cond = TRUE;
+               break;
+       }
+       
+       switch(prop->criteria) {
+       case MATCHING_ALL:
+               break;
+
+       case MATCHING_NOT_SUBJECT:
+       case MATCHING_NOT_FROM:
+       case MATCHING_NOT_TO:
+       case MATCHING_NOT_CC:
+       case MATCHING_NOT_TO_AND_NOT_CC:
+       case MATCHING_NOT_NEWSGROUPS:
+       case MATCHING_NOT_INREPLYTO:
+       case MATCHING_NOT_REFERENCES:
+       case MATCHING_NOT_HEADERS_PART:
+       case MATCHING_NOT_BODY_PART:
+       case MATCHING_NOT_MESSAGE:
+       case MATCHING_SUBJECT:
+       case MATCHING_FROM:
+       case MATCHING_TO:
+       case MATCHING_CC:
+       case MATCHING_TO_OR_CC:
+       case MATCHING_NEWSGROUPS:
+       case MATCHING_INREPLYTO:
+       case MATCHING_REFERENCES:
+       case MATCHING_HEADERS_PART:
+       case MATCHING_BODY_PART:
+       case MATCHING_MESSAGE:
+               gtk_entry_set_text(GTK_ENTRY(matcher.value_entry), prop->expr);
+               break;
+
+       case MATCHING_AGE_GREATER:
+       case MATCHING_AGE_LOWER:
+       case MATCHING_SCORE_GREATER:
+       case MATCHING_SCORE_LOWER:
+               gtk_entry_set_text(GTK_ENTRY(matcher.value_entry), itos(prop->value));
+               break;
+
+       case MATCHING_NOT_HEADER:
+       case MATCHING_HEADER:
+               gtk_entry_set_text(GTK_ENTRY(matcher.header_entry), prop->header);
+               gtk_entry_set_text(GTK_ENTRY(matcher.value_entry), prop->expr);
+               break;
+       }
+
+       if (negative_cond)
+               gtk_list_select_item(GTK_LIST(matcher.predicate_list), 1);
        else
-               gtk_toggle_button_set_active
-                       (GTK_TOGGLE_BUTTON(filter.dest_radiobtn), TRUE);
-}
+               gtk_list_select_item(GTK_LIST(matcher.predicate_list), 0);
 
-static void prefs_filter_dest_radio_button_toggled(void)
-{
-       gtk_widget_set_sensitive(filter.dest_entry, TRUE);
-       gtk_widget_set_sensitive(filter.destsel_btn, TRUE);
-}
+       switch(prop->matchtype) {
+       case MATCHING_MATCH:
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_chkbtn), FALSE);
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_chkbtn), TRUE);
+               break;
 
-static void prefs_filter_notrecv_radio_button_toggled(void)
-{
-       gtk_widget_set_sensitive(filter.dest_entry, FALSE);
-       gtk_widget_set_sensitive(filter.destsel_btn, FALSE);
-}
-*/
+       case MATCHING_MATCHCASE:
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_chkbtn), FALSE);
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_chkbtn), FALSE);
+               break;
+
+       case MATCHING_REGEXP:
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_chkbtn), TRUE);
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_chkbtn), TRUE);
+               break;
 
+       case MATCHING_REGEXPCASE:
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.regexp_chkbtn), TRUE);
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(matcher.case_chkbtn), FALSE);
+               break;
+       }
+}
 
-static void prefs_matcher_criteria_select(GtkEditable *editable,
+static void prefs_matcher_criteria_select(GtkList *list,
+                                         GtkWidget *widget,
                                          gpointer user_data)
 {
        gint value;
 
-       value = criteria_get_from_string(gtk_entry_get_text(GTK_ENTRY(matcher.criteria_entry)));
+       value = get_sel_from_list(GTK_LIST(matcher.criteria_list));
 
        switch (value) {
        case CRITERIA_ALL:
-               gtk_widget_set_sensitive(matcher.header_entry, FALSE);
+               gtk_widget_set_sensitive(matcher.header_combo, FALSE);
                gtk_widget_set_sensitive(matcher.header_label, FALSE);
                gtk_widget_set_sensitive(matcher.value_label, FALSE);
                gtk_widget_set_sensitive(matcher.value_entry, FALSE);
                gtk_widget_set_sensitive(matcher.predicate_label, FALSE);
-               gtk_widget_set_sensitive(matcher.predicate_entry, FALSE);
+               gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
+               gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
+               gtk_widget_hide(matcher.predicate_combo);
+               gtk_widget_show(matcher.predicate_flag_combo);
                gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
                gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
+               gtk_widget_set_sensitive(matcher.exec_btn, FALSE);
+               break;
+
+       case CRITERIA_UNREAD:
+       case CRITERIA_NEW:
+       case CRITERIA_MARKED:
+       case CRITERIA_DELETED:
+       case CRITERIA_REPLIED:
+       case CRITERIA_FORWARDED:
+               gtk_widget_set_sensitive(matcher.header_combo, FALSE);
+               gtk_widget_set_sensitive(matcher.header_label, FALSE);
+               gtk_widget_set_sensitive(matcher.value_label, FALSE);
+               gtk_widget_set_sensitive(matcher.value_entry, FALSE);
+               gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
+               gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
+               gtk_widget_set_sensitive(matcher.predicate_flag_combo, TRUE);
+               gtk_widget_hide(matcher.predicate_combo);
+               gtk_widget_show(matcher.predicate_flag_combo);
+               gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
+               gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
+               gtk_widget_set_sensitive(matcher.exec_btn, FALSE);
                break;
 
        case CRITERIA_SUBJECT:
@@ -1061,40 +1275,71 @@ static void prefs_matcher_criteria_select(GtkEditable *editable,
        case CRITERIA_CC:
        case CRITERIA_TO_OR_CC:
        case CRITERIA_NEWSGROUPS:
+       case CRITERIA_INREPLYTO:
+       case CRITERIA_REFERENCES:
        case CRITERIA_HEADERS_PART:
        case CRITERIA_BODY_PART:
        case CRITERIA_MESSAGE:
-               gtk_widget_set_sensitive(matcher.header_entry, FALSE);
+               gtk_widget_set_sensitive(matcher.header_combo, FALSE);
                gtk_widget_set_sensitive(matcher.header_label, FALSE);
                gtk_widget_set_sensitive(matcher.value_label, TRUE);
                gtk_widget_set_sensitive(matcher.value_entry, TRUE);
                gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
-               gtk_widget_set_sensitive(matcher.predicate_entry, TRUE);
+               gtk_widget_set_sensitive(matcher.predicate_combo, TRUE);
+               gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
+               gtk_widget_show(matcher.predicate_combo);
+               gtk_widget_hide(matcher.predicate_flag_combo);
                gtk_widget_set_sensitive(matcher.case_chkbtn, TRUE);
                gtk_widget_set_sensitive(matcher.regexp_chkbtn, TRUE);
+               gtk_widget_set_sensitive(matcher.exec_btn, FALSE);
+               break;
+
+       case CRITERIA_EXECUTE:
+               gtk_widget_set_sensitive(matcher.header_combo, FALSE);
+               gtk_widget_set_sensitive(matcher.header_label, FALSE);
+               gtk_widget_set_sensitive(matcher.value_label, TRUE);
+               gtk_widget_set_sensitive(matcher.value_entry, TRUE);
+               gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
+               gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
+               gtk_widget_set_sensitive(matcher.predicate_flag_combo, TRUE);
+               gtk_widget_hide(matcher.predicate_combo);
+               gtk_widget_show(matcher.predicate_flag_combo);
+               gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
+               gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
+               gtk_widget_set_sensitive(matcher.exec_btn, TRUE);
                break;
 
        case CRITERIA_AGE_GREATER:
        case CRITERIA_AGE_LOWER:
-               gtk_widget_set_sensitive(matcher.header_entry, FALSE);
+       case CRITERIA_SCORE_GREATER:
+       case CRITERIA_SCORE_LOWER:
+               gtk_widget_set_sensitive(matcher.header_combo, FALSE);
                gtk_widget_set_sensitive(matcher.header_label, FALSE);
                gtk_widget_set_sensitive(matcher.value_label, TRUE);
                gtk_widget_set_sensitive(matcher.value_entry, TRUE);
                gtk_widget_set_sensitive(matcher.predicate_label, FALSE);
-               gtk_widget_set_sensitive(matcher.predicate_entry, FALSE);
+               gtk_widget_set_sensitive(matcher.predicate_combo, FALSE);
+               gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
+               gtk_widget_show(matcher.predicate_combo);
+               gtk_widget_hide(matcher.predicate_flag_combo);
                gtk_widget_set_sensitive(matcher.case_chkbtn, FALSE);
                gtk_widget_set_sensitive(matcher.regexp_chkbtn, FALSE);
+               gtk_widget_set_sensitive(matcher.exec_btn, FALSE);
                break;
 
        case CRITERIA_HEADER:
-               gtk_widget_set_sensitive(matcher.header_entry, TRUE);
+               gtk_widget_set_sensitive(matcher.header_combo, TRUE);
                gtk_widget_set_sensitive(matcher.header_label, TRUE);
                gtk_widget_set_sensitive(matcher.value_label, TRUE);
                gtk_widget_set_sensitive(matcher.value_entry, TRUE);
                gtk_widget_set_sensitive(matcher.predicate_label, TRUE);
-               gtk_widget_set_sensitive(matcher.predicate_entry, TRUE);
+               gtk_widget_set_sensitive(matcher.predicate_combo, TRUE);
+               gtk_widget_set_sensitive(matcher.predicate_flag_combo, FALSE);
+               gtk_widget_show(matcher.predicate_combo);
+               gtk_widget_hide(matcher.predicate_flag_combo);
                gtk_widget_set_sensitive(matcher.case_chkbtn, TRUE);
                gtk_widget_set_sensitive(matcher.regexp_chkbtn, TRUE);
+               gtk_widget_set_sensitive(matcher.exec_btn, FALSE);
                break;
        }
 }
@@ -1103,21 +1348,119 @@ static void prefs_matcher_key_pressed(GtkWidget *widget, GdkEventKey *event,
                                     gpointer data)
 {
        if (event && event->keyval == GDK_Escape)
-               prefs_matcher_close();
+               prefs_matcher_cancel();
 }
 
-static void prefs_matcher_close(void)
+static void prefs_matcher_cancel(void)
 {
-       /*      prefs_filter_write_config(); */
        gtk_widget_hide(matcher.window);
-       /*
-       inc_autocheck_timer_set();      
-       */
+}
+
+static void prefs_matcher_ok(void)
+{
+       MatcherList * matchers;
+
+       matchers = prefs_matcher_get_list();
+       if (matchers != NULL) {
+               gtk_widget_hide(matcher.window);
+               if (matchers_callback != NULL)
+                       matchers_callback(matchers);
+               matcherlist_free(matchers);
+       }
+       else {
+               gtk_widget_hide(matcher.window);
+       }
 }
 
 static gint prefs_matcher_deleted(GtkWidget *widget, GdkEventAny *event,
                                  gpointer data)
 {
-       prefs_matcher_close();
+       prefs_matcher_cancel();
        return TRUE;
 }
+
+static GtkWidget * exec_info_win;
+
+void prefs_matcher_exec_info(void)
+{
+       if (!exec_info_win)
+               prefs_matcher_exec_info_create();
+
+       gtk_widget_show(exec_info_win);
+       gtk_main();
+       gtk_widget_hide(exec_info_win);
+}
+
+static void prefs_matcher_exec_info_create(void)
+{
+       GtkWidget *vbox;
+       GtkWidget *hbox;
+       GtkWidget *hbbox;
+       GtkWidget *label;
+       GtkWidget *ok_btn;
+
+       exec_info_win = gtk_window_new(GTK_WINDOW_DIALOG);
+       gtk_window_set_title(GTK_WINDOW(exec_info_win),
+                            _("Description of symbols"));
+       gtk_container_set_border_width(GTK_CONTAINER(exec_info_win), 8);
+       gtk_window_set_position(GTK_WINDOW(exec_info_win), GTK_WIN_POS_CENTER);
+       gtk_window_set_modal(GTK_WINDOW(exec_info_win), TRUE);
+       gtk_window_set_policy(GTK_WINDOW(exec_info_win), FALSE, TRUE, FALSE);
+
+       vbox = gtk_vbox_new(FALSE, 8);
+       gtk_container_add(GTK_CONTAINER(exec_info_win), vbox);
+
+       hbox = gtk_hbox_new(FALSE, 4);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
+
+       label = gtk_label_new
+               ("%%:\n"
+                "%s:\n"
+                "%f:\n"
+                "%t:\n"
+                "%c:\n"
+                "%d:\n"
+                "%i:\n"
+                "%n:\n"
+                "%r:\n"
+                "%F:\n"
+                "\\n:\n"
+                "\\:\n"
+                "\\\":\n"
+                "%%:");
+
+       gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
+       gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
+
+       label = gtk_label_new
+               (_("%\n"
+                  "Subject\n"
+                  "From\n"
+                  "To\n"
+                  "Cc\n"
+                  "Date\n"
+                  "Message-ID\n"
+                  "Newsgroups\n"
+                  "References\n"
+                  "Filename - should not be modified\n"
+                  "new line\n"
+                  "escape character for quotes\n"
+                  "quote character\n"
+                  "%"));
+
+       gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
+       gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
+
+       gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
+                               NULL, NULL, NULL, NULL);
+       gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
+
+       gtk_widget_grab_default(ok_btn);
+       gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
+                                 GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
+
+       gtk_signal_connect(GTK_OBJECT(exec_info_win), "delete_event",
+                                         GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
+
+       gtk_widget_show_all(vbox);
+}