Fix bug #3574: Template addressing
[claws.git] / src / matcher_parser_parse.y
blobdd2aee702e0728372d8ffa31f73cfcf20225b860
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;
54 static GSList **prefs_filtering = NULL;
55 static int enable_compatibility = 0;
57 enum {
58 MATCHER_PARSE_FILE,
59 MATCHER_PARSE_NO_EOL,
60 MATCHER_PARSE_ENABLED,
61 MATCHER_PARSE_NAME,
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);
88 account_id = 0;
89 matcher_parserparse();
93 void * matcher_parser_scan_string(const char * str);
95 FilteringProp *matcher_parser_get_filtering(gchar *str)
97 void *bufstate;
98 void *tmp_str = NULL;
100 /* little hack to allow passing rules with no names */
101 if (!strncmp(str, "rulename ", 9))
102 tmp_str = g_strdup(str);
103 else
104 tmp_str = g_strconcat("rulename \"\" ", str, NULL);
106 /* bad coding to enable the sub-grammar matching
107 in yacc */
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)
116 filtering = NULL;
117 matcher_parse_op = MATCHER_PARSE_FILE;
118 matcher_parser_delete_buffer(bufstate);
119 g_free(tmp_str);
120 return filtering;
123 static gboolean check_quote_symetry(gchar *str)
125 const gchar *walk;
126 int ret = 0;
128 if (str == NULL)
129 return TRUE; /* heh, that's symetric */
130 if (*str == '\0')
131 return TRUE;
132 for (walk = str; *walk; walk++) {
133 if (*walk == '\"') {
134 if (walk == str /* first char */
135 || *(walk - 1) != '\\') /* not escaped */
136 ret ++;
139 return !(ret % 2);
142 MatcherList *matcher_parser_get_name(gchar *str)
144 void *bufstate;
146 if (!check_quote_symetry(str)) {
147 cond = NULL;
148 return cond;
151 /* bad coding to enable the sub-grammar matching
152 in yacc */
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);
162 return cond;
165 MatcherList *matcher_parser_get_enabled(gchar *str)
167 void *bufstate;
169 if (!check_quote_symetry(str)) {
170 cond = NULL;
171 return cond;
174 /* bad coding to enable the sub-grammar matching
175 in yacc */
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);
185 return cond;
188 MatcherList *matcher_parser_get_account(gchar *str)
190 void *bufstate;
192 if (!check_quote_symetry(str)) {
193 cond = NULL;
194 return cond;
197 /* bad coding to enable the sub-grammar matching
198 in yacc */
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);
208 return cond;
211 MatcherList *matcher_parser_get_cond(gchar *str, gboolean *is_fast)
213 void *bufstate;
215 if (!check_quote_symetry(str)) {
216 cond = NULL;
217 return cond;
220 matcher_is_fast = TRUE;
221 /* bad coding to enable the sub-grammar matching
222 in yacc */
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);
232 if (is_fast)
233 *is_fast = matcher_is_fast;
234 return cond;
237 GSList *matcher_parser_get_action_list(gchar *str)
239 void *bufstate;
241 if (!check_quote_symetry(str)) {
242 action_list = NULL;
243 return action_list;
246 /* bad coding to enable the sub-grammar matching
247 in yacc */
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);
257 return action_list;
260 MatcherProp *matcher_parser_get_prop(gchar *str)
262 MatcherList *list;
263 MatcherProp *prop;
265 matcher_parserlineno = 1;
266 list = matcher_parser_get_cond(str, NULL);
267 if (list == NULL)
268 return NULL;
270 if (list->matchers == NULL)
271 return NULL;
273 if (list->matchers->next != NULL)
274 return NULL;
276 prop = list->matchers->data;
278 g_slist_free(list->matchers);
279 g_free(list);
281 return prop;
284 void matcher_parsererror(char *str)
286 GSList *l;
288 if (matchers_list) {
289 for (l = matchers_list; l != NULL; l = g_slist_next(l)) {
290 matcherprop_free((MatcherProp *)
291 l->data);
292 l->data = NULL;
294 g_slist_free(matchers_list);
295 matchers_list = NULL;
297 cond = NULL;
298 if (!disable_warnings)
299 g_warning("filtering parsing: %i: %s",
300 matcher_parserlineno, str);
301 error = 1;
304 int matcher_parserwrap(void)
306 return 1;
310 %union {
311 char *str;
312 int value;
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
356 %start file
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
367 file:
369 if (matcher_parse_op == MATCHER_PARSE_FILE) {
370 prefs_filtering = &pre_global_processing;
373 file_line_list;
375 file_line_list:
376 file_line
377 file_line_list
378 | file_line
381 file_line:
382 section_notification
384 { action_list = NULL; }
385 instruction
386 | error MATCHER_EOL
388 yyerrok;
391 section_notification:
392 MATCHER_SECTION MATCHER_EOL
394 gchar *folder = $1;
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;
412 else {
413 item = folder_find_item_from_identifier(folder);
414 if (item != NULL) {
415 prefs_filtering = &item->prefs->processing;
416 } else {
417 prefs_filtering = NULL;
424 instruction:
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)
433 YYACCEPT;
434 else {
435 matcher_parsererror("parse error [no eol]");
436 YYERROR;
439 | enabled
441 if (matcher_parse_op == MATCHER_PARSE_ENABLED)
442 YYACCEPT;
443 else {
444 matcher_parsererror("parse error [enabled]");
445 YYERROR;
448 | account
450 if (matcher_parse_op == MATCHER_PARSE_ACCOUNT)
451 YYACCEPT;
452 else {
453 matcher_parsererror("parse error [account]");
454 YYERROR;
457 | name
459 if (matcher_parse_op == MATCHER_PARSE_NAME)
460 YYACCEPT;
461 else {
462 matcher_parsererror("parse error [name]");
463 YYERROR;
466 | condition
468 if (matcher_parse_op == MATCHER_PARSE_CONDITION)
469 YYACCEPT;
470 else {
471 matcher_parsererror("parse error [condition]");
472 YYERROR;
475 | filtering_action_list
477 if (matcher_parse_op == MATCHER_PARSE_FILTERING_ACTION)
478 YYACCEPT;
479 else {
480 matcher_parsererror("parse error [filtering action]");
481 YYERROR;
484 | MATCHER_EOL
487 enabled:
488 MATCHER_ENABLED
490 enabled = TRUE;
492 | MATCHER_DISABLED
494 enabled = FALSE;
498 name:
499 MATCHER_RULENAME MATCHER_STRING
501 name = g_strdup($2);
505 account:
506 MATCHER_ACCOUNT MATCHER_INTEGER
508 account_id = strtol($2, NULL, 10);
512 filtering:
513 filtering_action_list
515 filtering = filteringprop_new(enabled, name, account_id, cond, action_list);
516 enabled = TRUE;
517 account_id = 0;
518 g_free(name);
519 name = NULL;
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;
532 cond = NULL;
533 action_list = NULL;
535 if ((matcher_parse_op == MATCHER_PARSE_FILE) &&
536 (prefs_filtering != NULL)) {
537 *prefs_filtering = g_slist_append(*prefs_filtering,
538 filtering);
539 filtering = NULL;
544 filtering_action_list:
545 filtering_action_b filtering_action_list
546 | filtering_action_b
549 filtering_action_b:
550 filtering_action
552 action_list = g_slist_append(action_list, action);
553 action = NULL;
557 match_type:
558 MATCHER_MATCHCASE
560 match_type = MATCHTYPE_MATCHCASE;
562 | MATCHER_MATCH
564 match_type = MATCHTYPE_MATCH;
566 | MATCHER_REGEXPCASE
568 match_type = MATCHTYPE_REGEXPCASE;
570 | MATCHER_REGEXP
572 match_type = MATCHTYPE_REGEXP;
576 condition:
577 condition_list
579 cond = matcherlist_new(matchers_list, (bool_op == MATCHERBOOL_AND));
580 matchers_list = NULL;
584 condition_list:
585 condition_list bool_op one_condition
587 matchers_list = g_slist_append(matchers_list, prop);
589 | one_condition
591 matchers_list = NULL;
592 matchers_list = g_slist_append(matchers_list, prop);
596 bool_op:
597 MATCHER_AND
599 bool_op = MATCHERBOOL_AND;
601 | MATCHER_OR
603 bool_op = MATCHERBOOL_OR;
607 one_condition:
608 MATCHER_ALL
610 gint criteria = 0;
612 criteria = MATCHCRITERIA_ALL;
613 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
615 | MATCHER_UNREAD
617 gint criteria = 0;
619 criteria = MATCHCRITERIA_UNREAD;
620 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
622 | MATCHER_NOT_UNREAD
624 gint criteria = 0;
626 criteria = MATCHCRITERIA_NOT_UNREAD;
627 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
629 | MATCHER_NEW
631 gint criteria = 0;
633 criteria = MATCHCRITERIA_NEW;
634 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
636 | MATCHER_NOT_NEW
638 gint criteria = 0;
640 criteria = MATCHCRITERIA_NOT_NEW;
641 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
643 | MATCHER_MARKED
645 gint criteria = 0;
647 criteria = MATCHCRITERIA_MARKED;
648 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
650 | MATCHER_NOT_MARKED
652 gint criteria = 0;
654 criteria = MATCHCRITERIA_NOT_MARKED;
655 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
657 | MATCHER_DELETED
659 gint criteria = 0;
661 criteria = MATCHCRITERIA_DELETED;
662 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
664 | MATCHER_NOT_DELETED
666 gint criteria = 0;
668 criteria = MATCHCRITERIA_NOT_DELETED;
669 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
671 | MATCHER_REPLIED
673 gint criteria = 0;
675 criteria = MATCHCRITERIA_REPLIED;
676 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
678 | MATCHER_NOT_REPLIED
680 gint criteria = 0;
682 criteria = MATCHCRITERIA_NOT_REPLIED;
683 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
685 | MATCHER_FORWARDED
687 gint criteria = 0;
689 criteria = MATCHCRITERIA_FORWARDED;
690 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
692 | MATCHER_NOT_FORWARDED
694 gint criteria = 0;
696 criteria = MATCHCRITERIA_NOT_FORWARDED;
697 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
699 | MATCHER_LOCKED
701 gint criteria = 0;
703 criteria = MATCHCRITERIA_LOCKED;
704 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
706 | MATCHER_NOT_LOCKED
708 gint criteria = 0;
710 criteria = MATCHCRITERIA_NOT_LOCKED;
711 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
713 | MATCHER_SPAM
715 gint criteria = 0;
717 criteria = MATCHCRITERIA_SPAM;
718 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
720 | MATCHER_NOT_SPAM
722 gint criteria = 0;
724 criteria = MATCHCRITERIA_NOT_SPAM;
725 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
727 | MATCHER_HAS_ATTACHMENT
729 gint criteria = 0;
731 criteria = MATCHCRITERIA_HAS_ATTACHMENT;
732 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
734 | MATCHER_HAS_NO_ATTACHMENT
736 gint criteria = 0;
738 criteria = MATCHCRITERIA_HAS_NO_ATTACHMENT;
739 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
741 | MATCHER_SIGNED
743 gint criteria = 0;
745 criteria = MATCHCRITERIA_SIGNED;
746 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
748 | MATCHER_NOT_SIGNED
750 gint criteria = 0;
752 criteria = MATCHCRITERIA_NOT_SIGNED;
753 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
755 | MATCHER_PARTIAL
757 gint criteria = 0;
759 criteria = MATCHCRITERIA_PARTIAL;
760 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
762 | MATCHER_NOT_PARTIAL
764 gint criteria = 0;
766 criteria = MATCHCRITERIA_NOT_PARTIAL;
767 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
769 | MATCHER_COLORLABEL MATCHER_INTEGER
771 gint criteria = 0;
772 gint value = 0;
774 criteria = MATCHCRITERIA_COLORLABEL;
775 value = strtol($2, NULL, 10);
776 if (value < 0) value = 0;
777 else if (value > COLORLABELS) value = COLORLABELS;
778 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
780 | MATCHER_NOT_COLORLABEL MATCHER_INTEGER
782 gint criteria = 0;
783 gint value = 0;
785 criteria = MATCHCRITERIA_NOT_COLORLABEL;
786 value = strtol($2, NULL, 0);
787 if (value < 0) value = 0;
788 else if (value > COLORLABELS) value = COLORLABELS;
789 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
791 | MATCHER_IGNORE_THREAD
793 gint criteria = 0;
795 criteria = MATCHCRITERIA_IGNORE_THREAD;
796 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
798 | MATCHER_NOT_IGNORE_THREAD
800 gint criteria = 0;
802 criteria = MATCHCRITERIA_NOT_IGNORE_THREAD;
803 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
805 | MATCHER_WATCH_THREAD
807 gint criteria = 0;
809 criteria = MATCHCRITERIA_WATCH_THREAD;
810 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
812 | MATCHER_NOT_WATCH_THREAD
814 gint criteria = 0;
816 criteria = MATCHCRITERIA_NOT_WATCH_THREAD;
817 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
819 | MATCHER_SUBJECT match_type MATCHER_STRING
821 gint criteria = 0;
822 gchar *expr = NULL;
824 criteria = MATCHCRITERIA_SUBJECT;
825 expr = $3;
826 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
828 | MATCHER_NOT_SUBJECT match_type MATCHER_STRING
830 gint criteria = 0;
831 gchar *expr = NULL;
833 criteria = MATCHCRITERIA_NOT_SUBJECT;
834 expr = $3;
835 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
837 | MATCHER_FROM match_type MATCHER_STRING
839 gint criteria = 0;
840 gchar *expr = NULL;
842 criteria = MATCHCRITERIA_FROM;
843 expr = $3;
844 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
846 | MATCHER_NOT_FROM match_type MATCHER_STRING
848 gint criteria = 0;
849 gchar *expr = NULL;
851 criteria = MATCHCRITERIA_NOT_FROM;
852 expr = $3;
853 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
855 | MATCHER_TO match_type MATCHER_STRING
857 gint criteria = 0;
858 gchar *expr = NULL;
860 criteria = MATCHCRITERIA_TO;
861 expr = $3;
862 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
864 | MATCHER_NOT_TO match_type MATCHER_STRING
866 gint criteria = 0;
867 gchar *expr = NULL;
869 criteria = MATCHCRITERIA_NOT_TO;
870 expr = $3;
871 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
873 | MATCHER_CC match_type MATCHER_STRING
875 gint criteria = 0;
876 gchar *expr = NULL;
878 criteria = MATCHCRITERIA_CC;
879 expr = $3;
880 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
882 | MATCHER_NOT_CC match_type MATCHER_STRING
884 gint criteria = 0;
885 gchar *expr = NULL;
887 criteria = MATCHCRITERIA_NOT_CC;
888 expr = $3;
889 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
891 | MATCHER_TO_OR_CC match_type MATCHER_STRING
893 gint criteria = 0;
894 gchar *expr = NULL;
896 criteria = MATCHCRITERIA_TO_OR_CC;
897 expr = $3;
898 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
900 | MATCHER_NOT_TO_AND_NOT_CC match_type MATCHER_STRING
902 gint criteria = 0;
903 gchar *expr = NULL;
905 criteria = MATCHCRITERIA_NOT_TO_AND_NOT_CC;
906 expr = $3;
907 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
909 | MATCHER_TAG match_type MATCHER_STRING
911 gint criteria = 0;
912 gchar *expr = NULL;
914 criteria = MATCHCRITERIA_TAG;
915 expr = $3;
916 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
918 | MATCHER_NOT_TAG match_type MATCHER_STRING
920 gint criteria = 0;
921 gchar *expr = NULL;
923 criteria = MATCHCRITERIA_NOT_TAG;
924 expr = $3;
925 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
927 | MATCHER_TAGGED
929 gint criteria = 0;
931 criteria = MATCHCRITERIA_TAGGED;
932 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
934 | MATCHER_NOT_TAGGED
936 gint criteria = 0;
938 criteria = MATCHCRITERIA_NOT_TAGGED;
939 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
941 | MATCHER_AGE_GREATER MATCHER_INTEGER
943 gint criteria = 0;
944 gint value = 0;
946 criteria = MATCHCRITERIA_AGE_GREATER;
947 value = strtol($2, NULL, 0);
948 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
950 | MATCHER_AGE_LOWER MATCHER_INTEGER
952 gint criteria = 0;
953 gint value = 0;
955 criteria = MATCHCRITERIA_AGE_LOWER;
956 value = strtol($2, NULL, 0);
957 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
959 | MATCHER_AGE_GREATER_HOURS MATCHER_INTEGER
961 gint criteria = 0;
962 gint value = 0;
964 criteria = MATCHCRITERIA_AGE_GREATER_HOURS;
965 value = strtol($2, NULL, 0);
966 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
968 | MATCHER_AGE_LOWER_HOURS MATCHER_INTEGER
970 gint criteria = 0;
971 gint value = 0;
973 criteria = MATCHCRITERIA_AGE_LOWER_HOURS;
974 value = strtol($2, NULL, 0);
975 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
977 | MATCHER_NEWSGROUPS match_type MATCHER_STRING
979 gint criteria = 0;
980 gchar *expr = NULL;
982 criteria = MATCHCRITERIA_NEWSGROUPS;
983 expr = $3;
984 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
986 | MATCHER_NOT_NEWSGROUPS match_type MATCHER_STRING
988 gint criteria = 0;
989 gchar *expr = NULL;
991 criteria = MATCHCRITERIA_NOT_NEWSGROUPS;
992 expr = $3;
993 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
995 | MATCHER_MESSAGEID match_type MATCHER_STRING
997 gint criteria = 0;
998 gchar *expr = NULL;
1000 criteria = MATCHCRITERIA_MESSAGEID;
1001 expr = $3;
1002 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1004 | MATCHER_NOT_MESSAGEID match_type MATCHER_STRING
1006 gint criteria = 0;
1007 gchar *expr = NULL;
1009 criteria = MATCHCRITERIA_NOT_MESSAGEID;
1010 expr = $3;
1011 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1013 | MATCHER_INREPLYTO match_type MATCHER_STRING
1015 gint criteria = 0;
1016 gchar *expr = NULL;
1018 criteria = MATCHCRITERIA_INREPLYTO;
1019 expr = $3;
1020 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1022 | MATCHER_NOT_INREPLYTO match_type MATCHER_STRING
1024 gint criteria = 0;
1025 gchar *expr = NULL;
1027 criteria = MATCHCRITERIA_NOT_INREPLYTO;
1028 expr = $3;
1029 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1031 | MATCHER_REFERENCES match_type MATCHER_STRING
1033 gint criteria = 0;
1034 gchar *expr = NULL;
1036 criteria = MATCHCRITERIA_REFERENCES;
1037 expr = $3;
1038 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1040 | MATCHER_NOT_REFERENCES match_type MATCHER_STRING
1042 gint criteria = 0;
1043 gchar *expr = NULL;
1045 criteria = MATCHCRITERIA_NOT_REFERENCES;
1046 expr = $3;
1047 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1049 | MATCHER_SCORE_GREATER MATCHER_INTEGER
1051 gint criteria = 0;
1052 gint value = 0;
1054 criteria = MATCHCRITERIA_SCORE_GREATER;
1055 value = strtol($2, NULL, 0);
1056 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1058 | MATCHER_SCORE_LOWER MATCHER_INTEGER
1060 gint criteria = 0;
1061 gint value = 0;
1063 criteria = MATCHCRITERIA_SCORE_LOWER;
1064 value = strtol($2, NULL, 0);
1065 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1067 | MATCHER_SCORE_EQUAL MATCHER_INTEGER
1069 gint criteria = 0;
1070 gint value = 0;
1072 criteria = MATCHCRITERIA_SCORE_EQUAL;
1073 value = strtol($2, NULL, 0);
1074 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1076 | MATCHER_SIZE_GREATER MATCHER_INTEGER
1078 gint criteria = 0;
1079 gint value = 0;
1080 criteria = MATCHCRITERIA_SIZE_GREATER;
1081 value = strtol($2, NULL, 0);
1082 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1084 | MATCHER_SIZE_SMALLER MATCHER_INTEGER
1086 gint criteria = 0;
1087 gint value = 0;
1088 criteria = MATCHCRITERIA_SIZE_SMALLER;
1089 value = strtol($2, NULL, 0);
1090 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1092 | MATCHER_SIZE_EQUAL MATCHER_INTEGER
1094 gint criteria = 0;
1095 gint value = 0;
1096 criteria = MATCHCRITERIA_SIZE_EQUAL;
1097 value = strtol($2, NULL, 0);
1098 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1100 | MATCHER_HEADER MATCHER_STRING
1102 header = g_strdup($2);
1103 } match_type MATCHER_STRING
1105 gint criteria = 0;
1106 gchar *expr = NULL;
1107 matcher_is_fast = FALSE;
1108 criteria = MATCHCRITERIA_HEADER;
1109 expr = $2;
1110 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1111 g_free(header);
1113 | MATCHER_NOT_HEADER MATCHER_STRING
1115 header = g_strdup($2);
1116 } match_type MATCHER_STRING
1118 gint criteria = 0;
1119 gchar *expr = NULL;
1120 matcher_is_fast = FALSE;
1121 criteria = MATCHCRITERIA_NOT_HEADER;
1122 expr = $2;
1123 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1124 g_free(header);
1126 | MATCHER_HEADERS_PART match_type MATCHER_STRING
1128 gint criteria = 0;
1129 gchar *expr = NULL;
1130 matcher_is_fast = FALSE;
1131 criteria = MATCHCRITERIA_HEADERS_PART;
1132 expr = $3;
1133 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1135 | MATCHER_NOT_HEADERS_PART match_type MATCHER_STRING
1137 gint criteria = 0;
1138 gchar *expr = NULL;
1139 matcher_is_fast = FALSE;
1140 criteria = MATCHCRITERIA_NOT_HEADERS_PART;
1141 expr = $3;
1142 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1144 | MATCHER_HEADERS_CONT match_type MATCHER_STRING
1146 gint criteria = 0;
1147 gchar *expr = NULL;
1148 matcher_is_fast = FALSE;
1149 criteria = MATCHCRITERIA_HEADERS_CONT;
1150 expr = $3;
1151 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1153 | MATCHER_NOT_HEADERS_CONT match_type MATCHER_STRING
1155 gint criteria = 0;
1156 gchar *expr = NULL;
1157 matcher_is_fast = FALSE;
1158 criteria = MATCHCRITERIA_NOT_HEADERS_CONT;
1159 expr = $3;
1160 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1162 | MATCHER_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1164 header = g_strdup($2);
1165 } MATCHER_IN MATCHER_STRING
1167 gint criteria = 0;
1168 gchar *expr = NULL;
1170 criteria = MATCHCRITERIA_FOUND_IN_ADDRESSBOOK;
1171 expr = $2;
1172 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1173 g_free(header);
1175 | MATCHER_NOT_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1177 header = g_strdup($2);
1178 } MATCHER_IN MATCHER_STRING
1180 gint criteria = 0;
1181 gchar *expr = NULL;
1183 criteria = MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK;
1184 expr = $2;
1185 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1186 g_free(header);
1188 | MATCHER_MESSAGE match_type MATCHER_STRING
1190 gint criteria = 0;
1191 gchar *expr = NULL;
1192 matcher_is_fast = FALSE;
1193 criteria = MATCHCRITERIA_MESSAGE;
1194 expr = $3;
1195 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1197 | MATCHER_NOT_MESSAGE match_type MATCHER_STRING
1199 gint criteria = 0;
1200 gchar *expr = NULL;
1201 matcher_is_fast = FALSE;
1202 criteria = MATCHCRITERIA_NOT_MESSAGE;
1203 expr = $3;
1204 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1206 | MATCHER_BODY_PART match_type MATCHER_STRING
1208 gint criteria = 0;
1209 gchar *expr = NULL;
1210 matcher_is_fast = FALSE;
1211 criteria = MATCHCRITERIA_BODY_PART;
1212 expr = $3;
1213 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1215 | MATCHER_NOT_BODY_PART match_type MATCHER_STRING
1217 gint criteria = 0;
1218 gchar *expr = NULL;
1219 matcher_is_fast = FALSE;
1220 criteria = MATCHCRITERIA_NOT_BODY_PART;
1221 expr = $3;
1222 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1224 | MATCHER_TEST MATCHER_STRING
1226 gint criteria = 0;
1227 gchar *expr = NULL;
1228 matcher_is_fast = FALSE;
1229 criteria = MATCHCRITERIA_TEST;
1230 expr = $2;
1231 prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, expr, 0);
1233 | MATCHER_NOT_TEST MATCHER_STRING
1235 gint criteria = 0;
1236 gchar *expr = NULL;
1237 matcher_is_fast = FALSE;
1238 criteria = MATCHCRITERIA_NOT_TEST;
1239 expr = $2;
1240 prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, expr, 0);
1244 filtering_action:
1245 MATCHER_EXECUTE MATCHER_STRING
1247 gchar *cmd = NULL;
1248 gint action_type = 0;
1250 action_type = MATCHACTION_EXECUTE;
1251 cmd = $2;
1252 action = filteringaction_new(action_type, 0, cmd, 0, 0, NULL);
1254 | MATCHER_MOVE MATCHER_STRING
1256 gchar *destination = NULL;
1257 gint action_type = 0;
1259 action_type = MATCHACTION_MOVE;
1260 destination = $2;
1261 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1263 | MATCHER_SET_TAG MATCHER_STRING
1265 gchar *destination = NULL;
1266 gint action_type = 0;
1268 action_type = MATCHACTION_SET_TAG;
1269 destination = $2;
1270 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1272 | MATCHER_UNSET_TAG MATCHER_STRING
1274 gchar *destination = NULL;
1275 gint action_type = 0;
1277 action_type = MATCHACTION_UNSET_TAG;
1278 destination = $2;
1279 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1281 | MATCHER_CLEAR_TAGS
1283 gint action_type = 0;
1285 action_type = MATCHACTION_CLEAR_TAGS;
1286 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1288 | MATCHER_COPY MATCHER_STRING
1290 gchar *destination = NULL;
1291 gint action_type = 0;
1293 action_type = MATCHACTION_COPY;
1294 destination = $2;
1295 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1297 | MATCHER_DELETE
1299 gint action_type = 0;
1301 action_type = MATCHACTION_DELETE;
1302 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1304 | MATCHER_MARK
1306 gint action_type = 0;
1308 action_type = MATCHACTION_MARK;
1309 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1311 | MATCHER_UNMARK
1313 gint action_type = 0;
1315 action_type = MATCHACTION_UNMARK;
1316 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1318 | MATCHER_LOCK
1320 gint action_type = 0;
1322 action_type = MATCHACTION_LOCK;
1323 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1325 | MATCHER_UNLOCK
1327 gint action_type = 0;
1329 action_type = MATCHACTION_UNLOCK;
1330 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1332 | MATCHER_MARK_AS_READ
1334 gint action_type = 0;
1336 action_type = MATCHACTION_MARK_AS_READ;
1337 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1339 | MATCHER_MARK_AS_UNREAD
1341 gint action_type = 0;
1343 action_type = MATCHACTION_MARK_AS_UNREAD;
1344 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1346 | MATCHER_MARK_AS_SPAM
1348 gint action_type = 0;
1350 action_type = MATCHACTION_MARK_AS_SPAM;
1351 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1353 | MATCHER_MARK_AS_HAM
1355 gint action_type = 0;
1357 action_type = MATCHACTION_MARK_AS_HAM;
1358 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1360 | MATCHER_FORWARD MATCHER_INTEGER MATCHER_STRING
1362 gchar *destination = NULL;
1363 gint action_type = 0;
1364 gint account_id = 0;
1366 action_type = MATCHACTION_FORWARD;
1367 account_id = strtol($2, NULL, 10);
1368 destination = $3;
1369 action = filteringaction_new(action_type,
1370 account_id, destination, 0, 0, NULL);
1372 | MATCHER_FORWARD_AS_ATTACHMENT MATCHER_INTEGER MATCHER_STRING
1374 gchar *destination = NULL;
1375 gint action_type = 0;
1376 gint account_id = 0;
1378 action_type = MATCHACTION_FORWARD_AS_ATTACHMENT;
1379 account_id = strtol($2, NULL, 10);
1380 destination = $3;
1381 action = filteringaction_new(action_type,
1382 account_id, destination, 0, 0, NULL);
1384 | MATCHER_REDIRECT MATCHER_INTEGER MATCHER_STRING
1386 gchar *destination = NULL;
1387 gint action_type = 0;
1388 gint account_id = 0;
1390 action_type = MATCHACTION_REDIRECT;
1391 account_id = strtol($2, NULL, 10);
1392 destination = $3;
1393 action = filteringaction_new(action_type,
1394 account_id, destination, 0, 0, NULL);
1396 | MATCHER_COLOR MATCHER_INTEGER
1398 gint action_type = 0;
1399 gint color = 0;
1401 action_type = MATCHACTION_COLOR;
1402 color = strtol($2, NULL, 10);
1403 action = filteringaction_new(action_type, 0, NULL, color, 0, NULL);
1405 | MATCHER_CHANGE_SCORE MATCHER_INTEGER
1407 gint score = 0;
1409 score = strtol($2, NULL, 10);
1410 action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1411 NULL, 0, score, NULL);
1413 /* backward compatibility */
1414 | MATCHER_SCORE MATCHER_INTEGER
1416 gint score = 0;
1418 score = strtol($2, NULL, 10);
1419 action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1420 NULL, 0, score, NULL);
1422 | MATCHER_SET_SCORE MATCHER_INTEGER
1424 gint score = 0;
1426 score = strtol($2, NULL, 10);
1427 action = filteringaction_new(MATCHACTION_SET_SCORE, 0,
1428 NULL, 0, score, NULL);
1430 | MATCHER_HIDE
1432 action = filteringaction_new(MATCHACTION_HIDE, 0, NULL, 0, 0, NULL);
1434 | MATCHER_IGNORE
1436 action = filteringaction_new(MATCHACTION_IGNORE, 0, NULL, 0, 0, NULL);
1438 | MATCHER_WATCH
1440 action = filteringaction_new(MATCHACTION_WATCH, 0, NULL, 0, 0, NULL);
1442 | MATCHER_ADD_TO_ADDRESSBOOK MATCHER_STRING
1444 header = g_strdup($2);
1445 } MATCHER_STRING
1447 gchar *addressbook = NULL;
1448 gint action_type = 0;
1450 action_type = MATCHACTION_ADD_TO_ADDRESSBOOK;
1451 addressbook = $2;
1452 action = filteringaction_new(action_type, 0, addressbook, 0, 0, header);
1453 g_free(header);
1455 | MATCHER_STOP
1457 action = filteringaction_new(MATCHACTION_STOP, 0, NULL, 0, 0, NULL);