Fix truncated input widgets in preferences window
[claws.git] / src / matcher_parser_parse.y
blobea37c44cacd409949a0d5afd33f9c4ff0076baec
1 %{
2 /*
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/>.
21 #include "defs.h"
23 #include <glib.h>
24 #include <glib/gi18n.h>
26 #include "utils.h"
27 #include "filtering.h"
28 #include "matcher.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;
53 static gboolean filtering_ptr_externally_managed = FALSE;
55 static GSList **prefs_filtering = NULL;
56 static int enable_compatibility = 0;
58 enum {
59 MATCHER_PARSE_FILE,
60 MATCHER_PARSE_NO_EOL,
61 MATCHER_PARSE_ENABLED,
62 MATCHER_PARSE_NAME,
63 MATCHER_PARSE_ACCOUNT,
64 MATCHER_PARSE_CONDITION,
65 MATCHER_PARSE_FILTERING_ACTION,
68 static int matcher_parse_op = MATCHER_PARSE_FILE;
71 /* ******************************************************************** */
72 /* redeclarations to avoid warnings */
73 void matcher_parserrestart(FILE *input_file);
74 void matcher_parser_init(void);
75 void matcher_parser_switch_to_buffer(void * new_buffer);
76 void matcher_parser_delete_buffer(void * b);
77 void matcher_parserpop_buffer_state(void);
78 int matcher_parserlex(void);
80 void matcher_parser_disable_warnings(const gboolean disable)
82 disable_warnings = disable;
85 void matcher_parser_start_parsing(FILE *f)
87 matcher_parserlineno = 1;
88 matcher_parserrestart(f);
89 account_id = 0;
90 matcher_parserparse();
94 void * matcher_parser_scan_string(const char * str);
96 FilteringProp *matcher_parser_get_filtering(gchar *str)
98 void *bufstate;
99 void *tmp_str = NULL;
101 /* little hack to allow passing rules with no names */
102 if (!strncmp(str, "rulename ", 9))
103 tmp_str = g_strdup(str);
104 else
105 tmp_str = g_strconcat("rulename \"\" ", str, NULL);
107 /* bad coding to enable the sub-grammar matching
108 in yacc */
109 matcher_parserlineno = 1;
110 matcher_parse_op = MATCHER_PARSE_NO_EOL;
111 matcher_parserrestart(NULL);
112 matcher_parserpop_buffer_state();
113 matcher_parser_init();
114 bufstate = matcher_parser_scan_string((const char *) tmp_str);
115 matcher_parser_switch_to_buffer(bufstate);
116 /* Indicate that we will be using the global "filtering" pointer,
117 * so that yyparse does not free it in "filtering_action_list"
118 * section. */
119 filtering_ptr_externally_managed = TRUE;
120 if (matcher_parserparse() != 0)
121 filtering = NULL;
122 matcher_parse_op = MATCHER_PARSE_FILE;
123 matcher_parser_delete_buffer(bufstate);
124 g_free(tmp_str);
125 filtering_ptr_externally_managed = FALSE; /* Return to normal. */
126 return filtering;
129 static gboolean check_quote_symetry(gchar *str)
131 const gchar *walk;
132 int ret = 0;
134 if (str == NULL)
135 return TRUE; /* heh, that's symetric */
136 if (*str == '\0')
137 return TRUE;
138 for (walk = str; *walk; walk++) {
139 if (*walk == '\"') {
140 if (walk == str /* first char */
141 || *(walk - 1) != '\\') /* not escaped */
142 ret ++;
145 return !(ret % 2);
148 MatcherList *matcher_parser_get_name(gchar *str)
150 void *bufstate;
152 if (!check_quote_symetry(str)) {
153 cond = NULL;
154 return cond;
157 /* bad coding to enable the sub-grammar matching
158 in yacc */
159 matcher_parserlineno = 1;
160 matcher_parse_op = MATCHER_PARSE_NAME;
161 matcher_parserrestart(NULL);
162 matcher_parserpop_buffer_state();
163 matcher_parser_init();
164 bufstate = matcher_parser_scan_string(str);
165 matcher_parserparse();
166 matcher_parse_op = MATCHER_PARSE_FILE;
167 matcher_parser_delete_buffer(bufstate);
168 return cond;
171 MatcherList *matcher_parser_get_enabled(gchar *str)
173 void *bufstate;
175 if (!check_quote_symetry(str)) {
176 cond = NULL;
177 return cond;
180 /* bad coding to enable the sub-grammar matching
181 in yacc */
182 matcher_parserlineno = 1;
183 matcher_parse_op = MATCHER_PARSE_ENABLED;
184 matcher_parserrestart(NULL);
185 matcher_parserpop_buffer_state();
186 matcher_parser_init();
187 bufstate = matcher_parser_scan_string(str);
188 matcher_parserparse();
189 matcher_parse_op = MATCHER_PARSE_FILE;
190 matcher_parser_delete_buffer(bufstate);
191 return cond;
194 MatcherList *matcher_parser_get_account(gchar *str)
196 void *bufstate;
198 if (!check_quote_symetry(str)) {
199 cond = NULL;
200 return cond;
203 /* bad coding to enable the sub-grammar matching
204 in yacc */
205 matcher_parserlineno = 1;
206 matcher_parse_op = MATCHER_PARSE_ACCOUNT;
207 matcher_parserrestart(NULL);
208 matcher_parserpop_buffer_state();
209 matcher_parser_init();
210 bufstate = matcher_parser_scan_string(str);
211 matcher_parserparse();
212 matcher_parse_op = MATCHER_PARSE_FILE;
213 matcher_parser_delete_buffer(bufstate);
214 return cond;
217 MatcherList *matcher_parser_get_cond(gchar *str, gboolean *is_fast)
219 void *bufstate;
221 if (!check_quote_symetry(str)) {
222 cond = NULL;
223 return cond;
226 matcher_is_fast = TRUE;
227 /* bad coding to enable the sub-grammar matching
228 in yacc */
229 matcher_parserlineno = 1;
230 matcher_parse_op = MATCHER_PARSE_CONDITION;
231 matcher_parserrestart(NULL);
232 matcher_parserpop_buffer_state();
233 matcher_parser_init();
234 bufstate = matcher_parser_scan_string(str);
235 matcher_parserparse();
236 matcher_parse_op = MATCHER_PARSE_FILE;
237 matcher_parser_delete_buffer(bufstate);
238 if (is_fast)
239 *is_fast = matcher_is_fast;
240 return cond;
243 GSList *matcher_parser_get_action_list(gchar *str)
245 void *bufstate;
247 if (!check_quote_symetry(str)) {
248 action_list = NULL;
249 return action_list;
252 /* bad coding to enable the sub-grammar matching
253 in yacc */
254 matcher_parserlineno = 1;
255 matcher_parse_op = MATCHER_PARSE_FILTERING_ACTION;
256 matcher_parserrestart(NULL);
257 matcher_parserpop_buffer_state();
258 matcher_parser_init();
259 bufstate = matcher_parser_scan_string(str);
260 matcher_parserparse();
261 matcher_parse_op = MATCHER_PARSE_FILE;
262 matcher_parser_delete_buffer(bufstate);
263 return action_list;
266 MatcherProp *matcher_parser_get_prop(gchar *str)
268 MatcherList *list;
269 MatcherProp *prop;
271 matcher_parserlineno = 1;
272 list = matcher_parser_get_cond(str, NULL);
273 if (list == NULL)
274 return NULL;
276 if (list->matchers == NULL)
277 return NULL;
279 if (list->matchers->next != NULL)
280 return NULL;
282 prop = list->matchers->data;
284 g_slist_free(list->matchers);
285 g_free(list);
287 return prop;
290 void matcher_parsererror(char *str)
292 GSList *l;
294 if (matchers_list) {
295 for (l = matchers_list; l != NULL; l = g_slist_next(l)) {
296 matcherprop_free((MatcherProp *)
297 l->data);
298 l->data = NULL;
300 g_slist_free(matchers_list);
301 matchers_list = NULL;
303 cond = NULL;
304 if (!disable_warnings)
305 g_warning("filtering parsing: %i: %s",
306 matcher_parserlineno, str);
307 error = 1;
310 int matcher_parserwrap(void)
312 return 1;
316 %union {
317 char *str;
318 int value;
320 %token MATCHER_ALL MATCHER_UNREAD MATCHER_NOT_UNREAD
321 %token MATCHER_NEW MATCHER_NOT_NEW MATCHER_MARKED
322 %token MATCHER_NOT_MARKED MATCHER_DELETED MATCHER_NOT_DELETED
323 %token MATCHER_REPLIED MATCHER_NOT_REPLIED MATCHER_FORWARDED
324 %token MATCHER_NOT_FORWARDED MATCHER_SUBJECT MATCHER_NOT_SUBJECT
325 %token MATCHER_FROM MATCHER_NOT_FROM MATCHER_TO MATCHER_NOT_TO
326 %token MATCHER_CC MATCHER_NOT_CC MATCHER_TO_OR_CC MATCHER_NOT_TO_AND_NOT_CC
327 %token MATCHER_AGE_GREATER MATCHER_AGE_LOWER MATCHER_NEWSGROUPS
328 %token MATCHER_AGE_GREATER_HOURS MATCHER_AGE_LOWER_HOURS
329 %token MATCHER_NOT_NEWSGROUPS MATCHER_INREPLYTO MATCHER_NOT_INREPLYTO
330 %token MATCHER_MESSAGEID MATCHER_NOT_MESSAGEID
331 %token MATCHER_REFERENCES MATCHER_NOT_REFERENCES MATCHER_SCORE_GREATER
332 %token MATCHER_SCORE_LOWER MATCHER_HEADER MATCHER_NOT_HEADER
333 %token MATCHER_HEADERS_PART MATCHER_NOT_HEADERS_PART MATCHER_MESSAGE
334 %token MATCHER_HEADERS_CONT MATCHER_NOT_HEADERS_CONT
335 %token MATCHER_NOT_MESSAGE MATCHER_BODY_PART MATCHER_NOT_BODY_PART
336 %token MATCHER_TEST MATCHER_NOT_TEST MATCHER_MATCHCASE MATCHER_MATCH
337 %token MATCHER_REGEXPCASE MATCHER_REGEXP MATCHER_SCORE MATCHER_MOVE
338 %token MATCHER_FOUND_IN_ADDRESSBOOK MATCHER_NOT_FOUND_IN_ADDRESSBOOK MATCHER_IN
339 %token MATCHER_COPY MATCHER_DELETE MATCHER_MARK MATCHER_UNMARK
340 %token MATCHER_LOCK MATCHER_UNLOCK
341 %token MATCHER_EXECUTE
342 %token MATCHER_MARK_AS_READ MATCHER_MARK_AS_UNREAD MATCHER_FORWARD
343 %token MATCHER_MARK_AS_SPAM MATCHER_MARK_AS_HAM
344 %token MATCHER_FORWARD_AS_ATTACHMENT MATCHER_EOL
345 %token MATCHER_OR MATCHER_AND
346 %token MATCHER_COLOR MATCHER_SCORE_EQUAL MATCHER_REDIRECT
347 %token MATCHER_SIZE_GREATER MATCHER_SIZE_SMALLER MATCHER_SIZE_EQUAL
348 %token MATCHER_LOCKED MATCHER_NOT_LOCKED
349 %token MATCHER_PARTIAL MATCHER_NOT_PARTIAL
350 %token MATCHER_COLORLABEL MATCHER_NOT_COLORLABEL
351 %token MATCHER_IGNORE_THREAD MATCHER_NOT_IGNORE_THREAD
352 %token MATCHER_WATCH_THREAD MATCHER_NOT_WATCH_THREAD
353 %token MATCHER_CHANGE_SCORE MATCHER_SET_SCORE
354 %token MATCHER_ADD_TO_ADDRESSBOOK
355 %token MATCHER_STOP MATCHER_HIDE MATCHER_IGNORE MATCHER_WATCH
356 %token MATCHER_SPAM MATCHER_NOT_SPAM
357 %token MATCHER_HAS_ATTACHMENT MATCHER_HAS_NO_ATTACHMENT
358 %token MATCHER_SIGNED MATCHER_NOT_SIGNED
359 %token MATCHER_TAG MATCHER_NOT_TAG MATCHER_SET_TAG MATCHER_UNSET_TAG
360 %token MATCHER_TAGGED MATCHER_NOT_TAGGED MATCHER_CLEAR_TAGS
362 %start file
364 %token MATCHER_ENABLED MATCHER_DISABLED
365 %token MATCHER_RULENAME
366 %token MATCHER_ACCOUNT
367 %token <str> MATCHER_STRING
368 %token <str> MATCHER_SECTION
369 %token <str> MATCHER_INTEGER
373 file:
375 if (matcher_parse_op == MATCHER_PARSE_FILE) {
376 prefs_filtering = &pre_global_processing;
379 file_line_list;
381 file_line_list:
382 file_line
383 file_line_list
384 | file_line
387 file_line:
388 section_notification
390 { action_list = NULL; }
391 instruction
392 | error MATCHER_EOL
394 yyerrok;
397 section_notification:
398 MATCHER_SECTION MATCHER_EOL
400 gchar *folder = $1;
401 FolderItem *item = NULL;
403 if (matcher_parse_op == MATCHER_PARSE_FILE) {
404 enable_compatibility = 0;
405 if (!strcmp(folder, "global")) {
406 /* backward compatibility */
407 enable_compatibility = 1;
409 else if (!strcmp(folder, "preglobal")) {
410 prefs_filtering = &pre_global_processing;
412 else if (!strcmp(folder, "postglobal")) {
413 prefs_filtering = &post_global_processing;
415 else if (!strcmp(folder, "filtering")) {
416 prefs_filtering = &filtering_rules;
418 else {
419 item = folder_find_item_from_identifier(folder);
420 if (item != NULL) {
421 prefs_filtering = &item->prefs->processing;
422 } else {
423 prefs_filtering = NULL;
430 instruction:
431 enabled name account condition filtering MATCHER_EOL
432 | enabled name account condition filtering
433 | enabled name condition filtering MATCHER_EOL
434 | enabled name condition filtering
435 | name condition filtering MATCHER_EOL
436 | name condition filtering
438 if (matcher_parse_op == MATCHER_PARSE_NO_EOL)
439 YYACCEPT;
440 else {
441 matcher_parsererror("parse error [no eol]");
442 YYERROR;
445 | enabled
447 if (matcher_parse_op == MATCHER_PARSE_ENABLED)
448 YYACCEPT;
449 else {
450 matcher_parsererror("parse error [enabled]");
451 YYERROR;
454 | account
456 if (matcher_parse_op == MATCHER_PARSE_ACCOUNT)
457 YYACCEPT;
458 else {
459 matcher_parsererror("parse error [account]");
460 YYERROR;
463 | name
465 if (matcher_parse_op == MATCHER_PARSE_NAME)
466 YYACCEPT;
467 else {
468 matcher_parsererror("parse error [name]");
469 YYERROR;
472 | condition
474 if (matcher_parse_op == MATCHER_PARSE_CONDITION)
475 YYACCEPT;
476 else {
477 matcher_parsererror("parse error [condition]");
478 YYERROR;
481 | filtering_action_list
483 if (matcher_parse_op == MATCHER_PARSE_FILTERING_ACTION)
484 YYACCEPT;
485 else {
486 matcher_parsererror("parse error [filtering action]");
487 YYERROR;
490 | MATCHER_EOL
493 enabled:
494 MATCHER_ENABLED
496 enabled = TRUE;
498 | MATCHER_DISABLED
500 enabled = FALSE;
504 name:
505 MATCHER_RULENAME MATCHER_STRING
507 name = g_strdup($2);
511 account:
512 MATCHER_ACCOUNT MATCHER_INTEGER
514 account_id = strtol($2, NULL, 10);
518 filtering:
519 filtering_action_list
521 filtering = filteringprop_new(enabled, name, account_id, cond, action_list);
522 enabled = TRUE;
523 account_id = 0;
524 g_free(name);
525 name = NULL;
526 if (enable_compatibility) {
527 prefs_filtering = &filtering_rules;
528 if (action_list != NULL) {
529 FilteringAction * first_action;
531 first_action = action_list->data;
533 if (first_action->type == MATCHACTION_CHANGE_SCORE)
534 prefs_filtering = &pre_global_processing;
538 cond = NULL;
539 action_list = NULL;
541 if ((matcher_parse_op == MATCHER_PARSE_FILE) &&
542 (prefs_filtering != NULL)) {
543 *prefs_filtering = g_slist_append(*prefs_filtering,
544 filtering);
545 filtering = NULL;
546 } else if (!filtering_ptr_externally_managed) {
547 /* If filtering_ptr_externally_managed was TRUE, it
548 * would mean that some function higher in the stack is
549 * interested in the data "filtering" is pointing at, so
550 * we would not free it. That function has to free it itself.
551 * At the time of writing this, the only function that
552 * does this is matcher_parser_get_filtering(). */
553 filteringprop_free(filtering);
554 filtering = NULL;
559 filtering_action_list:
560 filtering_action_b filtering_action_list
561 | filtering_action_b
564 filtering_action_b:
565 filtering_action
567 action_list = g_slist_append(action_list, action);
568 action = NULL;
572 match_type:
573 MATCHER_MATCHCASE
575 match_type = MATCHTYPE_MATCHCASE;
577 | MATCHER_MATCH
579 match_type = MATCHTYPE_MATCH;
581 | MATCHER_REGEXPCASE
583 match_type = MATCHTYPE_REGEXPCASE;
585 | MATCHER_REGEXP
587 match_type = MATCHTYPE_REGEXP;
591 condition:
592 condition_list
594 cond = matcherlist_new(matchers_list, (bool_op == MATCHERBOOL_AND));
595 matchers_list = NULL;
599 condition_list:
600 condition_list bool_op one_condition
602 matchers_list = g_slist_append(matchers_list, prop);
604 | one_condition
606 matchers_list = NULL;
607 matchers_list = g_slist_append(matchers_list, prop);
611 bool_op:
612 MATCHER_AND
614 bool_op = MATCHERBOOL_AND;
616 | MATCHER_OR
618 bool_op = MATCHERBOOL_OR;
622 one_condition:
623 MATCHER_ALL
625 gint criteria = 0;
627 criteria = MATCHCRITERIA_ALL;
628 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
630 | MATCHER_UNREAD
632 gint criteria = 0;
634 criteria = MATCHCRITERIA_UNREAD;
635 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
637 | MATCHER_NOT_UNREAD
639 gint criteria = 0;
641 criteria = MATCHCRITERIA_NOT_UNREAD;
642 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
644 | MATCHER_NEW
646 gint criteria = 0;
648 criteria = MATCHCRITERIA_NEW;
649 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
651 | MATCHER_NOT_NEW
653 gint criteria = 0;
655 criteria = MATCHCRITERIA_NOT_NEW;
656 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
658 | MATCHER_MARKED
660 gint criteria = 0;
662 criteria = MATCHCRITERIA_MARKED;
663 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
665 | MATCHER_NOT_MARKED
667 gint criteria = 0;
669 criteria = MATCHCRITERIA_NOT_MARKED;
670 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
672 | MATCHER_DELETED
674 gint criteria = 0;
676 criteria = MATCHCRITERIA_DELETED;
677 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
679 | MATCHER_NOT_DELETED
681 gint criteria = 0;
683 criteria = MATCHCRITERIA_NOT_DELETED;
684 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
686 | MATCHER_REPLIED
688 gint criteria = 0;
690 criteria = MATCHCRITERIA_REPLIED;
691 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
693 | MATCHER_NOT_REPLIED
695 gint criteria = 0;
697 criteria = MATCHCRITERIA_NOT_REPLIED;
698 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
700 | MATCHER_FORWARDED
702 gint criteria = 0;
704 criteria = MATCHCRITERIA_FORWARDED;
705 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
707 | MATCHER_NOT_FORWARDED
709 gint criteria = 0;
711 criteria = MATCHCRITERIA_NOT_FORWARDED;
712 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
714 | MATCHER_LOCKED
716 gint criteria = 0;
718 criteria = MATCHCRITERIA_LOCKED;
719 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
721 | MATCHER_NOT_LOCKED
723 gint criteria = 0;
725 criteria = MATCHCRITERIA_NOT_LOCKED;
726 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
728 | MATCHER_SPAM
730 gint criteria = 0;
732 criteria = MATCHCRITERIA_SPAM;
733 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
735 | MATCHER_NOT_SPAM
737 gint criteria = 0;
739 criteria = MATCHCRITERIA_NOT_SPAM;
740 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
742 | MATCHER_HAS_ATTACHMENT
744 gint criteria = 0;
746 criteria = MATCHCRITERIA_HAS_ATTACHMENT;
747 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
749 | MATCHER_HAS_NO_ATTACHMENT
751 gint criteria = 0;
753 criteria = MATCHCRITERIA_HAS_NO_ATTACHMENT;
754 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
756 | MATCHER_SIGNED
758 gint criteria = 0;
760 criteria = MATCHCRITERIA_SIGNED;
761 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
763 | MATCHER_NOT_SIGNED
765 gint criteria = 0;
767 criteria = MATCHCRITERIA_NOT_SIGNED;
768 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
770 | MATCHER_PARTIAL
772 gint criteria = 0;
774 criteria = MATCHCRITERIA_PARTIAL;
775 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
777 | MATCHER_NOT_PARTIAL
779 gint criteria = 0;
781 criteria = MATCHCRITERIA_NOT_PARTIAL;
782 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
784 | MATCHER_COLORLABEL MATCHER_INTEGER
786 gint criteria = 0;
787 gint value = 0;
789 criteria = MATCHCRITERIA_COLORLABEL;
790 value = strtol($2, NULL, 10);
791 if (value < 0) value = 0;
792 else if (value > COLORLABELS) value = COLORLABELS;
793 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
795 | MATCHER_NOT_COLORLABEL MATCHER_INTEGER
797 gint criteria = 0;
798 gint value = 0;
800 criteria = MATCHCRITERIA_NOT_COLORLABEL;
801 value = strtol($2, NULL, 0);
802 if (value < 0) value = 0;
803 else if (value > COLORLABELS) value = COLORLABELS;
804 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
806 | MATCHER_IGNORE_THREAD
808 gint criteria = 0;
810 criteria = MATCHCRITERIA_IGNORE_THREAD;
811 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
813 | MATCHER_NOT_IGNORE_THREAD
815 gint criteria = 0;
817 criteria = MATCHCRITERIA_NOT_IGNORE_THREAD;
818 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
820 | MATCHER_WATCH_THREAD
822 gint criteria = 0;
824 criteria = MATCHCRITERIA_WATCH_THREAD;
825 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
827 | MATCHER_NOT_WATCH_THREAD
829 gint criteria = 0;
831 criteria = MATCHCRITERIA_NOT_WATCH_THREAD;
832 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
834 | MATCHER_SUBJECT match_type MATCHER_STRING
836 gint criteria = 0;
837 gchar *expr = NULL;
839 criteria = MATCHCRITERIA_SUBJECT;
840 expr = $3;
841 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
843 | MATCHER_NOT_SUBJECT match_type MATCHER_STRING
845 gint criteria = 0;
846 gchar *expr = NULL;
848 criteria = MATCHCRITERIA_NOT_SUBJECT;
849 expr = $3;
850 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
852 | MATCHER_FROM match_type MATCHER_STRING
854 gint criteria = 0;
855 gchar *expr = NULL;
857 criteria = MATCHCRITERIA_FROM;
858 expr = $3;
859 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
861 | MATCHER_NOT_FROM match_type MATCHER_STRING
863 gint criteria = 0;
864 gchar *expr = NULL;
866 criteria = MATCHCRITERIA_NOT_FROM;
867 expr = $3;
868 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
870 | MATCHER_TO match_type MATCHER_STRING
872 gint criteria = 0;
873 gchar *expr = NULL;
875 criteria = MATCHCRITERIA_TO;
876 expr = $3;
877 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
879 | MATCHER_NOT_TO match_type MATCHER_STRING
881 gint criteria = 0;
882 gchar *expr = NULL;
884 criteria = MATCHCRITERIA_NOT_TO;
885 expr = $3;
886 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
888 | MATCHER_CC match_type MATCHER_STRING
890 gint criteria = 0;
891 gchar *expr = NULL;
893 criteria = MATCHCRITERIA_CC;
894 expr = $3;
895 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
897 | MATCHER_NOT_CC match_type MATCHER_STRING
899 gint criteria = 0;
900 gchar *expr = NULL;
902 criteria = MATCHCRITERIA_NOT_CC;
903 expr = $3;
904 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
906 | MATCHER_TO_OR_CC match_type MATCHER_STRING
908 gint criteria = 0;
909 gchar *expr = NULL;
911 criteria = MATCHCRITERIA_TO_OR_CC;
912 expr = $3;
913 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
915 | MATCHER_NOT_TO_AND_NOT_CC match_type MATCHER_STRING
917 gint criteria = 0;
918 gchar *expr = NULL;
920 criteria = MATCHCRITERIA_NOT_TO_AND_NOT_CC;
921 expr = $3;
922 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
924 | MATCHER_TAG match_type MATCHER_STRING
926 gint criteria = 0;
927 gchar *expr = NULL;
929 criteria = MATCHCRITERIA_TAG;
930 expr = $3;
931 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
933 | MATCHER_NOT_TAG match_type MATCHER_STRING
935 gint criteria = 0;
936 gchar *expr = NULL;
938 criteria = MATCHCRITERIA_NOT_TAG;
939 expr = $3;
940 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
942 | MATCHER_TAGGED
944 gint criteria = 0;
946 criteria = MATCHCRITERIA_TAGGED;
947 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
949 | MATCHER_NOT_TAGGED
951 gint criteria = 0;
953 criteria = MATCHCRITERIA_NOT_TAGGED;
954 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
956 | MATCHER_AGE_GREATER MATCHER_INTEGER
958 gint criteria = 0;
959 gint value = 0;
961 criteria = MATCHCRITERIA_AGE_GREATER;
962 value = strtol($2, NULL, 0);
963 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
965 | MATCHER_AGE_LOWER MATCHER_INTEGER
967 gint criteria = 0;
968 gint value = 0;
970 criteria = MATCHCRITERIA_AGE_LOWER;
971 value = strtol($2, NULL, 0);
972 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
974 | MATCHER_AGE_GREATER_HOURS MATCHER_INTEGER
976 gint criteria = 0;
977 gint value = 0;
979 criteria = MATCHCRITERIA_AGE_GREATER_HOURS;
980 value = strtol($2, NULL, 0);
981 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
983 | MATCHER_AGE_LOWER_HOURS MATCHER_INTEGER
985 gint criteria = 0;
986 gint value = 0;
988 criteria = MATCHCRITERIA_AGE_LOWER_HOURS;
989 value = strtol($2, NULL, 0);
990 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
992 | MATCHER_NEWSGROUPS match_type MATCHER_STRING
994 gint criteria = 0;
995 gchar *expr = NULL;
997 criteria = MATCHCRITERIA_NEWSGROUPS;
998 expr = $3;
999 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1001 | MATCHER_NOT_NEWSGROUPS match_type MATCHER_STRING
1003 gint criteria = 0;
1004 gchar *expr = NULL;
1006 criteria = MATCHCRITERIA_NOT_NEWSGROUPS;
1007 expr = $3;
1008 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1010 | MATCHER_MESSAGEID match_type MATCHER_STRING
1012 gint criteria = 0;
1013 gchar *expr = NULL;
1015 criteria = MATCHCRITERIA_MESSAGEID;
1016 expr = $3;
1017 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1019 | MATCHER_NOT_MESSAGEID match_type MATCHER_STRING
1021 gint criteria = 0;
1022 gchar *expr = NULL;
1024 criteria = MATCHCRITERIA_NOT_MESSAGEID;
1025 expr = $3;
1026 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1028 | MATCHER_INREPLYTO match_type MATCHER_STRING
1030 gint criteria = 0;
1031 gchar *expr = NULL;
1033 criteria = MATCHCRITERIA_INREPLYTO;
1034 expr = $3;
1035 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1037 | MATCHER_NOT_INREPLYTO match_type MATCHER_STRING
1039 gint criteria = 0;
1040 gchar *expr = NULL;
1042 criteria = MATCHCRITERIA_NOT_INREPLYTO;
1043 expr = $3;
1044 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1046 | MATCHER_REFERENCES match_type MATCHER_STRING
1048 gint criteria = 0;
1049 gchar *expr = NULL;
1051 criteria = MATCHCRITERIA_REFERENCES;
1052 expr = $3;
1053 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1055 | MATCHER_NOT_REFERENCES match_type MATCHER_STRING
1057 gint criteria = 0;
1058 gchar *expr = NULL;
1060 criteria = MATCHCRITERIA_NOT_REFERENCES;
1061 expr = $3;
1062 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1064 | MATCHER_SCORE_GREATER MATCHER_INTEGER
1066 gint criteria = 0;
1067 gint value = 0;
1069 criteria = MATCHCRITERIA_SCORE_GREATER;
1070 value = strtol($2, NULL, 0);
1071 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1073 | MATCHER_SCORE_LOWER MATCHER_INTEGER
1075 gint criteria = 0;
1076 gint value = 0;
1078 criteria = MATCHCRITERIA_SCORE_LOWER;
1079 value = strtol($2, NULL, 0);
1080 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1082 | MATCHER_SCORE_EQUAL MATCHER_INTEGER
1084 gint criteria = 0;
1085 gint value = 0;
1087 criteria = MATCHCRITERIA_SCORE_EQUAL;
1088 value = strtol($2, NULL, 0);
1089 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1091 | MATCHER_SIZE_GREATER MATCHER_INTEGER
1093 gint criteria = 0;
1094 gint value = 0;
1095 criteria = MATCHCRITERIA_SIZE_GREATER;
1096 value = strtol($2, NULL, 0);
1097 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1099 | MATCHER_SIZE_SMALLER MATCHER_INTEGER
1101 gint criteria = 0;
1102 gint value = 0;
1103 criteria = MATCHCRITERIA_SIZE_SMALLER;
1104 value = strtol($2, NULL, 0);
1105 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1107 | MATCHER_SIZE_EQUAL MATCHER_INTEGER
1109 gint criteria = 0;
1110 gint value = 0;
1111 criteria = MATCHCRITERIA_SIZE_EQUAL;
1112 value = strtol($2, NULL, 0);
1113 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1115 | MATCHER_HEADER MATCHER_STRING
1117 header = g_strdup($2);
1118 } match_type MATCHER_STRING
1120 gint criteria = 0;
1121 gchar *expr = NULL;
1122 matcher_is_fast = FALSE;
1123 criteria = MATCHCRITERIA_HEADER;
1124 expr = $2;
1125 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1126 g_free(header);
1128 | MATCHER_NOT_HEADER MATCHER_STRING
1130 header = g_strdup($2);
1131 } match_type MATCHER_STRING
1133 gint criteria = 0;
1134 gchar *expr = NULL;
1135 matcher_is_fast = FALSE;
1136 criteria = MATCHCRITERIA_NOT_HEADER;
1137 expr = $2;
1138 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1139 g_free(header);
1141 | MATCHER_HEADERS_PART match_type MATCHER_STRING
1143 gint criteria = 0;
1144 gchar *expr = NULL;
1145 matcher_is_fast = FALSE;
1146 criteria = MATCHCRITERIA_HEADERS_PART;
1147 expr = $3;
1148 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1150 | MATCHER_NOT_HEADERS_PART match_type MATCHER_STRING
1152 gint criteria = 0;
1153 gchar *expr = NULL;
1154 matcher_is_fast = FALSE;
1155 criteria = MATCHCRITERIA_NOT_HEADERS_PART;
1156 expr = $3;
1157 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1159 | MATCHER_HEADERS_CONT match_type MATCHER_STRING
1161 gint criteria = 0;
1162 gchar *expr = NULL;
1163 matcher_is_fast = FALSE;
1164 criteria = MATCHCRITERIA_HEADERS_CONT;
1165 expr = $3;
1166 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1168 | MATCHER_NOT_HEADERS_CONT match_type MATCHER_STRING
1170 gint criteria = 0;
1171 gchar *expr = NULL;
1172 matcher_is_fast = FALSE;
1173 criteria = MATCHCRITERIA_NOT_HEADERS_CONT;
1174 expr = $3;
1175 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1177 | MATCHER_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1179 header = g_strdup($2);
1180 } MATCHER_IN MATCHER_STRING
1182 gint criteria = 0;
1183 gchar *expr = NULL;
1185 criteria = MATCHCRITERIA_FOUND_IN_ADDRESSBOOK;
1186 expr = $2;
1187 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1188 g_free(header);
1190 | MATCHER_NOT_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1192 header = g_strdup($2);
1193 } MATCHER_IN MATCHER_STRING
1195 gint criteria = 0;
1196 gchar *expr = NULL;
1198 criteria = MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK;
1199 expr = $2;
1200 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1201 g_free(header);
1203 | MATCHER_MESSAGE match_type MATCHER_STRING
1205 gint criteria = 0;
1206 gchar *expr = NULL;
1207 matcher_is_fast = FALSE;
1208 criteria = MATCHCRITERIA_MESSAGE;
1209 expr = $3;
1210 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1212 | MATCHER_NOT_MESSAGE match_type MATCHER_STRING
1214 gint criteria = 0;
1215 gchar *expr = NULL;
1216 matcher_is_fast = FALSE;
1217 criteria = MATCHCRITERIA_NOT_MESSAGE;
1218 expr = $3;
1219 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1221 | MATCHER_BODY_PART match_type MATCHER_STRING
1223 gint criteria = 0;
1224 gchar *expr = NULL;
1225 matcher_is_fast = FALSE;
1226 criteria = MATCHCRITERIA_BODY_PART;
1227 expr = $3;
1228 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1230 | MATCHER_NOT_BODY_PART match_type MATCHER_STRING
1232 gint criteria = 0;
1233 gchar *expr = NULL;
1234 matcher_is_fast = FALSE;
1235 criteria = MATCHCRITERIA_NOT_BODY_PART;
1236 expr = $3;
1237 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1239 | MATCHER_TEST MATCHER_STRING
1241 gint criteria = 0;
1242 gchar *expr = NULL;
1243 matcher_is_fast = FALSE;
1244 criteria = MATCHCRITERIA_TEST;
1245 expr = $2;
1246 prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, expr, 0);
1248 | MATCHER_NOT_TEST MATCHER_STRING
1250 gint criteria = 0;
1251 gchar *expr = NULL;
1252 matcher_is_fast = FALSE;
1253 criteria = MATCHCRITERIA_NOT_TEST;
1254 expr = $2;
1255 prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, expr, 0);
1259 filtering_action:
1260 MATCHER_EXECUTE MATCHER_STRING
1262 gchar *cmd = NULL;
1263 gint action_type = 0;
1265 action_type = MATCHACTION_EXECUTE;
1266 cmd = $2;
1267 action = filteringaction_new(action_type, 0, cmd, 0, 0, NULL);
1269 | MATCHER_MOVE MATCHER_STRING
1271 gchar *destination = NULL;
1272 gint action_type = 0;
1274 action_type = MATCHACTION_MOVE;
1275 destination = $2;
1276 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1278 | MATCHER_SET_TAG MATCHER_STRING
1280 gchar *destination = NULL;
1281 gint action_type = 0;
1283 action_type = MATCHACTION_SET_TAG;
1284 destination = $2;
1285 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1287 | MATCHER_UNSET_TAG MATCHER_STRING
1289 gchar *destination = NULL;
1290 gint action_type = 0;
1292 action_type = MATCHACTION_UNSET_TAG;
1293 destination = $2;
1294 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1296 | MATCHER_CLEAR_TAGS
1298 gint action_type = 0;
1300 action_type = MATCHACTION_CLEAR_TAGS;
1301 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1303 | MATCHER_COPY MATCHER_STRING
1305 gchar *destination = NULL;
1306 gint action_type = 0;
1308 action_type = MATCHACTION_COPY;
1309 destination = $2;
1310 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1312 | MATCHER_DELETE
1314 gint action_type = 0;
1316 action_type = MATCHACTION_DELETE;
1317 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1319 | MATCHER_MARK
1321 gint action_type = 0;
1323 action_type = MATCHACTION_MARK;
1324 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1326 | MATCHER_UNMARK
1328 gint action_type = 0;
1330 action_type = MATCHACTION_UNMARK;
1331 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1333 | MATCHER_LOCK
1335 gint action_type = 0;
1337 action_type = MATCHACTION_LOCK;
1338 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1340 | MATCHER_UNLOCK
1342 gint action_type = 0;
1344 action_type = MATCHACTION_UNLOCK;
1345 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1347 | MATCHER_MARK_AS_READ
1349 gint action_type = 0;
1351 action_type = MATCHACTION_MARK_AS_READ;
1352 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1354 | MATCHER_MARK_AS_UNREAD
1356 gint action_type = 0;
1358 action_type = MATCHACTION_MARK_AS_UNREAD;
1359 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1361 | MATCHER_MARK_AS_SPAM
1363 gint action_type = 0;
1365 action_type = MATCHACTION_MARK_AS_SPAM;
1366 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1368 | MATCHER_MARK_AS_HAM
1370 gint action_type = 0;
1372 action_type = MATCHACTION_MARK_AS_HAM;
1373 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1375 | MATCHER_FORWARD MATCHER_INTEGER MATCHER_STRING
1377 gchar *destination = NULL;
1378 gint action_type = 0;
1379 gint account_id = 0;
1381 action_type = MATCHACTION_FORWARD;
1382 account_id = strtol($2, NULL, 10);
1383 destination = $3;
1384 action = filteringaction_new(action_type,
1385 account_id, destination, 0, 0, NULL);
1387 | MATCHER_FORWARD_AS_ATTACHMENT MATCHER_INTEGER MATCHER_STRING
1389 gchar *destination = NULL;
1390 gint action_type = 0;
1391 gint account_id = 0;
1393 action_type = MATCHACTION_FORWARD_AS_ATTACHMENT;
1394 account_id = strtol($2, NULL, 10);
1395 destination = $3;
1396 action = filteringaction_new(action_type,
1397 account_id, destination, 0, 0, NULL);
1399 | MATCHER_REDIRECT MATCHER_INTEGER MATCHER_STRING
1401 gchar *destination = NULL;
1402 gint action_type = 0;
1403 gint account_id = 0;
1405 action_type = MATCHACTION_REDIRECT;
1406 account_id = strtol($2, NULL, 10);
1407 destination = $3;
1408 action = filteringaction_new(action_type,
1409 account_id, destination, 0, 0, NULL);
1411 | MATCHER_COLOR MATCHER_INTEGER
1413 gint action_type = 0;
1414 gint color = 0;
1416 action_type = MATCHACTION_COLOR;
1417 color = strtol($2, NULL, 10);
1418 action = filteringaction_new(action_type, 0, NULL, color, 0, NULL);
1420 | MATCHER_CHANGE_SCORE MATCHER_INTEGER
1422 gint score = 0;
1424 score = strtol($2, NULL, 10);
1425 action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1426 NULL, 0, score, NULL);
1428 /* backward compatibility */
1429 | MATCHER_SCORE MATCHER_INTEGER
1431 gint score = 0;
1433 score = strtol($2, NULL, 10);
1434 action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1435 NULL, 0, score, NULL);
1437 | MATCHER_SET_SCORE MATCHER_INTEGER
1439 gint score = 0;
1441 score = strtol($2, NULL, 10);
1442 action = filteringaction_new(MATCHACTION_SET_SCORE, 0,
1443 NULL, 0, score, NULL);
1445 | MATCHER_HIDE
1447 action = filteringaction_new(MATCHACTION_HIDE, 0, NULL, 0, 0, NULL);
1449 | MATCHER_IGNORE
1451 action = filteringaction_new(MATCHACTION_IGNORE, 0, NULL, 0, 0, NULL);
1453 | MATCHER_WATCH
1455 action = filteringaction_new(MATCHACTION_WATCH, 0, NULL, 0, 0, NULL);
1457 | MATCHER_ADD_TO_ADDRESSBOOK MATCHER_STRING
1459 header = g_strdup($2);
1460 } MATCHER_STRING
1462 gchar *addressbook = NULL;
1463 gint action_type = 0;
1465 action_type = MATCHACTION_ADD_TO_ADDRESSBOOK;
1466 addressbook = $2;
1467 action = filteringaction_new(action_type, 0, addressbook, 0, 0, header);
1468 g_free(header);
1470 | MATCHER_STOP
1472 action = filteringaction_new(MATCHACTION_STOP, 0, NULL, 0, 0, NULL);