+2003-10-12 [hoa] 0.9.6claws17
+
+ * src/filtering.c
+ * src/filtering.h
+ * src/matcher.c
+ * src/matcher.h
+ * src/matcher_parser_parse.y
+ * src/prefs_filtering_action.c
+ added "stop" action : stop applying the filtering rules.
+ added "set score" and "increase/decrease score" actions.
+ That two last action replace the "change_score" action
+ introduced by alfons in 0.8.8claws85.
+ "set score" is to set a given score to the message.
+ "increase/decrease score" will increase or decrease the
+ score if the given value is respectively positive or
+ negative. If someone find a some better name for this last
+ rule, it can be modified.
+
2003-10-12 [paul] 0.9.6claws16
* AUTHORS
MICRO_VERSION=6
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=16
+EXTRA_VERSION=17
if test $EXTRA_VERSION -eq 0; then
VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
else
FilteringAction * filteringaction_new(int type, int account_id,
gchar * destination,
- gint labelcolor)
+ gint labelcolor, gint score)
{
FilteringAction * action;
action = g_new0(FilteringAction, 1);
- /* NOTE:
- * if type is MATCHACTION_CHANGE_SCORE, account_id = (-1, 0, 1) and
- * labelcolor = the score value change
- */
-
action->type = type;
action->account_id = account_id;
if (destination) {
action->unesc_destination = NULL;
}
action->labelcolor = labelcolor;
+ action->score = score;
return action;
}
}
return TRUE;
- case MATCHACTION_CHANGE_SCORE:
- /* NOTE:
- * action->account_id is 0 if just assignment, -1 if decrement
- * and 1 if increment by action->labelcolor
- * action->labelcolor has the score value change
- */
- info->score = action->account_id == 1 ? info->score + action->labelcolor
- : action->account_id == -1 ? info->score - action->labelcolor
- : action->labelcolor;
+ case MATCHACTION_SET_SCORE:
+ info->score = action->score;
+ return TRUE;
+
+ case MATCHACTION_ADD_SCORE:
+ info->score += action->score;
return TRUE;
+ case MATCHACTION_STOP:
+ break;
+
default:
break;
}
switch(filtering_action->type) {
case MATCHACTION_MOVE:
case MATCHACTION_DELETE:
+ case MATCHACTION_STOP:
return TRUE; /* MsgInfo invalid for message */
- case MATCHACTION_EXECUTE:
- case MATCHACTION_COPY:
- case MATCHACTION_MARK:
- case MATCHACTION_UNMARK:
- case MATCHACTION_LOCK:
- case MATCHACTION_UNLOCK:
- case MATCHACTION_MARK_AS_READ:
- case MATCHACTION_MARK_AS_UNREAD:
- case MATCHACTION_FORWARD:
- case MATCHACTION_FORWARD_AS_ATTACHMENT:
- case MATCHACTION_REDIRECT:
- return FALSE; /* MsgInfo still valid for message */
default:
return FALSE;
}
case MATCHACTION_UNLOCK:
case MATCHACTION_MARK_AS_READ:
case MATCHACTION_MARK_AS_UNREAD:
+ case MATCHACTION_STOP:
g_snprintf(dest, destlen, "%s", command_str);
return dest;
case MATCHACTION_COLOR:
g_snprintf(dest, destlen, "%s %d", command_str, action->labelcolor);
return dest;
+
+ case MATCHACTION_ADD_SCORE:
+ case MATCHACTION_SET_SCORE:
+ g_snprintf(dest, destlen, "%s %d", command_str, action->score);
+ return dest;
+
default:
return NULL;
}
gchar *destination;
gchar *unesc_destination; /* for exec cmd line */
gint labelcolor;
+ gint score;
};
typedef struct _FilteringAction FilteringAction;
FilteringAction * filteringaction_new(int type, int account_id,
- gchar *destination,
- gint labelcolor);
+ gchar * destination,
+ gint labelcolor, gint score);
void filteringaction_free(FilteringAction *action);
FilteringAction * filteringaction_parse(gchar **str);
gboolean filteringaction_apply_action_list (GSList *action_list, MsgInfo *info);
{MATCHACTION_EXECUTE, "execute"},
{MATCHACTION_COLOR, "color"},
{MATCHACTION_REDIRECT, "redirect"},
- {MATCHACTION_CHANGE_SCORE, "change_score"}
+ {MATCHACTION_ADD_SCORE, "add_score"},
+ {MATCHACTION_SET_SCORE, "set_score"},
+ {MATCHACTION_STOP, "stop"},
};
/*!
MA_(FORWARD_AS_ATTACHMENT),
MA_(COLOR),
MA_(REDIRECT),
- MA_(CHANGE_SCORE),
+ MA_(ADD_SCORE),
+ MA_(SET_SCORE),
+ MA_(STOP),
/* boolean operations */
MB_(OR),
MB_(AND)
%token MATCHER_LOCKED MATCHER_NOT_LOCKED
%token MATCHER_COLORLABEL MATCHER_NOT_COLORLABEL
%token MATCHER_IGNORE_THREAD MATCHER_NOT_IGNORE_THREAD
-%token MATCHER_CHANGE_SCORE
+%token MATCHER_ADD_SCORE MATCHER_SET_SCORE
+%token MATCHER_STOP
%start file
gint value = 0;
criteria = MATCHCRITERIA_COLORLABEL;
- value = atoi($2);
+ value = strtol($2, NULL, 10);
if (value < 1) value = 1;
else if (value > MAX_COLORLABELS) value = MAX_COLORLABELS;
prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value);
gint value = 0;
criteria = MATCHCRITERIA_NOT_COLORLABEL;
- value = atoi($2);
+ value = strtol($2, NULL, 0);
if (value < 1) value = 1;
else if (value > MAX_COLORLABELS) value = MAX_COLORLABELS;
prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value);
gint value = 0;
criteria = MATCHCRITERIA_AGE_GREATER;
- value = atoi($2);
+ value = strtol($2, NULL, 0);
prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value);
}
| MATCHER_AGE_LOWER MATCHER_INTEGER
gint value = 0;
criteria = MATCHCRITERIA_AGE_LOWER;
- value = atoi($2);
+ value = strtol($2, NULL, 0);
prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value);
}
| MATCHER_NEWSGROUPS match_type MATCHER_STRING
gint value = 0;
criteria = MATCHCRITERIA_SCORE_GREATER;
- value = atoi($2);
+ value = strtol($2, NULL, 0);
prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value);
}
| MATCHER_SCORE_LOWER MATCHER_INTEGER
gint value = 0;
criteria = MATCHCRITERIA_SCORE_LOWER;
- value = atoi($2);
+ value = strtol($2, NULL, 0);
prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value);
}
| MATCHER_SCORE_EQUAL MATCHER_INTEGER
gint value = 0;
criteria = MATCHCRITERIA_SCORE_EQUAL;
- value = atoi($2);
+ value = strtol($2, NULL, 0);
prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value);
}
| MATCHER_SIZE_GREATER MATCHER_INTEGER
gint criteria = 0;
gint value = 0;
criteria = MATCHCRITERIA_SIZE_GREATER;
- value = atoi($2);
+ value = strtol($2, NULL, 0);
prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value);
}
| MATCHER_SIZE_SMALLER MATCHER_INTEGER
gint criteria = 0;
gint value = 0;
criteria = MATCHCRITERIA_SIZE_SMALLER;
- value = atoi($2);
+ value = strtol($2, NULL, 0);
prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value);
}
| MATCHER_SIZE_EQUAL MATCHER_INTEGER
gint criteria = 0;
gint value = 0;
criteria = MATCHCRITERIA_SIZE_EQUAL;
- value = atoi($2);
+ value = strtol($2, NULL, 0);
prop = matcherprop_unquote_new(criteria, NULL, 0, NULL, value);
}
| MATCHER_HEADER MATCHER_STRING
action_type = MATCHACTION_EXECUTE;
cmd = $2;
- action = filteringaction_new(action_type, 0, cmd, 0);
+ action = filteringaction_new(action_type, 0, cmd, 0, 0);
}
| MATCHER_MOVE MATCHER_STRING
{
action_type = MATCHACTION_MOVE;
destination = $2;
- action = filteringaction_new(action_type, 0, destination, 0);
+ action = filteringaction_new(action_type, 0, destination, 0, 0);
}
| MATCHER_COPY MATCHER_STRING
{
action_type = MATCHACTION_COPY;
destination = $2;
- action = filteringaction_new(action_type, 0, destination, 0);
+ action = filteringaction_new(action_type, 0, destination, 0, 0);
}
| MATCHER_DELETE
{
gint action_type = 0;
action_type = MATCHACTION_DELETE;
- action = filteringaction_new(action_type, 0, NULL, 0);
+ action = filteringaction_new(action_type, 0, NULL, 0, 0);
}
| MATCHER_MARK
{
gint action_type = 0;
action_type = MATCHACTION_MARK;
- action = filteringaction_new(action_type, 0, NULL, 0);
+ action = filteringaction_new(action_type, 0, NULL, 0, 0);
}
| MATCHER_UNMARK
{
gint action_type = 0;
action_type = MATCHACTION_UNMARK;
- action = filteringaction_new(action_type, 0, NULL, 0);
+ action = filteringaction_new(action_type, 0, NULL, 0, 0);
}
| MATCHER_LOCK
{
gint action_type = 0;
action_type = MATCHACTION_LOCK;
- action = filteringaction_new(action_type, 0, NULL, 0);
+ action = filteringaction_new(action_type, 0, NULL, 0, 0);
}
| MATCHER_UNLOCK
{
gint action_type = 0;
action_type = MATCHACTION_UNLOCK;
- action = filteringaction_new(action_type, 0, NULL, 0);
+ action = filteringaction_new(action_type, 0, NULL, 0, 0);
}
| MATCHER_MARK_AS_READ
{
gint action_type = 0;
action_type = MATCHACTION_MARK_AS_READ;
- action = filteringaction_new(action_type, 0, NULL, 0);
+ action = filteringaction_new(action_type, 0, NULL, 0, 0);
}
| MATCHER_MARK_AS_UNREAD
{
gint action_type = 0;
action_type = MATCHACTION_MARK_AS_UNREAD;
- action = filteringaction_new(action_type, 0, NULL, 0);
+ action = filteringaction_new(action_type, 0, NULL, 0, 0);
}
| MATCHER_FORWARD MATCHER_INTEGER MATCHER_STRING
{
gint account_id = 0;
action_type = MATCHACTION_FORWARD;
- account_id = atoi($2);
+ account_id = strtol($2, NULL, 10);
destination = $3;
- action = filteringaction_new(action_type, account_id, destination, 0);
+ action = filteringaction_new(action_type,
+ account_id, destination, 0, 0);
}
| MATCHER_FORWARD_AS_ATTACHMENT MATCHER_INTEGER MATCHER_STRING
{
gint account_id = 0;
action_type = MATCHACTION_FORWARD_AS_ATTACHMENT;
- account_id = atoi($2);
+ account_id = strtol($2, NULL, 10);
destination = $3;
- action = filteringaction_new(action_type, account_id, destination, 0);
+ action = filteringaction_new(action_type,
+ account_id, destination, 0, 0);
}
| MATCHER_REDIRECT MATCHER_INTEGER MATCHER_STRING
{
gint account_id = 0;
action_type = MATCHACTION_REDIRECT;
- account_id = atoi($2);
+ account_id = strtol($2, NULL, 10);
destination = $3;
- action = filteringaction_new(action_type, account_id, destination, 0);
+ action = filteringaction_new(action_type,
+ account_id, destination, 0, 0);
}
| MATCHER_COLOR MATCHER_INTEGER
{
gint color = 0;
action_type = MATCHACTION_COLOR;
- color = atoi($2);
- action = filteringaction_new(action_type, 0, NULL, color);
-}
-| MATCHER_CHANGE_SCORE MATCHER_STRING
-{
- gint action_type = MATCHACTION_CHANGE_SCORE;
- char *last_tok = NULL;
- const gchar *first_tok;
- long int chscore;
- int change_type; /* -1 == decrement, 0 == assign, 1 == increment */
-
-#define is_number(x) ( ((x) == '+') || ((x) == '-') || (isdigit((x))) )
- /* find start */
- for (first_tok = $2; *first_tok && !is_number(*first_tok); first_tok++)
- ;
-#undef is_number
-
- chscore = strtol(first_tok, &last_tok, 10);
- if (last_tok == first_tok || *last_tok == 0)
- chscore = 0;
- change_type = *first_tok == '+' ? 1 : *first_tok == '-' ? -1 : 0;
- action = filteringaction_new(MATCHACTION_CHANGE_SCORE, change_type,
- NULL, chscore);
+ color = strtol($2, NULL, 10);
+ action = filteringaction_new(action_type, 0, NULL, color, 0);
+}
+| MATCHER_ADD_SCORE MATCHER_INTEGER
+{
+ gint action_type = MATCHACTION_ADD_SCORE;
+ gint score = 0;
+
+ score = strtol($2, NULL, 10);
+ action = filteringaction_new(MATCHACTION_ADD_SCORE, 0,
+ NULL, 0, score);
+}
+| MATCHER_SET_SCORE MATCHER_INTEGER
+{
+ gint action_type = MATCHACTION_SET_SCORE;
+ gint score = 0;
+
+ score = strtol($2, NULL, 10);
+ action = filteringaction_new(MATCHACTION_SET_SCORE, 0,
+ NULL, 0, score);
+}
+| MATCHER_STOP
+{
+ action = filteringaction_new(MATCHACTION_STOP, 0, NULL, 0, 0);
}
;
scoring_rule:
MATCHER_SCORE MATCHER_INTEGER
{
- score = atoi($2);
+ score = strtol($2, NULL, 0);
}
;
GtkWidget *exec_btn;
GtkWidget *color_label;
GtkWidget *color_optmenu;
+ GtkWidget *score_label;
gint current_action;
} filtering_action;
ACTION_REDIRECT,
ACTION_EXECUTE,
ACTION_COLOR,
+ ACTION_ADD_SCORE,
+ ACTION_SET_SCORE,
+ ACTION_STOP,
/* add other action constants */
} Action;
{ N_("Forward as attachment"), ACTION_FORWARD_AS_ATTACHMENT },
{ N_("Redirect"), ACTION_REDIRECT },
{ N_("Execute"), ACTION_EXECUTE },
- { N_("Color"), ACTION_COLOR }
+ { N_("Color"), ACTION_COLOR },
+ { N_("(In/de)crease score"), ACTION_ADD_SCORE},
+ { N_("Set score"), ACTION_SET_SCORE},
+ { N_("Stop filter"), ACTION_STOP },
};
GtkWidget *account_list;
GtkWidget *dest_label;
GtkWidget *exec_label;
+ GtkWidget *score_label;
GtkWidget *color_label;
GtkWidget *account_label;
GtkWidget *account_combo;
gtk_misc_set_alignment(GTK_MISC(color_label), 0, 0.5);
gtk_box_pack_start(GTK_BOX(hbox1), color_label, FALSE, FALSE, 0);
+ score_label = gtk_label_new (_("Score"));
+ gtk_widget_show (score_label);
+ gtk_misc_set_alignment (GTK_MISC (score_label), 0, 0.5);
+ gtk_box_pack_start (GTK_BOX (hbox1), score_label, FALSE, FALSE, 0);
+
dest_entry = gtk_entry_new ();
gtk_widget_set_usize (dest_entry, 150, -1);
gtk_widget_show (dest_entry);
filtering_action.exec_btn = exec_btn;
filtering_action.color_label = color_label;
filtering_action.color_optmenu = color_optmenu;
+ filtering_action.score_label = score_label;
filtering_action.ok_btn = ok_btn;
filtering_action.action_clist = action_clist;
}
return MATCHACTION_EXECUTE;
case ACTION_COLOR:
return MATCHACTION_COLOR;
+ case ACTION_STOP:
+ return MATCHACTION_STOP;
+ case ACTION_ADD_SCORE:
+ return MATCHACTION_ADD_SCORE;
+ case ACTION_SET_SCORE:
+ return MATCHACTION_SET_SCORE;
default:
return -1;
}
gchar * destination;
gint labelcolor = 0;
FilteringAction * action;
-
+ gchar * score_str;
+ gint score;
+
action_id = get_sel_from_list(GTK_LIST(filtering_action.action_type_list));
action_type = prefs_filtering_action_get_matching_from_action(action_id);
list_id = get_sel_from_list(GTK_LIST(filtering_action.account_list));
account_id = get_account_id_from_list_id(list_id);
-
+ score = 0;
+ destination = NULL;
+
switch (action_id) {
case ACTION_MOVE:
case ACTION_COPY:
gtk_option_menu_get_menu(GTK_OPTION_MENU(filtering_action.color_optmenu)));
destination = NULL;
break;
+ case ACTION_ADD_SCORE:
+ case ACTION_SET_SCORE:
+ score_str = gtk_entry_get_text(GTK_ENTRY(filtering_action.dest_entry));
+ if (*score_str == '\0') {
+ if (alert)
+ alertpanel_error(_("Score is not set"));
+ return NULL;
+ }
+ score = strtol(score_str, NULL, 10);
+ break;
+ case ACTION_STOP:
+ case ACTION_DELETE:
+ case ACTION_MARK:
+ case ACTION_UNMARK:
+ case ACTION_LOCK:
+ case ACTION_UNLOCK:
+ case ACTION_MARK_AS_READ:
+ case ACTION_MARK_AS_UNREAD:
default:
- destination = NULL;
break;
}
- action = filteringaction_new(action_type, account_id, destination, labelcolor);
+ action = filteringaction_new(action_type, account_id,
+ destination, labelcolor, score);
return action;
}
ACTION_COLOR);
gtk_option_menu_set_history(GTK_OPTION_MENU(filtering_action.color_optmenu), action->labelcolor);
break;
+ case MATCHACTION_ADD_SCORE:
+ gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
+ ACTION_ADD_SCORE);
+ break;
+ case MATCHACTION_SET_SCORE:
+ gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
+ ACTION_SET_SCORE);
+ break;
+ case MATCHACTION_STOP:
+ gtk_list_select_item(GTK_LIST(filtering_action.action_type_list),
+ ACTION_STOP);
+ break;
}
}
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);
break;
case ACTION_COPY:
gtk_widget_show(filtering_action.account_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);
break;
case ACTION_DELETE:
gtk_widget_show(filtering_action.account_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);
break;
case ACTION_MARK:
case ACTION_UNMARK:
case ACTION_UNLOCK:
case ACTION_MARK_AS_READ:
case ACTION_MARK_AS_UNREAD:
+ case ACTION_STOP:
gtk_widget_show(filtering_action.account_label);
gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
gtk_widget_set_sensitive(filtering_action.account_combo, FALSE);
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);
break;
case ACTION_FORWARD:
gtk_widget_show(filtering_action.account_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);
break;
case ACTION_FORWARD_AS_ATTACHMENT:
gtk_widget_show(filtering_action.account_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);
break;
case ACTION_REDIRECT:
gtk_widget_show(filtering_action.account_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);
break;
case ACTION_EXECUTE:
gtk_widget_show(filtering_action.account_label);
gtk_widget_show(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);
break;
case ACTION_COLOR:
gtk_widget_show(filtering_action.account_label);
gtk_widget_set_sensitive(filtering_action.exec_btn, FALSE);
gtk_widget_show(filtering_action.color_optmenu);
gtk_widget_show(filtering_action.color_label);
+ gtk_widget_hide(filtering_action.score_label);
+ break;
+ case ACTION_ADD_SCORE:
+ case ACTION_SET_SCORE:
+ gtk_widget_show(filtering_action.account_label);
+ gtk_widget_set_sensitive(filtering_action.account_label, FALSE);
+ gtk_widget_set_sensitive(filtering_action.account_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_hide(filtering_action.dest_label);
+ gtk_widget_hide(filtering_action.recip_label);
+ gtk_widget_hide(filtering_action.exec_label);
+ gtk_widget_show(filtering_action.exec_btn);
+ gtk_widget_set_sensitive(filtering_action.exec_btn, FALSE);
+ gtk_widget_hide(filtering_action.color_optmenu);
+ gtk_widget_hide(filtering_action.color_label);
+ gtk_widget_show(filtering_action.score_label);
break;
}
}