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) {
}
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;
+ return TRUE;
+
default:
break;
}
{MATCHACTION_EXECUTE, "execute"},
{MATCHACTION_COLOR, "color"},
{MATCHACTION_REDIRECT, "redirect"},
- {MATCHACTION_DELETE_ON_SERVER, "delete_on_server"}
+ {MATCHACTION_DELETE_ON_SERVER, "delete_on_server"},
+ {MATCHACTION_CHANGE_SCORE, "change_score"}
};
/*!
for (i = 0; i < sizeof matchparser_tab / sizeof matchparser_tab[0]; i++)
g_hash_table_insert(matchparser_hashtab,
matchparser_tab[i].str,
- &matchparser_tab[i]);
+ (gpointer) &matchparser_tab[i]);
}
/*!
prop = matcherprop_new(criteria, header, matchtype, expr, value);
- g_free(header);
- g_free(expr);
+ g_free((gpointer) header);
+ g_free((gpointer) expr);
return prop;
}
*\return gboolean TRUE if str matches the condition in the
* matcher structure
*/
-static gboolean matcherprop_string_match(const MatcherProp *prop, const gchar *str)
+static gboolean matcherprop_string_match(MatcherProp *prop, const gchar *str)
{
gchar *str1;
gchar *str2;
*\return gboolean TRUE if command was executed succesfully
*/
static gboolean matcherprop_match_execute(const MatcherProp *prop,
- const MsgInfo *info)
+ MsgInfo *info)
{
gchar *file;
gchar *cmd;
*
*\return gboolean TRUE if a match
*/
-gboolean matcherprop_match(const MatcherProp *prop,
- const MsgInfo *info)
+gboolean matcherprop_match(MatcherProp *prop,
+ MsgInfo *info)
{
time_t t;
*
*\return boolean TRUE if matching header
*/
-static gboolean matcherprop_match_one_header(const MatcherProp *matcher,
- const gchar *buf)
+static gboolean matcherprop_match_one_header(MatcherProp *matcher,
+ gchar *buf)
{
gboolean result;
Header *header;
*\return gboolean TRUE if matching should stop
*/
static gboolean matcherlist_match_one_header(MatcherList *matchers,
- const gchar *buf)
+ gchar *buf)
{
GSList *l;
*
*\return gchar * Newly allocated string
*/
-gchar *matcherprop_to_string(const MatcherProp *matcher)
+gchar *matcherprop_to_string(MatcherProp *matcher)
{
gchar *matcher_str = NULL;
const gchar *criteria_str;
const gchar *matchtype_str;
int i;
- char *expr;
+ const char *expr;
char *header;
criteria_str = NULL;
case MATCHCRITERIA_NOT_EXECUTE:
expr = matcher_escape_str(matcher->expr);
matcher_str = g_strdup_printf("%s \"%s\"", criteria_str, expr);
- g_free(expr);
+ g_free((gpointer) expr);
return matcher_str;
}
case MATCHTYPE_REGEXP:
case MATCHTYPE_REGEXPCASE:
expr = matcher_escape_str(matcher->expr);
- header = matcher_escape_str(matcher->header);
if (matcher->header)
matcher_str = g_strdup_printf
("%s \"%s\" %s \"%s\"",
matcher_str = g_strdup_printf
("%s %s \"%s\"", criteria_str,
matchtype_str, expr);
- g_free(header);
- g_free(expr);
+ g_free((gpointer) expr);
break;
}
MA_(COLOR),
MA_(REDIRECT),
MA_(DELETE_ON_SERVER),
+ MA_(CHANGE_SCORE),
/* boolean operations */
MB_(OR),
MB_(AND)
MatcherProp *matcherprop_copy (const MatcherProp *src);
-gboolean matcherprop_match (const MatcherProp *prop,
- const MsgInfo *info);
+gboolean matcherprop_match (MatcherProp *prop,
+ MsgInfo *info);
MatcherList * matcherlist_new (GSList *matchers,
gboolean bool_and);
gchar *matcher_parse_str (gchar **str);
const gchar *matcher_escape_str (const gchar *str);
gchar *matcher_unescape_str (gchar *str);
-gchar *matcherprop_to_string (const MatcherProp *matcher);
+gchar *matcherprop_to_string (MatcherProp *matcher);
gchar *matcherlist_to_string (const MatcherList *matchers);
gchar *matching_build_command (const gchar *cmd,
MsgInfo *info);
%token MATCHER_LOCKED MATCHER_NOT_LOCKED
%token MATCHER_COLORLABEL MATCHER_NOT_COLORLABEL
%token MATCHER_IGNORE_THREAD MATCHER_NOT_IGNORE_THREAD
+%token MATCHER_CHANGE_SCORE
%start file
action_type = MATCHACTION_DELETE_ON_SERVER;
action = filteringaction_new(action_type, 0, NULL, 0);
}
+| 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);
+}
;
scoring_rule: