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",
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_MESSAGEID MATCHER_NOT_MESSAGEID
325 %token MATCHER_REFERENCES MATCHER_NOT_REFERENCES MATCHER_SCORE_GREATER
326 %token MATCHER_SCORE_LOWER MATCHER_HEADER MATCHER_NOT_HEADER
327 %token MATCHER_HEADERS_PART MATCHER_NOT_HEADERS_PART MATCHER_MESSAGE
328 %token MATCHER_HEADERS_CONT MATCHER_NOT_HEADERS_CONT
329 %token MATCHER_NOT_MESSAGE MATCHER_BODY_PART MATCHER_NOT_BODY_PART
330 %token MATCHER_TEST MATCHER_NOT_TEST MATCHER_MATCHCASE MATCHER_MATCH
331 %token MATCHER_REGEXPCASE MATCHER_REGEXP MATCHER_SCORE MATCHER_MOVE
332 %token MATCHER_FOUND_IN_ADDRESSBOOK MATCHER_NOT_FOUND_IN_ADDRESSBOOK MATCHER_IN
333 %token MATCHER_COPY MATCHER_DELETE MATCHER_MARK MATCHER_UNMARK
334 %token MATCHER_LOCK MATCHER_UNLOCK
335 %token MATCHER_EXECUTE
336 %token MATCHER_MARK_AS_READ MATCHER_MARK_AS_UNREAD MATCHER_FORWARD
337 %token MATCHER_MARK_AS_SPAM MATCHER_MARK_AS_HAM
338 %token MATCHER_FORWARD_AS_ATTACHMENT MATCHER_EOL
339 %token MATCHER_OR MATCHER_AND
340 %token MATCHER_COLOR MATCHER_SCORE_EQUAL MATCHER_REDIRECT
341 %token MATCHER_SIZE_GREATER MATCHER_SIZE_SMALLER MATCHER_SIZE_EQUAL
342 %token MATCHER_LOCKED MATCHER_NOT_LOCKED
343 %token MATCHER_PARTIAL MATCHER_NOT_PARTIAL
344 %token MATCHER_COLORLABEL MATCHER_NOT_COLORLABEL
345 %token MATCHER_IGNORE_THREAD MATCHER_NOT_IGNORE_THREAD
346 %token MATCHER_WATCH_THREAD MATCHER_NOT_WATCH_THREAD
347 %token MATCHER_CHANGE_SCORE MATCHER_SET_SCORE
348 %token MATCHER_ADD_TO_ADDRESSBOOK
349 %token MATCHER_STOP MATCHER_HIDE MATCHER_IGNORE MATCHER_WATCH
350 %token MATCHER_SPAM MATCHER_NOT_SPAM
351 %token MATCHER_HAS_ATTACHMENT MATCHER_HAS_NO_ATTACHMENT
352 %token MATCHER_SIGNED MATCHER_NOT_SIGNED
353 %token MATCHER_TAG MATCHER_NOT_TAG MATCHER_SET_TAG MATCHER_UNSET_TAG
354 %token MATCHER_TAGGED MATCHER_NOT_TAGGED MATCHER_CLEAR_TAGS
358 %token MATCHER_ENABLED MATCHER_DISABLED
359 %token MATCHER_RULENAME
360 %token MATCHER_ACCOUNT
361 %token <str> MATCHER_STRING
362 %token <str> MATCHER_SECTION
363 %token <str> MATCHER_INTEGER
369 if (matcher_parse_op == MATCHER_PARSE_FILE) {
370 prefs_filtering = &pre_global_processing;
384 { action_list = NULL; }
391 section_notification:
392 MATCHER_SECTION MATCHER_EOL
395 FolderItem *item = NULL;
397 if (matcher_parse_op == MATCHER_PARSE_FILE) {
398 enable_compatibility = 0;
399 if (!strcmp(folder, "global")) {
400 /* backward compatibility */
401 enable_compatibility = 1;
403 else if (!strcmp(folder, "preglobal")) {
404 prefs_filtering = &pre_global_processing;
406 else if (!strcmp(folder, "postglobal")) {
407 prefs_filtering = &post_global_processing;
409 else if (!strcmp(folder, "filtering")) {
410 prefs_filtering = &filtering_rules;
413 item = folder_find_item_from_identifier(folder);
415 prefs_filtering = &item->prefs->processing;
417 prefs_filtering = NULL;
425 enabled name account condition filtering MATCHER_EOL
426 | enabled name account condition filtering
427 | enabled name condition filtering MATCHER_EOL
428 | enabled name condition filtering
429 | name condition filtering MATCHER_EOL
430 | name condition filtering
432 if (matcher_parse_op == MATCHER_PARSE_NO_EOL)
435 matcher_parsererror("parse error [no eol]");
441 if (matcher_parse_op == MATCHER_PARSE_ENABLED)
444 matcher_parsererror("parse error [enabled]");
450 if (matcher_parse_op == MATCHER_PARSE_ACCOUNT)
453 matcher_parsererror("parse error [account]");
459 if (matcher_parse_op == MATCHER_PARSE_NAME)
462 matcher_parsererror("parse error [name]");
468 if (matcher_parse_op == MATCHER_PARSE_CONDITION)
471 matcher_parsererror("parse error [condition]");
475 | filtering_action_list
477 if (matcher_parse_op == MATCHER_PARSE_FILTERING_ACTION)
480 matcher_parsererror("parse error [filtering action]");
499 MATCHER_RULENAME MATCHER_STRING
506 MATCHER_ACCOUNT MATCHER_INTEGER
508 account_id = strtol($2, NULL, 10);
513 filtering_action_list
515 filtering = filteringprop_new(enabled, name, account_id, cond, action_list);
520 if (enable_compatibility) {
521 prefs_filtering = &filtering_rules;
522 if (action_list != NULL) {
523 FilteringAction * first_action;
525 first_action = action_list->data;
527 if (first_action->type == MATCHACTION_CHANGE_SCORE)
528 prefs_filtering = &pre_global_processing;
535 if ((matcher_parse_op == MATCHER_PARSE_FILE) &&
536 (prefs_filtering != NULL)) {
537 *prefs_filtering = g_slist_append(*prefs_filtering,
541 filteringprop_free(filtering);
547 filtering_action_list:
548 filtering_action_b filtering_action_list
555 action_list = g_slist_append(action_list, action);
563 match_type = MATCHTYPE_MATCHCASE;
567 match_type = MATCHTYPE_MATCH;
571 match_type = MATCHTYPE_REGEXPCASE;
575 match_type = MATCHTYPE_REGEXP;
582 cond = matcherlist_new(matchers_list, (bool_op == MATCHERBOOL_AND));
583 matchers_list = NULL;
588 condition_list bool_op one_condition
590 matchers_list = g_slist_append(matchers_list, prop);
594 matchers_list = NULL;
595 matchers_list = g_slist_append(matchers_list, prop);
602 bool_op = MATCHERBOOL_AND;
606 bool_op = MATCHERBOOL_OR;
615 criteria = MATCHCRITERIA_ALL;
616 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
622 criteria = MATCHCRITERIA_UNREAD;
623 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
629 criteria = MATCHCRITERIA_NOT_UNREAD;
630 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
636 criteria = MATCHCRITERIA_NEW;
637 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
643 criteria = MATCHCRITERIA_NOT_NEW;
644 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
650 criteria = MATCHCRITERIA_MARKED;
651 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
657 criteria = MATCHCRITERIA_NOT_MARKED;
658 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
664 criteria = MATCHCRITERIA_DELETED;
665 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
667 | MATCHER_NOT_DELETED
671 criteria = MATCHCRITERIA_NOT_DELETED;
672 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
678 criteria = MATCHCRITERIA_REPLIED;
679 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
681 | MATCHER_NOT_REPLIED
685 criteria = MATCHCRITERIA_NOT_REPLIED;
686 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
692 criteria = MATCHCRITERIA_FORWARDED;
693 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
695 | MATCHER_NOT_FORWARDED
699 criteria = MATCHCRITERIA_NOT_FORWARDED;
700 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
706 criteria = MATCHCRITERIA_LOCKED;
707 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
713 criteria = MATCHCRITERIA_NOT_LOCKED;
714 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
720 criteria = MATCHCRITERIA_SPAM;
721 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
727 criteria = MATCHCRITERIA_NOT_SPAM;
728 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
730 | MATCHER_HAS_ATTACHMENT
734 criteria = MATCHCRITERIA_HAS_ATTACHMENT;
735 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
737 | MATCHER_HAS_NO_ATTACHMENT
741 criteria = MATCHCRITERIA_HAS_NO_ATTACHMENT;
742 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
748 criteria = MATCHCRITERIA_SIGNED;
749 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
755 criteria = MATCHCRITERIA_NOT_SIGNED;
756 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
762 criteria = MATCHCRITERIA_PARTIAL;
763 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
765 | MATCHER_NOT_PARTIAL
769 criteria = MATCHCRITERIA_NOT_PARTIAL;
770 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
772 | MATCHER_COLORLABEL MATCHER_INTEGER
777 criteria = MATCHCRITERIA_COLORLABEL;
778 value = strtol($2, NULL, 10);
779 if (value < 0) value = 0;
780 else if (value > COLORLABELS) value = COLORLABELS;
781 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
783 | MATCHER_NOT_COLORLABEL MATCHER_INTEGER
788 criteria = MATCHCRITERIA_NOT_COLORLABEL;
789 value = strtol($2, NULL, 0);
790 if (value < 0) value = 0;
791 else if (value > COLORLABELS) value = COLORLABELS;
792 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
794 | MATCHER_IGNORE_THREAD
798 criteria = MATCHCRITERIA_IGNORE_THREAD;
799 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
801 | MATCHER_NOT_IGNORE_THREAD
805 criteria = MATCHCRITERIA_NOT_IGNORE_THREAD;
806 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
808 | MATCHER_WATCH_THREAD
812 criteria = MATCHCRITERIA_WATCH_THREAD;
813 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
815 | MATCHER_NOT_WATCH_THREAD
819 criteria = MATCHCRITERIA_NOT_WATCH_THREAD;
820 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
822 | MATCHER_SUBJECT match_type MATCHER_STRING
827 criteria = MATCHCRITERIA_SUBJECT;
829 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
831 | MATCHER_NOT_SUBJECT match_type MATCHER_STRING
836 criteria = MATCHCRITERIA_NOT_SUBJECT;
838 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
840 | MATCHER_FROM match_type MATCHER_STRING
845 criteria = MATCHCRITERIA_FROM;
847 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
849 | MATCHER_NOT_FROM match_type MATCHER_STRING
854 criteria = MATCHCRITERIA_NOT_FROM;
856 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
858 | MATCHER_TO match_type MATCHER_STRING
863 criteria = MATCHCRITERIA_TO;
865 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
867 | MATCHER_NOT_TO match_type MATCHER_STRING
872 criteria = MATCHCRITERIA_NOT_TO;
874 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
876 | MATCHER_CC match_type MATCHER_STRING
881 criteria = MATCHCRITERIA_CC;
883 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
885 | MATCHER_NOT_CC match_type MATCHER_STRING
890 criteria = MATCHCRITERIA_NOT_CC;
892 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
894 | MATCHER_TO_OR_CC match_type MATCHER_STRING
899 criteria = MATCHCRITERIA_TO_OR_CC;
901 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
903 | MATCHER_NOT_TO_AND_NOT_CC match_type MATCHER_STRING
908 criteria = MATCHCRITERIA_NOT_TO_AND_NOT_CC;
910 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
912 | MATCHER_TAG match_type MATCHER_STRING
917 criteria = MATCHCRITERIA_TAG;
919 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
921 | MATCHER_NOT_TAG match_type MATCHER_STRING
926 criteria = MATCHCRITERIA_NOT_TAG;
928 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
934 criteria = MATCHCRITERIA_TAGGED;
935 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
941 criteria = MATCHCRITERIA_NOT_TAGGED;
942 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
944 | MATCHER_AGE_GREATER MATCHER_INTEGER
949 criteria = MATCHCRITERIA_AGE_GREATER;
950 value = strtol($2, NULL, 0);
951 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
953 | MATCHER_AGE_LOWER MATCHER_INTEGER
958 criteria = MATCHCRITERIA_AGE_LOWER;
959 value = strtol($2, NULL, 0);
960 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
962 | MATCHER_AGE_GREATER_HOURS MATCHER_INTEGER
967 criteria = MATCHCRITERIA_AGE_GREATER_HOURS;
968 value = strtol($2, NULL, 0);
969 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
971 | MATCHER_AGE_LOWER_HOURS MATCHER_INTEGER
976 criteria = MATCHCRITERIA_AGE_LOWER_HOURS;
977 value = strtol($2, NULL, 0);
978 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
980 | MATCHER_NEWSGROUPS match_type MATCHER_STRING
985 criteria = MATCHCRITERIA_NEWSGROUPS;
987 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
989 | MATCHER_NOT_NEWSGROUPS match_type MATCHER_STRING
994 criteria = MATCHCRITERIA_NOT_NEWSGROUPS;
996 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
998 | MATCHER_MESSAGEID match_type MATCHER_STRING
1003 criteria = MATCHCRITERIA_MESSAGEID;
1005 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1007 | MATCHER_NOT_MESSAGEID match_type MATCHER_STRING
1012 criteria = MATCHCRITERIA_NOT_MESSAGEID;
1014 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1016 | MATCHER_INREPLYTO match_type MATCHER_STRING
1021 criteria = MATCHCRITERIA_INREPLYTO;
1023 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1025 | MATCHER_NOT_INREPLYTO match_type MATCHER_STRING
1030 criteria = MATCHCRITERIA_NOT_INREPLYTO;
1032 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1034 | MATCHER_REFERENCES match_type MATCHER_STRING
1039 criteria = MATCHCRITERIA_REFERENCES;
1041 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1043 | MATCHER_NOT_REFERENCES match_type MATCHER_STRING
1048 criteria = MATCHCRITERIA_NOT_REFERENCES;
1050 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1052 | MATCHER_SCORE_GREATER MATCHER_INTEGER
1057 criteria = MATCHCRITERIA_SCORE_GREATER;
1058 value = strtol($2, NULL, 0);
1059 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1061 | MATCHER_SCORE_LOWER MATCHER_INTEGER
1066 criteria = MATCHCRITERIA_SCORE_LOWER;
1067 value = strtol($2, NULL, 0);
1068 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1070 | MATCHER_SCORE_EQUAL MATCHER_INTEGER
1075 criteria = MATCHCRITERIA_SCORE_EQUAL;
1076 value = strtol($2, NULL, 0);
1077 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1079 | MATCHER_SIZE_GREATER MATCHER_INTEGER
1083 criteria = MATCHCRITERIA_SIZE_GREATER;
1084 value = strtol($2, NULL, 0);
1085 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1087 | MATCHER_SIZE_SMALLER MATCHER_INTEGER
1091 criteria = MATCHCRITERIA_SIZE_SMALLER;
1092 value = strtol($2, NULL, 0);
1093 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1095 | MATCHER_SIZE_EQUAL MATCHER_INTEGER
1099 criteria = MATCHCRITERIA_SIZE_EQUAL;
1100 value = strtol($2, NULL, 0);
1101 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1103 | MATCHER_HEADER MATCHER_STRING
1105 header = g_strdup($2);
1106 } match_type MATCHER_STRING
1110 matcher_is_fast = FALSE;
1111 criteria = MATCHCRITERIA_HEADER;
1113 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1116 | MATCHER_NOT_HEADER MATCHER_STRING
1118 header = g_strdup($2);
1119 } match_type MATCHER_STRING
1123 matcher_is_fast = FALSE;
1124 criteria = MATCHCRITERIA_NOT_HEADER;
1126 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1129 | MATCHER_HEADERS_PART match_type MATCHER_STRING
1133 matcher_is_fast = FALSE;
1134 criteria = MATCHCRITERIA_HEADERS_PART;
1136 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1138 | MATCHER_NOT_HEADERS_PART match_type MATCHER_STRING
1142 matcher_is_fast = FALSE;
1143 criteria = MATCHCRITERIA_NOT_HEADERS_PART;
1145 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1147 | MATCHER_HEADERS_CONT match_type MATCHER_STRING
1151 matcher_is_fast = FALSE;
1152 criteria = MATCHCRITERIA_HEADERS_CONT;
1154 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1156 | MATCHER_NOT_HEADERS_CONT match_type MATCHER_STRING
1160 matcher_is_fast = FALSE;
1161 criteria = MATCHCRITERIA_NOT_HEADERS_CONT;
1163 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1165 | MATCHER_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1167 header = g_strdup($2);
1168 } MATCHER_IN MATCHER_STRING
1173 criteria = MATCHCRITERIA_FOUND_IN_ADDRESSBOOK;
1175 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1178 | MATCHER_NOT_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1180 header = g_strdup($2);
1181 } MATCHER_IN MATCHER_STRING
1186 criteria = MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK;
1188 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1191 | MATCHER_MESSAGE match_type MATCHER_STRING
1195 matcher_is_fast = FALSE;
1196 criteria = MATCHCRITERIA_MESSAGE;
1198 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1200 | MATCHER_NOT_MESSAGE match_type MATCHER_STRING
1204 matcher_is_fast = FALSE;
1205 criteria = MATCHCRITERIA_NOT_MESSAGE;
1207 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1209 | MATCHER_BODY_PART match_type MATCHER_STRING
1213 matcher_is_fast = FALSE;
1214 criteria = MATCHCRITERIA_BODY_PART;
1216 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1218 | MATCHER_NOT_BODY_PART match_type MATCHER_STRING
1222 matcher_is_fast = FALSE;
1223 criteria = MATCHCRITERIA_NOT_BODY_PART;
1225 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1227 | MATCHER_TEST MATCHER_STRING
1231 matcher_is_fast = FALSE;
1232 criteria = MATCHCRITERIA_TEST;
1234 prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, expr, 0);
1236 | MATCHER_NOT_TEST MATCHER_STRING
1240 matcher_is_fast = FALSE;
1241 criteria = MATCHCRITERIA_NOT_TEST;
1243 prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, expr, 0);
1248 MATCHER_EXECUTE MATCHER_STRING
1251 gint action_type = 0;
1253 action_type = MATCHACTION_EXECUTE;
1255 action = filteringaction_new(action_type, 0, cmd, 0, 0, NULL);
1257 | MATCHER_MOVE MATCHER_STRING
1259 gchar *destination = NULL;
1260 gint action_type = 0;
1262 action_type = MATCHACTION_MOVE;
1264 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1266 | MATCHER_SET_TAG MATCHER_STRING
1268 gchar *destination = NULL;
1269 gint action_type = 0;
1271 action_type = MATCHACTION_SET_TAG;
1273 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1275 | MATCHER_UNSET_TAG MATCHER_STRING
1277 gchar *destination = NULL;
1278 gint action_type = 0;
1280 action_type = MATCHACTION_UNSET_TAG;
1282 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1284 | MATCHER_CLEAR_TAGS
1286 gint action_type = 0;
1288 action_type = MATCHACTION_CLEAR_TAGS;
1289 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1291 | MATCHER_COPY MATCHER_STRING
1293 gchar *destination = NULL;
1294 gint action_type = 0;
1296 action_type = MATCHACTION_COPY;
1298 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1302 gint action_type = 0;
1304 action_type = MATCHACTION_DELETE;
1305 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1309 gint action_type = 0;
1311 action_type = MATCHACTION_MARK;
1312 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1316 gint action_type = 0;
1318 action_type = MATCHACTION_UNMARK;
1319 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1323 gint action_type = 0;
1325 action_type = MATCHACTION_LOCK;
1326 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1330 gint action_type = 0;
1332 action_type = MATCHACTION_UNLOCK;
1333 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1335 | MATCHER_MARK_AS_READ
1337 gint action_type = 0;
1339 action_type = MATCHACTION_MARK_AS_READ;
1340 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1342 | MATCHER_MARK_AS_UNREAD
1344 gint action_type = 0;
1346 action_type = MATCHACTION_MARK_AS_UNREAD;
1347 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1349 | MATCHER_MARK_AS_SPAM
1351 gint action_type = 0;
1353 action_type = MATCHACTION_MARK_AS_SPAM;
1354 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1356 | MATCHER_MARK_AS_HAM
1358 gint action_type = 0;
1360 action_type = MATCHACTION_MARK_AS_HAM;
1361 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1363 | MATCHER_FORWARD MATCHER_INTEGER MATCHER_STRING
1365 gchar *destination = NULL;
1366 gint action_type = 0;
1367 gint account_id = 0;
1369 action_type = MATCHACTION_FORWARD;
1370 account_id = strtol($2, NULL, 10);
1372 action = filteringaction_new(action_type,
1373 account_id, destination, 0, 0, NULL);
1375 | MATCHER_FORWARD_AS_ATTACHMENT MATCHER_INTEGER MATCHER_STRING
1377 gchar *destination = NULL;
1378 gint action_type = 0;
1379 gint account_id = 0;
1381 action_type = MATCHACTION_FORWARD_AS_ATTACHMENT;
1382 account_id = strtol($2, NULL, 10);
1384 action = filteringaction_new(action_type,
1385 account_id, destination, 0, 0, NULL);
1387 | MATCHER_REDIRECT MATCHER_INTEGER MATCHER_STRING
1389 gchar *destination = NULL;
1390 gint action_type = 0;
1391 gint account_id = 0;
1393 action_type = MATCHACTION_REDIRECT;
1394 account_id = strtol($2, NULL, 10);
1396 action = filteringaction_new(action_type,
1397 account_id, destination, 0, 0, NULL);
1399 | MATCHER_COLOR MATCHER_INTEGER
1401 gint action_type = 0;
1404 action_type = MATCHACTION_COLOR;
1405 color = strtol($2, NULL, 10);
1406 action = filteringaction_new(action_type, 0, NULL, color, 0, NULL);
1408 | MATCHER_CHANGE_SCORE MATCHER_INTEGER
1412 score = strtol($2, NULL, 10);
1413 action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1414 NULL, 0, score, NULL);
1416 /* backward compatibility */
1417 | MATCHER_SCORE MATCHER_INTEGER
1421 score = strtol($2, NULL, 10);
1422 action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1423 NULL, 0, score, NULL);
1425 | MATCHER_SET_SCORE MATCHER_INTEGER
1429 score = strtol($2, NULL, 10);
1430 action = filteringaction_new(MATCHACTION_SET_SCORE, 0,
1431 NULL, 0, score, NULL);
1435 action = filteringaction_new(MATCHACTION_HIDE, 0, NULL, 0, 0, NULL);
1439 action = filteringaction_new(MATCHACTION_IGNORE, 0, NULL, 0, 0, NULL);
1443 action = filteringaction_new(MATCHACTION_WATCH, 0, NULL, 0, 0, NULL);
1445 | MATCHER_ADD_TO_ADDRESSBOOK MATCHER_STRING
1447 header = g_strdup($2);
1450 gchar *addressbook = NULL;
1451 gint action_type = 0;
1453 action_type = MATCHACTION_ADD_TO_ADDRESSBOOK;
1455 action = filteringaction_new(action_type, 0, addressbook, 0, 0, header);
1460 action = filteringaction_new(MATCHACTION_STOP, 0, NULL, 0, 0, NULL);