3 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
4 * Copyright (c) 2001-2014 by Hiroyuki Yamamoto & The Claws Mail Team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <glib/gi18n.h>
27 #include "filtering.h"
29 #include "matcher_parser.h"
30 #include "matcher_parser_lex.h"
31 #include "colorlabel.h"
32 #include "folder_item_prefs.h"
34 static gint error = 0;
35 static gint bool_op = 0;
36 static gint match_type = 0;
37 static gchar *header = NULL;
39 static MatcherProp *prop;
41 static GSList *matchers_list = NULL;
43 static gboolean enabled = TRUE;
44 static gchar *name = NULL;
45 static gint account_id = 0;
46 static MatcherList *cond;
47 static GSList *action_list = NULL;
48 static FilteringAction *action = NULL;
49 static gboolean matcher_is_fast = TRUE;
50 static gboolean disable_warnings = FALSE;
52 static FilteringProp *filtering;
54 static GSList **prefs_filtering = NULL;
55 static int enable_compatibility = 0;
60 MATCHER_PARSE_ENABLED,
62 MATCHER_PARSE_ACCOUNT,
63 MATCHER_PARSE_CONDITION,
64 MATCHER_PARSE_FILTERING_ACTION,
67 static int matcher_parse_op = MATCHER_PARSE_FILE;
70 /* ******************************************************************** */
71 /* redeclarations to avoid warnings */
72 void matcher_parserrestart(FILE *input_file);
73 void matcher_parser_init(void);
74 void matcher_parser_switch_to_buffer(void * new_buffer);
75 void matcher_parser_delete_buffer(void * b);
76 void matcher_parserpop_buffer_state(void);
77 int matcher_parserlex(void);
79 void matcher_parser_disable_warnings(const gboolean disable)
81 disable_warnings = disable;
84 void matcher_parser_start_parsing(FILE *f)
86 matcher_parserlineno = 1;
87 matcher_parserrestart(f);
89 matcher_parserparse();
93 void * matcher_parser_scan_string(const char * str);
95 FilteringProp *matcher_parser_get_filtering(gchar *str)
100 /* little hack to allow passing rules with no names */
101 if (!strncmp(str, "rulename ", 9))
102 tmp_str = g_strdup(str);
104 tmp_str = g_strconcat("rulename \"\" ", str, NULL);
106 /* bad coding to enable the sub-grammar matching
108 matcher_parserlineno = 1;
109 matcher_parse_op = MATCHER_PARSE_NO_EOL;
110 matcher_parserrestart(NULL);
111 matcher_parserpop_buffer_state();
112 matcher_parser_init();
113 bufstate = matcher_parser_scan_string((const char *) tmp_str);
114 matcher_parser_switch_to_buffer(bufstate);
115 if (matcher_parserparse() != 0)
117 matcher_parse_op = MATCHER_PARSE_FILE;
118 matcher_parser_delete_buffer(bufstate);
123 static gboolean check_quote_symetry(gchar *str)
129 return TRUE; /* heh, that's symetric */
132 for (walk = str; *walk; walk++) {
134 if (walk == str /* first char */
135 || *(walk - 1) != '\\') /* not escaped */
142 MatcherList *matcher_parser_get_name(gchar *str)
146 if (!check_quote_symetry(str)) {
151 /* bad coding to enable the sub-grammar matching
153 matcher_parserlineno = 1;
154 matcher_parse_op = MATCHER_PARSE_NAME;
155 matcher_parserrestart(NULL);
156 matcher_parserpop_buffer_state();
157 matcher_parser_init();
158 bufstate = matcher_parser_scan_string(str);
159 matcher_parserparse();
160 matcher_parse_op = MATCHER_PARSE_FILE;
161 matcher_parser_delete_buffer(bufstate);
165 MatcherList *matcher_parser_get_enabled(gchar *str)
169 if (!check_quote_symetry(str)) {
174 /* bad coding to enable the sub-grammar matching
176 matcher_parserlineno = 1;
177 matcher_parse_op = MATCHER_PARSE_ENABLED;
178 matcher_parserrestart(NULL);
179 matcher_parserpop_buffer_state();
180 matcher_parser_init();
181 bufstate = matcher_parser_scan_string(str);
182 matcher_parserparse();
183 matcher_parse_op = MATCHER_PARSE_FILE;
184 matcher_parser_delete_buffer(bufstate);
188 MatcherList *matcher_parser_get_account(gchar *str)
192 if (!check_quote_symetry(str)) {
197 /* bad coding to enable the sub-grammar matching
199 matcher_parserlineno = 1;
200 matcher_parse_op = MATCHER_PARSE_ACCOUNT;
201 matcher_parserrestart(NULL);
202 matcher_parserpop_buffer_state();
203 matcher_parser_init();
204 bufstate = matcher_parser_scan_string(str);
205 matcher_parserparse();
206 matcher_parse_op = MATCHER_PARSE_FILE;
207 matcher_parser_delete_buffer(bufstate);
211 MatcherList *matcher_parser_get_cond(gchar *str, gboolean *is_fast)
215 if (!check_quote_symetry(str)) {
220 matcher_is_fast = TRUE;
221 /* bad coding to enable the sub-grammar matching
223 matcher_parserlineno = 1;
224 matcher_parse_op = MATCHER_PARSE_CONDITION;
225 matcher_parserrestart(NULL);
226 matcher_parserpop_buffer_state();
227 matcher_parser_init();
228 bufstate = matcher_parser_scan_string(str);
229 matcher_parserparse();
230 matcher_parse_op = MATCHER_PARSE_FILE;
231 matcher_parser_delete_buffer(bufstate);
233 *is_fast = matcher_is_fast;
237 GSList *matcher_parser_get_action_list(gchar *str)
241 if (!check_quote_symetry(str)) {
246 /* bad coding to enable the sub-grammar matching
248 matcher_parserlineno = 1;
249 matcher_parse_op = MATCHER_PARSE_FILTERING_ACTION;
250 matcher_parserrestart(NULL);
251 matcher_parserpop_buffer_state();
252 matcher_parser_init();
253 bufstate = matcher_parser_scan_string(str);
254 matcher_parserparse();
255 matcher_parse_op = MATCHER_PARSE_FILE;
256 matcher_parser_delete_buffer(bufstate);
260 MatcherProp *matcher_parser_get_prop(gchar *str)
265 matcher_parserlineno = 1;
266 list = matcher_parser_get_cond(str, NULL);
270 if (list->matchers == NULL)
273 if (list->matchers->next != NULL)
276 prop = list->matchers->data;
278 g_slist_free(list->matchers);
284 void matcher_parsererror(char *str)
289 for (l = matchers_list; l != NULL; l = g_slist_next(l)) {
290 matcherprop_free((MatcherProp *)
294 g_slist_free(matchers_list);
295 matchers_list = NULL;
298 if (!disable_warnings)
299 g_warning("filtering parsing: %i: %s\n",
300 matcher_parserlineno, str);
304 int matcher_parserwrap(void)
314 %token MATCHER_ALL MATCHER_UNREAD MATCHER_NOT_UNREAD
315 %token MATCHER_NEW MATCHER_NOT_NEW MATCHER_MARKED
316 %token MATCHER_NOT_MARKED MATCHER_DELETED MATCHER_NOT_DELETED
317 %token MATCHER_REPLIED MATCHER_NOT_REPLIED MATCHER_FORWARDED
318 %token MATCHER_NOT_FORWARDED MATCHER_SUBJECT MATCHER_NOT_SUBJECT
319 %token MATCHER_FROM MATCHER_NOT_FROM MATCHER_TO MATCHER_NOT_TO
320 %token MATCHER_CC MATCHER_NOT_CC MATCHER_TO_OR_CC MATCHER_NOT_TO_AND_NOT_CC
321 %token MATCHER_AGE_GREATER MATCHER_AGE_LOWER MATCHER_NEWSGROUPS
322 %token MATCHER_AGE_GREATER_HOURS MATCHER_AGE_LOWER_HOURS
323 %token MATCHER_NOT_NEWSGROUPS MATCHER_INREPLYTO MATCHER_NOT_INREPLYTO
324 %token MATCHER_REFERENCES MATCHER_NOT_REFERENCES MATCHER_SCORE_GREATER
325 %token MATCHER_SCORE_LOWER MATCHER_HEADER MATCHER_NOT_HEADER
326 %token MATCHER_HEADERS_PART MATCHER_NOT_HEADERS_PART MATCHER_MESSAGE
327 %token MATCHER_HEADERS_CONT MATCHER_NOT_HEADERS_CONT
328 %token MATCHER_NOT_MESSAGE MATCHER_BODY_PART MATCHER_NOT_BODY_PART
329 %token MATCHER_TEST MATCHER_NOT_TEST MATCHER_MATCHCASE MATCHER_MATCH
330 %token MATCHER_REGEXPCASE MATCHER_REGEXP MATCHER_SCORE MATCHER_MOVE
331 %token MATCHER_FOUND_IN_ADDRESSBOOK MATCHER_NOT_FOUND_IN_ADDRESSBOOK MATCHER_IN
332 %token MATCHER_COPY MATCHER_DELETE MATCHER_MARK MATCHER_UNMARK
333 %token MATCHER_LOCK MATCHER_UNLOCK
334 %token MATCHER_EXECUTE
335 %token MATCHER_MARK_AS_READ MATCHER_MARK_AS_UNREAD MATCHER_FORWARD
336 %token MATCHER_MARK_AS_SPAM MATCHER_MARK_AS_HAM
337 %token MATCHER_FORWARD_AS_ATTACHMENT MATCHER_EOL
338 %token MATCHER_OR MATCHER_AND
339 %token MATCHER_COLOR MATCHER_SCORE_EQUAL MATCHER_REDIRECT
340 %token MATCHER_SIZE_GREATER MATCHER_SIZE_SMALLER MATCHER_SIZE_EQUAL
341 %token MATCHER_LOCKED MATCHER_NOT_LOCKED
342 %token MATCHER_PARTIAL MATCHER_NOT_PARTIAL
343 %token MATCHER_COLORLABEL MATCHER_NOT_COLORLABEL
344 %token MATCHER_IGNORE_THREAD MATCHER_NOT_IGNORE_THREAD
345 %token MATCHER_WATCH_THREAD MATCHER_NOT_WATCH_THREAD
346 %token MATCHER_CHANGE_SCORE MATCHER_SET_SCORE
347 %token MATCHER_ADD_TO_ADDRESSBOOK
348 %token MATCHER_STOP MATCHER_HIDE MATCHER_IGNORE MATCHER_WATCH
349 %token MATCHER_SPAM MATCHER_NOT_SPAM
350 %token MATCHER_HAS_ATTACHMENT MATCHER_HAS_NO_ATTACHMENT
351 %token MATCHER_SIGNED MATCHER_NOT_SIGNED
352 %token MATCHER_TAG MATCHER_NOT_TAG MATCHER_SET_TAG MATCHER_UNSET_TAG
353 %token MATCHER_TAGGED MATCHER_NOT_TAGGED MATCHER_CLEAR_TAGS
357 %token MATCHER_ENABLED MATCHER_DISABLED
358 %token MATCHER_RULENAME
359 %token MATCHER_ACCOUNT
360 %token <str> MATCHER_STRING
361 %token <str> MATCHER_SECTION
362 %token <str> MATCHER_INTEGER
368 if (matcher_parse_op == MATCHER_PARSE_FILE) {
369 prefs_filtering = &pre_global_processing;
383 { action_list = NULL; }
390 section_notification:
391 MATCHER_SECTION MATCHER_EOL
394 FolderItem *item = NULL;
396 if (matcher_parse_op == MATCHER_PARSE_FILE) {
397 enable_compatibility = 0;
398 if (!strcmp(folder, "global")) {
399 /* backward compatibility */
400 enable_compatibility = 1;
402 else if (!strcmp(folder, "preglobal")) {
403 prefs_filtering = &pre_global_processing;
405 else if (!strcmp(folder, "postglobal")) {
406 prefs_filtering = &post_global_processing;
408 else if (!strcmp(folder, "filtering")) {
409 prefs_filtering = &filtering_rules;
412 item = folder_find_item_from_identifier(folder);
414 prefs_filtering = &item->prefs->processing;
416 prefs_filtering = NULL;
424 enabled name account condition filtering MATCHER_EOL
425 | enabled name account condition filtering
426 | enabled name condition filtering MATCHER_EOL
427 | enabled name condition filtering
428 | name condition filtering MATCHER_EOL
429 | name condition filtering
431 if (matcher_parse_op == MATCHER_PARSE_NO_EOL)
434 matcher_parsererror("parse error [no eol]");
440 if (matcher_parse_op == MATCHER_PARSE_ENABLED)
443 matcher_parsererror("parse error [enabled]");
449 if (matcher_parse_op == MATCHER_PARSE_ACCOUNT)
452 matcher_parsererror("parse error [account]");
458 if (matcher_parse_op == MATCHER_PARSE_NAME)
461 matcher_parsererror("parse error [name]");
467 if (matcher_parse_op == MATCHER_PARSE_CONDITION)
470 matcher_parsererror("parse error [condition]");
474 | filtering_action_list
476 if (matcher_parse_op == MATCHER_PARSE_FILTERING_ACTION)
479 matcher_parsererror("parse error [filtering action]");
498 MATCHER_RULENAME MATCHER_STRING
505 MATCHER_ACCOUNT MATCHER_INTEGER
507 account_id = strtol($2, NULL, 10);
512 filtering_action_list
514 filtering = filteringprop_new(enabled, name, account_id, cond, action_list);
519 if (enable_compatibility) {
520 prefs_filtering = &filtering_rules;
521 if (action_list != NULL) {
522 FilteringAction * first_action;
524 first_action = action_list->data;
526 if (first_action->type == MATCHACTION_CHANGE_SCORE)
527 prefs_filtering = &pre_global_processing;
534 if ((matcher_parse_op == MATCHER_PARSE_FILE) &&
535 (prefs_filtering != NULL)) {
536 *prefs_filtering = g_slist_append(*prefs_filtering,
543 filtering_action_list:
544 filtering_action_b filtering_action_list
551 action_list = g_slist_append(action_list, action);
559 match_type = MATCHTYPE_MATCHCASE;
563 match_type = MATCHTYPE_MATCH;
567 match_type = MATCHTYPE_REGEXPCASE;
571 match_type = MATCHTYPE_REGEXP;
578 cond = matcherlist_new(matchers_list, (bool_op == MATCHERBOOL_AND));
579 matchers_list = NULL;
584 condition_list bool_op one_condition
586 matchers_list = g_slist_append(matchers_list, prop);
590 matchers_list = NULL;
591 matchers_list = g_slist_append(matchers_list, prop);
598 bool_op = MATCHERBOOL_AND;
602 bool_op = MATCHERBOOL_OR;
611 criteria = MATCHCRITERIA_ALL;
612 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
618 criteria = MATCHCRITERIA_UNREAD;
619 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
625 criteria = MATCHCRITERIA_NOT_UNREAD;
626 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
632 criteria = MATCHCRITERIA_NEW;
633 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
639 criteria = MATCHCRITERIA_NOT_NEW;
640 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
646 criteria = MATCHCRITERIA_MARKED;
647 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
653 criteria = MATCHCRITERIA_NOT_MARKED;
654 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
660 criteria = MATCHCRITERIA_DELETED;
661 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
663 | MATCHER_NOT_DELETED
667 criteria = MATCHCRITERIA_NOT_DELETED;
668 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
674 criteria = MATCHCRITERIA_REPLIED;
675 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
677 | MATCHER_NOT_REPLIED
681 criteria = MATCHCRITERIA_NOT_REPLIED;
682 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
688 criteria = MATCHCRITERIA_FORWARDED;
689 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
691 | MATCHER_NOT_FORWARDED
695 criteria = MATCHCRITERIA_NOT_FORWARDED;
696 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
702 criteria = MATCHCRITERIA_LOCKED;
703 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
709 criteria = MATCHCRITERIA_NOT_LOCKED;
710 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
716 criteria = MATCHCRITERIA_SPAM;
717 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
723 criteria = MATCHCRITERIA_NOT_SPAM;
724 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
726 | MATCHER_HAS_ATTACHMENT
730 criteria = MATCHCRITERIA_HAS_ATTACHMENT;
731 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
733 | MATCHER_HAS_NO_ATTACHMENT
737 criteria = MATCHCRITERIA_HAS_NO_ATTACHMENT;
738 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
744 criteria = MATCHCRITERIA_SIGNED;
745 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
751 criteria = MATCHCRITERIA_NOT_SIGNED;
752 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
758 criteria = MATCHCRITERIA_PARTIAL;
759 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
761 | MATCHER_NOT_PARTIAL
765 criteria = MATCHCRITERIA_NOT_PARTIAL;
766 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
768 | MATCHER_COLORLABEL MATCHER_INTEGER
773 criteria = MATCHCRITERIA_COLORLABEL;
774 value = strtol($2, NULL, 10);
775 if (value < 0) value = 0;
776 else if (value > COLORLABELS) value = COLORLABELS;
777 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
779 | MATCHER_NOT_COLORLABEL MATCHER_INTEGER
784 criteria = MATCHCRITERIA_NOT_COLORLABEL;
785 value = strtol($2, NULL, 0);
786 if (value < 0) value = 0;
787 else if (value > COLORLABELS) value = COLORLABELS;
788 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
790 | MATCHER_IGNORE_THREAD
794 criteria = MATCHCRITERIA_IGNORE_THREAD;
795 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
797 | MATCHER_NOT_IGNORE_THREAD
801 criteria = MATCHCRITERIA_NOT_IGNORE_THREAD;
802 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
804 | MATCHER_WATCH_THREAD
808 criteria = MATCHCRITERIA_WATCH_THREAD;
809 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
811 | MATCHER_NOT_WATCH_THREAD
815 criteria = MATCHCRITERIA_NOT_WATCH_THREAD;
816 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
818 | MATCHER_SUBJECT match_type MATCHER_STRING
823 criteria = MATCHCRITERIA_SUBJECT;
825 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
827 | MATCHER_NOT_SUBJECT match_type MATCHER_STRING
832 criteria = MATCHCRITERIA_NOT_SUBJECT;
834 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
836 | MATCHER_FROM match_type MATCHER_STRING
841 criteria = MATCHCRITERIA_FROM;
843 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
845 | MATCHER_NOT_FROM match_type MATCHER_STRING
850 criteria = MATCHCRITERIA_NOT_FROM;
852 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
854 | MATCHER_TO match_type MATCHER_STRING
859 criteria = MATCHCRITERIA_TO;
861 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
863 | MATCHER_NOT_TO match_type MATCHER_STRING
868 criteria = MATCHCRITERIA_NOT_TO;
870 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
872 | MATCHER_CC match_type MATCHER_STRING
877 criteria = MATCHCRITERIA_CC;
879 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
881 | MATCHER_NOT_CC match_type MATCHER_STRING
886 criteria = MATCHCRITERIA_NOT_CC;
888 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
890 | MATCHER_TO_OR_CC match_type MATCHER_STRING
895 criteria = MATCHCRITERIA_TO_OR_CC;
897 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
899 | MATCHER_NOT_TO_AND_NOT_CC match_type MATCHER_STRING
904 criteria = MATCHCRITERIA_NOT_TO_AND_NOT_CC;
906 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
908 | MATCHER_TAG match_type MATCHER_STRING
913 criteria = MATCHCRITERIA_TAG;
915 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
917 | MATCHER_NOT_TAG match_type MATCHER_STRING
922 criteria = MATCHCRITERIA_NOT_TAG;
924 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
930 criteria = MATCHCRITERIA_TAGGED;
931 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
937 criteria = MATCHCRITERIA_NOT_TAGGED;
938 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
940 | MATCHER_AGE_GREATER MATCHER_INTEGER
945 criteria = MATCHCRITERIA_AGE_GREATER;
946 value = strtol($2, NULL, 0);
947 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
949 | MATCHER_AGE_LOWER MATCHER_INTEGER
954 criteria = MATCHCRITERIA_AGE_LOWER;
955 value = strtol($2, NULL, 0);
956 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
958 | MATCHER_AGE_GREATER_HOURS MATCHER_INTEGER
963 criteria = MATCHCRITERIA_AGE_GREATER_HOURS;
964 value = strtol($2, NULL, 0);
965 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
967 | MATCHER_AGE_LOWER_HOURS MATCHER_INTEGER
972 criteria = MATCHCRITERIA_AGE_LOWER_HOURS;
973 value = strtol($2, NULL, 0);
974 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
976 | MATCHER_NEWSGROUPS match_type MATCHER_STRING
981 criteria = MATCHCRITERIA_NEWSGROUPS;
983 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
985 | MATCHER_NOT_NEWSGROUPS match_type MATCHER_STRING
990 criteria = MATCHCRITERIA_NOT_NEWSGROUPS;
992 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
994 | MATCHER_INREPLYTO match_type MATCHER_STRING
999 criteria = MATCHCRITERIA_INREPLYTO;
1001 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1003 | MATCHER_NOT_INREPLYTO match_type MATCHER_STRING
1008 criteria = MATCHCRITERIA_NOT_INREPLYTO;
1010 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1012 | MATCHER_REFERENCES match_type MATCHER_STRING
1017 criteria = MATCHCRITERIA_REFERENCES;
1019 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1021 | MATCHER_NOT_REFERENCES match_type MATCHER_STRING
1026 criteria = MATCHCRITERIA_NOT_REFERENCES;
1028 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1030 | MATCHER_SCORE_GREATER MATCHER_INTEGER
1035 criteria = MATCHCRITERIA_SCORE_GREATER;
1036 value = strtol($2, NULL, 0);
1037 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1039 | MATCHER_SCORE_LOWER MATCHER_INTEGER
1044 criteria = MATCHCRITERIA_SCORE_LOWER;
1045 value = strtol($2, NULL, 0);
1046 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1048 | MATCHER_SCORE_EQUAL MATCHER_INTEGER
1053 criteria = MATCHCRITERIA_SCORE_EQUAL;
1054 value = strtol($2, NULL, 0);
1055 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1057 | MATCHER_SIZE_GREATER MATCHER_INTEGER
1061 criteria = MATCHCRITERIA_SIZE_GREATER;
1062 value = strtol($2, NULL, 0);
1063 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1065 | MATCHER_SIZE_SMALLER MATCHER_INTEGER
1069 criteria = MATCHCRITERIA_SIZE_SMALLER;
1070 value = strtol($2, NULL, 0);
1071 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1073 | MATCHER_SIZE_EQUAL MATCHER_INTEGER
1077 criteria = MATCHCRITERIA_SIZE_EQUAL;
1078 value = strtol($2, NULL, 0);
1079 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1081 | MATCHER_HEADER MATCHER_STRING
1083 header = g_strdup($2);
1084 } match_type MATCHER_STRING
1088 matcher_is_fast = FALSE;
1089 criteria = MATCHCRITERIA_HEADER;
1091 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1094 | MATCHER_NOT_HEADER MATCHER_STRING
1096 header = g_strdup($2);
1097 } match_type MATCHER_STRING
1101 matcher_is_fast = FALSE;
1102 criteria = MATCHCRITERIA_NOT_HEADER;
1104 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1107 | MATCHER_HEADERS_PART match_type MATCHER_STRING
1111 matcher_is_fast = FALSE;
1112 criteria = MATCHCRITERIA_HEADERS_PART;
1114 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1116 | MATCHER_NOT_HEADERS_PART match_type MATCHER_STRING
1120 matcher_is_fast = FALSE;
1121 criteria = MATCHCRITERIA_NOT_HEADERS_PART;
1123 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1125 | MATCHER_HEADERS_CONT match_type MATCHER_STRING
1129 matcher_is_fast = FALSE;
1130 criteria = MATCHCRITERIA_HEADERS_CONT;
1132 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1134 | MATCHER_NOT_HEADERS_CONT match_type MATCHER_STRING
1138 matcher_is_fast = FALSE;
1139 criteria = MATCHCRITERIA_NOT_HEADERS_CONT;
1141 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1143 | MATCHER_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1145 header = g_strdup($2);
1146 } MATCHER_IN MATCHER_STRING
1151 criteria = MATCHCRITERIA_FOUND_IN_ADDRESSBOOK;
1153 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1156 | MATCHER_NOT_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1158 header = g_strdup($2);
1159 } MATCHER_IN MATCHER_STRING
1164 criteria = MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK;
1166 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1169 | MATCHER_MESSAGE match_type MATCHER_STRING
1173 matcher_is_fast = FALSE;
1174 criteria = MATCHCRITERIA_MESSAGE;
1176 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1178 | MATCHER_NOT_MESSAGE match_type MATCHER_STRING
1182 matcher_is_fast = FALSE;
1183 criteria = MATCHCRITERIA_NOT_MESSAGE;
1185 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1187 | MATCHER_BODY_PART match_type MATCHER_STRING
1191 matcher_is_fast = FALSE;
1192 criteria = MATCHCRITERIA_BODY_PART;
1194 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1196 | MATCHER_NOT_BODY_PART match_type MATCHER_STRING
1200 matcher_is_fast = FALSE;
1201 criteria = MATCHCRITERIA_NOT_BODY_PART;
1203 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1205 | MATCHER_TEST MATCHER_STRING
1209 matcher_is_fast = FALSE;
1210 criteria = MATCHCRITERIA_TEST;
1212 prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, expr, 0);
1214 | MATCHER_NOT_TEST MATCHER_STRING
1218 matcher_is_fast = FALSE;
1219 criteria = MATCHCRITERIA_NOT_TEST;
1221 prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, expr, 0);
1226 MATCHER_EXECUTE MATCHER_STRING
1229 gint action_type = 0;
1231 action_type = MATCHACTION_EXECUTE;
1233 action = filteringaction_new(action_type, 0, cmd, 0, 0, NULL);
1235 | MATCHER_MOVE MATCHER_STRING
1237 gchar *destination = NULL;
1238 gint action_type = 0;
1240 action_type = MATCHACTION_MOVE;
1242 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1244 | MATCHER_SET_TAG MATCHER_STRING
1246 gchar *destination = NULL;
1247 gint action_type = 0;
1249 action_type = MATCHACTION_SET_TAG;
1251 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1253 | MATCHER_UNSET_TAG MATCHER_STRING
1255 gchar *destination = NULL;
1256 gint action_type = 0;
1258 action_type = MATCHACTION_UNSET_TAG;
1260 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1262 | MATCHER_CLEAR_TAGS
1264 gint action_type = 0;
1266 action_type = MATCHACTION_CLEAR_TAGS;
1267 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1269 | MATCHER_COPY MATCHER_STRING
1271 gchar *destination = NULL;
1272 gint action_type = 0;
1274 action_type = MATCHACTION_COPY;
1276 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1280 gint action_type = 0;
1282 action_type = MATCHACTION_DELETE;
1283 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1287 gint action_type = 0;
1289 action_type = MATCHACTION_MARK;
1290 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1294 gint action_type = 0;
1296 action_type = MATCHACTION_UNMARK;
1297 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1301 gint action_type = 0;
1303 action_type = MATCHACTION_LOCK;
1304 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1308 gint action_type = 0;
1310 action_type = MATCHACTION_UNLOCK;
1311 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1313 | MATCHER_MARK_AS_READ
1315 gint action_type = 0;
1317 action_type = MATCHACTION_MARK_AS_READ;
1318 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1320 | MATCHER_MARK_AS_UNREAD
1322 gint action_type = 0;
1324 action_type = MATCHACTION_MARK_AS_UNREAD;
1325 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1327 | MATCHER_MARK_AS_SPAM
1329 gint action_type = 0;
1331 action_type = MATCHACTION_MARK_AS_SPAM;
1332 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1334 | MATCHER_MARK_AS_HAM
1336 gint action_type = 0;
1338 action_type = MATCHACTION_MARK_AS_HAM;
1339 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1341 | MATCHER_FORWARD MATCHER_INTEGER MATCHER_STRING
1343 gchar *destination = NULL;
1344 gint action_type = 0;
1345 gint account_id = 0;
1347 action_type = MATCHACTION_FORWARD;
1348 account_id = strtol($2, NULL, 10);
1350 action = filteringaction_new(action_type,
1351 account_id, destination, 0, 0, NULL);
1353 | MATCHER_FORWARD_AS_ATTACHMENT MATCHER_INTEGER MATCHER_STRING
1355 gchar *destination = NULL;
1356 gint action_type = 0;
1357 gint account_id = 0;
1359 action_type = MATCHACTION_FORWARD_AS_ATTACHMENT;
1360 account_id = strtol($2, NULL, 10);
1362 action = filteringaction_new(action_type,
1363 account_id, destination, 0, 0, NULL);
1365 | MATCHER_REDIRECT MATCHER_INTEGER MATCHER_STRING
1367 gchar *destination = NULL;
1368 gint action_type = 0;
1369 gint account_id = 0;
1371 action_type = MATCHACTION_REDIRECT;
1372 account_id = strtol($2, NULL, 10);
1374 action = filteringaction_new(action_type,
1375 account_id, destination, 0, 0, NULL);
1377 | MATCHER_COLOR MATCHER_INTEGER
1379 gint action_type = 0;
1382 action_type = MATCHACTION_COLOR;
1383 color = strtol($2, NULL, 10);
1384 action = filteringaction_new(action_type, 0, NULL, color, 0, NULL);
1386 | MATCHER_CHANGE_SCORE MATCHER_INTEGER
1390 score = strtol($2, NULL, 10);
1391 action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1392 NULL, 0, score, NULL);
1394 /* backward compatibility */
1395 | MATCHER_SCORE MATCHER_INTEGER
1399 score = strtol($2, NULL, 10);
1400 action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1401 NULL, 0, score, NULL);
1403 | MATCHER_SET_SCORE MATCHER_INTEGER
1407 score = strtol($2, NULL, 10);
1408 action = filteringaction_new(MATCHACTION_SET_SCORE, 0,
1409 NULL, 0, score, NULL);
1413 action = filteringaction_new(MATCHACTION_HIDE, 0, NULL, 0, 0, NULL);
1417 action = filteringaction_new(MATCHACTION_IGNORE, 0, NULL, 0, 0, NULL);
1421 action = filteringaction_new(MATCHACTION_WATCH, 0, NULL, 0, 0, NULL);
1423 | MATCHER_ADD_TO_ADDRESSBOOK MATCHER_STRING
1425 header = g_strdup($2);
1428 gchar *addressbook = NULL;
1429 gint action_type = 0;
1431 action_type = MATCHACTION_ADD_TO_ADDRESSBOOK;
1433 action = filteringaction_new(action_type, 0, addressbook, 0, 0, header);
1438 action = filteringaction_new(MATCHACTION_STOP, 0, NULL, 0, 0, NULL);