Fix build error
[claws.git] / src / matcher_parser_parse.y
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
5  *
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.
10  *
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.
15  *
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/>.
18  * 
19  */
20
21 #include "defs.h"
22
23 #include <glib.h>
24 #include <glib/gi18n.h>
25
26 #include "utils.h"
27 #include "filtering.h"
28 #include "procheader.h"
29 #include "matcher.h"
30 #include "matcher_parser.h"
31 #include "matcher_parser_lex.h"
32 #include "colorlabel.h"
33 #include "folder_item_prefs.h"
34
35 static gint error = 0;
36 static gint bool_op = 0;
37 static gint match_type = 0;
38 static gchar *header = NULL;
39
40 static MatcherProp *prop;
41
42 static GSList *matchers_list = NULL;
43
44 static gboolean enabled = TRUE;
45 static gchar *name = NULL;
46 static gint account_id = 0;
47 static MatcherList *cond;
48 static GSList *action_list = NULL;
49 static FilteringAction *action = NULL;
50 static gboolean matcher_is_fast = TRUE;
51 static gboolean disable_warnings = FALSE;
52
53 static FilteringProp *filtering;
54 static gboolean filtering_ptr_externally_managed = FALSE;
55
56 static GSList **prefs_filtering = NULL;
57 static int enable_compatibility = 0;
58
59 enum {
60         MATCHER_PARSE_FILE,
61         MATCHER_PARSE_NO_EOL,
62         MATCHER_PARSE_ENABLED,
63         MATCHER_PARSE_NAME,
64         MATCHER_PARSE_ACCOUNT,
65         MATCHER_PARSE_CONDITION,
66         MATCHER_PARSE_FILTERING_ACTION,
67 };
68
69 static int matcher_parse_op = MATCHER_PARSE_FILE;
70
71
72 /* ******************************************************************** */
73 /* redeclarations to avoid warnings */
74 void matcher_parserrestart(FILE *input_file);
75 void matcher_parser_init(void);
76 void matcher_parser_switch_to_buffer(void * new_buffer);
77 void matcher_parser_delete_buffer(void * b);
78 void matcher_parserpop_buffer_state(void);
79 int matcher_parserlex(void);
80
81 void matcher_parser_disable_warnings(const gboolean disable)
82 {
83         disable_warnings = disable;
84 }
85
86 void matcher_parser_start_parsing(FILE *f)
87 {
88         matcher_parserlineno = 1;
89         matcher_parserrestart(f);
90         account_id = 0;
91         matcher_parserparse();
92 }
93
94  
95 void * matcher_parser_scan_string(const char * str);
96  
97 FilteringProp *matcher_parser_get_filtering(gchar *str)
98 {
99         void *bufstate;
100         void *tmp_str = NULL;
101         
102         /* little hack to allow passing rules with no names */
103         if (!strncmp(str, "rulename ", 9))
104                 tmp_str = g_strdup(str);
105         else 
106                 tmp_str = g_strconcat("rulename \"\" ", str, NULL);
107
108         /* bad coding to enable the sub-grammar matching
109            in yacc */
110         matcher_parserlineno = 1;
111         matcher_parse_op = MATCHER_PARSE_NO_EOL;
112         matcher_parserrestart(NULL);
113         matcher_parserpop_buffer_state();
114         matcher_parser_init();
115         bufstate = matcher_parser_scan_string((const char *) tmp_str);
116         matcher_parser_switch_to_buffer(bufstate);
117         /* Indicate that we will be using the global "filtering" pointer,
118          * so that yyparse does not free it in "filtering_action_list"
119          * section. */
120         filtering_ptr_externally_managed = TRUE;
121         if (matcher_parserparse() != 0)
122                 filtering = NULL;
123         matcher_parse_op = MATCHER_PARSE_FILE;
124         matcher_parser_delete_buffer(bufstate);
125         g_free(tmp_str);
126         filtering_ptr_externally_managed = FALSE; /* Return to normal. */
127         return filtering;
128 }
129
130 static gboolean check_quote_symetry(gchar *str)
131 {
132         const gchar *walk;
133         int ret = 0;
134         
135         if (str == NULL)
136                 return TRUE; /* heh, that's symetric */
137         if (*str == '\0')
138                 return TRUE;
139         for (walk = str; *walk; walk++) {
140                 if (*walk == '\"') {
141                         if (walk == str         /* first char */
142                         || *(walk - 1) != '\\') /* not escaped */
143                                 ret ++;
144                 }
145         }
146         return !(ret % 2);
147 }
148
149 MatcherList *matcher_parser_get_name(gchar *str)
150 {
151         void *bufstate;
152
153         if (!check_quote_symetry(str)) {
154                 cond = NULL;
155                 return cond;
156         }
157         
158         /* bad coding to enable the sub-grammar matching
159            in yacc */
160         matcher_parserlineno = 1;
161         matcher_parse_op = MATCHER_PARSE_NAME;
162         matcher_parserrestart(NULL);
163         matcher_parserpop_buffer_state();
164         matcher_parser_init();
165         bufstate = matcher_parser_scan_string(str);
166         matcher_parserparse();
167         matcher_parse_op = MATCHER_PARSE_FILE;
168         matcher_parser_delete_buffer(bufstate);
169         return cond;
170 }
171
172 MatcherList *matcher_parser_get_enabled(gchar *str)
173 {
174         void *bufstate;
175
176         if (!check_quote_symetry(str)) {
177                 cond = NULL;
178                 return cond;
179         }
180         
181         /* bad coding to enable the sub-grammar matching
182            in yacc */
183         matcher_parserlineno = 1;
184         matcher_parse_op = MATCHER_PARSE_ENABLED;
185         matcher_parserrestart(NULL);
186         matcher_parserpop_buffer_state();
187         matcher_parser_init();
188         bufstate = matcher_parser_scan_string(str);
189         matcher_parserparse();
190         matcher_parse_op = MATCHER_PARSE_FILE;
191         matcher_parser_delete_buffer(bufstate);
192         return cond;
193 }
194
195 MatcherList *matcher_parser_get_account(gchar *str)
196 {
197         void *bufstate;
198
199         if (!check_quote_symetry(str)) {
200                 cond = NULL;
201                 return cond;
202         }
203         
204         /* bad coding to enable the sub-grammar matching
205            in yacc */
206         matcher_parserlineno = 1;
207         matcher_parse_op = MATCHER_PARSE_ACCOUNT;
208         matcher_parserrestart(NULL);
209         matcher_parserpop_buffer_state();
210         matcher_parser_init();
211         bufstate = matcher_parser_scan_string(str);
212         matcher_parserparse();
213         matcher_parse_op = MATCHER_PARSE_FILE;
214         matcher_parser_delete_buffer(bufstate);
215         return cond;
216 }
217
218 MatcherList *matcher_parser_get_cond(gchar *str, gboolean *is_fast)
219 {
220         void *bufstate;
221
222         if (!check_quote_symetry(str)) {
223                 cond = NULL;
224                 return cond;
225         }
226         
227         matcher_is_fast = TRUE;
228         /* bad coding to enable the sub-grammar matching
229            in yacc */
230         matcher_parserlineno = 1;
231         matcher_parse_op = MATCHER_PARSE_CONDITION;
232         matcher_parserrestart(NULL);
233         matcher_parserpop_buffer_state();
234         matcher_parser_init();
235         bufstate = matcher_parser_scan_string(str);
236         matcher_parserparse();
237         matcher_parse_op = MATCHER_PARSE_FILE;
238         matcher_parser_delete_buffer(bufstate);
239         if (is_fast)
240                 *is_fast = matcher_is_fast;
241         return cond;
242 }
243
244 GSList *matcher_parser_get_action_list(gchar *str)
245 {
246         void *bufstate;
247
248         if (!check_quote_symetry(str)) {
249                 action_list = NULL;
250                 return action_list;
251         }
252         
253         /* bad coding to enable the sub-grammar matching
254            in yacc */
255         matcher_parserlineno = 1;
256         matcher_parse_op = MATCHER_PARSE_FILTERING_ACTION;
257         matcher_parserrestart(NULL);
258         matcher_parserpop_buffer_state();
259         matcher_parser_init();
260         bufstate = matcher_parser_scan_string(str);
261         matcher_parserparse();
262         matcher_parse_op = MATCHER_PARSE_FILE;
263         matcher_parser_delete_buffer(bufstate);
264         return action_list;
265 }
266
267 MatcherProp *matcher_parser_get_prop(gchar *str)
268 {
269         MatcherList *list;
270         MatcherProp *prop;
271
272         matcher_parserlineno = 1;
273         list = matcher_parser_get_cond(str, NULL);
274         if (list == NULL)
275                 return NULL;
276
277         if (list->matchers == NULL)
278                 return NULL;
279
280         if (list->matchers->next != NULL)
281                 return NULL;
282
283         prop = list->matchers->data;
284
285         g_slist_free(list->matchers);
286         g_free(list);
287
288         return prop;
289 }
290
291 void matcher_parsererror(char *str)
292 {
293         GSList *l;
294
295         if (matchers_list) {
296                 for (l = matchers_list; l != NULL; l = g_slist_next(l)) {
297                         matcherprop_free((MatcherProp *)
298                                          l->data);
299                         l->data = NULL;
300                 }
301                 g_slist_free(matchers_list);
302                 matchers_list = NULL;
303         }
304         cond = NULL;
305         if (!disable_warnings)
306                 g_warning("filtering parsing: %i: %s",
307                         matcher_parserlineno, str);
308         error = 1;
309 }
310
311 int matcher_parserwrap(void)
312 {
313         return 1;
314 }
315 %}
316
317 %union {
318         char *str;
319         int value;
320 }
321 %token MATCHER_ALL MATCHER_UNREAD  MATCHER_NOT_UNREAD 
322 %token MATCHER_NEW  MATCHER_NOT_NEW  MATCHER_MARKED
323 %token MATCHER_NOT_MARKED  MATCHER_DELETED  MATCHER_NOT_DELETED
324 %token MATCHER_REPLIED  MATCHER_NOT_REPLIED  MATCHER_FORWARDED
325 %token MATCHER_NOT_FORWARDED  MATCHER_SUBJECT  MATCHER_NOT_SUBJECT
326 %token MATCHER_FROM  MATCHER_NOT_FROM  MATCHER_TO  MATCHER_NOT_TO
327 %token MATCHER_CC  MATCHER_NOT_CC  MATCHER_TO_OR_CC  MATCHER_NOT_TO_AND_NOT_CC
328 %token MATCHER_AGE_GREATER  MATCHER_AGE_LOWER  MATCHER_NEWSGROUPS
329 %token MATCHER_AGE_GREATER_HOURS  MATCHER_AGE_LOWER_HOURS
330 %token MATCHER_DATE_AFTER  MATCHER_DATE_BEFORE
331 %token MATCHER_NOT_NEWSGROUPS  MATCHER_INREPLYTO  MATCHER_NOT_INREPLYTO
332 %token MATCHER_MESSAGEID MATCHER_NOT_MESSAGEID
333 %token MATCHER_REFERENCES  MATCHER_NOT_REFERENCES  MATCHER_SCORE_GREATER
334 %token MATCHER_SCORE_LOWER  MATCHER_HEADER  MATCHER_NOT_HEADER
335 %token MATCHER_HEADERS_PART  MATCHER_NOT_HEADERS_PART  MATCHER_MESSAGE
336 %token MATCHER_HEADERS_CONT  MATCHER_NOT_HEADERS_CONT
337 %token MATCHER_NOT_MESSAGE  MATCHER_BODY_PART  MATCHER_NOT_BODY_PART
338 %token MATCHER_TEST  MATCHER_NOT_TEST  MATCHER_MATCHCASE  MATCHER_MATCH
339 %token MATCHER_REGEXPCASE  MATCHER_REGEXP  MATCHER_SCORE  MATCHER_MOVE
340 %token MATCHER_FOUND_IN_ADDRESSBOOK MATCHER_NOT_FOUND_IN_ADDRESSBOOK MATCHER_IN
341 %token MATCHER_COPY  MATCHER_DELETE  MATCHER_MARK  MATCHER_UNMARK
342 %token MATCHER_LOCK MATCHER_UNLOCK
343 %token MATCHER_EXECUTE
344 %token MATCHER_MARK_AS_READ  MATCHER_MARK_AS_UNREAD  MATCHER_FORWARD
345 %token MATCHER_MARK_AS_SPAM MATCHER_MARK_AS_HAM
346 %token MATCHER_FORWARD_AS_ATTACHMENT  MATCHER_EOL
347 %token MATCHER_OR MATCHER_AND  
348 %token MATCHER_COLOR MATCHER_SCORE_EQUAL MATCHER_REDIRECT 
349 %token MATCHER_SIZE_GREATER MATCHER_SIZE_SMALLER MATCHER_SIZE_EQUAL
350 %token MATCHER_LOCKED MATCHER_NOT_LOCKED
351 %token MATCHER_PARTIAL MATCHER_NOT_PARTIAL
352 %token MATCHER_COLORLABEL MATCHER_NOT_COLORLABEL
353 %token MATCHER_IGNORE_THREAD MATCHER_NOT_IGNORE_THREAD
354 %token MATCHER_WATCH_THREAD MATCHER_NOT_WATCH_THREAD
355 %token MATCHER_CHANGE_SCORE MATCHER_SET_SCORE
356 %token MATCHER_ADD_TO_ADDRESSBOOK
357 %token MATCHER_STOP MATCHER_HIDE MATCHER_IGNORE MATCHER_WATCH
358 %token MATCHER_SPAM MATCHER_NOT_SPAM
359 %token MATCHER_HAS_ATTACHMENT MATCHER_HAS_NO_ATTACHMENT
360 %token MATCHER_SIGNED MATCHER_NOT_SIGNED
361 %token MATCHER_TAG MATCHER_NOT_TAG MATCHER_SET_TAG MATCHER_UNSET_TAG
362 %token MATCHER_TAGGED MATCHER_NOT_TAGGED MATCHER_CLEAR_TAGS
363
364 %start file
365
366 %token MATCHER_ENABLED MATCHER_DISABLED
367 %token MATCHER_RULENAME
368 %token MATCHER_ACCOUNT
369 %token <str> MATCHER_STRING
370 %token <str> MATCHER_SECTION
371 %token <str> MATCHER_INTEGER
372
373 %%
374
375 file:
376 {
377         if (matcher_parse_op == MATCHER_PARSE_FILE) {
378                 prefs_filtering = &pre_global_processing;
379         }
380 }
381 file_line_list;
382
383 file_line_list:
384 file_line
385 file_line_list
386 | file_line
387 ;
388
389 file_line:
390 section_notification
391
392 { action_list = NULL; }
393 instruction
394 | error MATCHER_EOL
395 {
396         yyerrok;
397 };
398
399 section_notification:
400 MATCHER_SECTION MATCHER_EOL
401 {
402         gchar *folder = $1;
403         FolderItem *item = NULL;
404
405         if (matcher_parse_op == MATCHER_PARSE_FILE) {
406                 enable_compatibility = 0;
407                 if (!strcmp(folder, "global")) {
408                         /* backward compatibility */
409                         enable_compatibility = 1;
410                 }
411                 else if (!strcmp(folder, "preglobal")) {
412                         prefs_filtering = &pre_global_processing;
413                 }
414                 else if (!strcmp(folder, "postglobal")) {
415                         prefs_filtering = &post_global_processing;
416                 }
417                 else if (!strcmp(folder, "filtering")) {
418                         prefs_filtering = &filtering_rules;
419                 }
420                 else {
421                         item = folder_find_item_from_identifier(folder);
422                         if (item != NULL) {
423                                 prefs_filtering = &item->prefs->processing;
424                         } else {
425                                 prefs_filtering = NULL;
426                         }
427                 }
428         }
429 }
430 ;
431
432 instruction:
433 enabled name account condition filtering MATCHER_EOL
434 | enabled name account condition filtering
435 | enabled name condition filtering MATCHER_EOL
436 | enabled name condition filtering
437 | name condition filtering MATCHER_EOL
438 | name condition filtering
439 {
440         if (matcher_parse_op == MATCHER_PARSE_NO_EOL)
441                 YYACCEPT;
442         else {
443                 matcher_parsererror("parse error [no eol]");
444                 YYERROR;
445         }
446 }
447 | enabled
448 {
449         if (matcher_parse_op == MATCHER_PARSE_ENABLED)
450                 YYACCEPT;
451         else {
452                 matcher_parsererror("parse error [enabled]");
453                 YYERROR;
454         }
455 }
456 | account
457 {
458         if (matcher_parse_op == MATCHER_PARSE_ACCOUNT)
459                 YYACCEPT;
460         else {
461                 matcher_parsererror("parse error [account]");
462                 YYERROR;
463         }
464 }
465 | name
466 {
467         if (matcher_parse_op == MATCHER_PARSE_NAME)
468                 YYACCEPT;
469         else {
470                 matcher_parsererror("parse error [name]");
471                 YYERROR;
472         }
473 }
474 | condition
475 {
476         if (matcher_parse_op == MATCHER_PARSE_CONDITION)
477                 YYACCEPT;
478         else {
479                 matcher_parsererror("parse error [condition]");
480                 YYERROR;
481         }
482 }
483 | filtering_action_list
484 {
485         if (matcher_parse_op == MATCHER_PARSE_FILTERING_ACTION)
486                 YYACCEPT;
487         else {
488                 matcher_parsererror("parse error [filtering action]");
489                 YYERROR;
490         }
491 }
492 | MATCHER_EOL
493 ;
494
495 enabled:
496 MATCHER_ENABLED
497 {
498         enabled = TRUE;
499 }
500 | MATCHER_DISABLED
501 {
502         enabled = FALSE;
503 }
504 ;
505
506 name:
507 MATCHER_RULENAME MATCHER_STRING
508 {
509         name = g_strdup($2);
510 }
511 ;
512
513 account:
514 MATCHER_ACCOUNT MATCHER_INTEGER
515 {
516         account_id = strtol($2, NULL, 10);
517 }
518 ;
519
520 filtering:
521 filtering_action_list
522 {
523         filtering = filteringprop_new(enabled, name, account_id, cond, action_list);
524         enabled = TRUE;
525         account_id = 0;
526         g_free(name);
527         name = NULL;
528         if (enable_compatibility) {
529                 prefs_filtering = &filtering_rules;
530                 if (action_list != NULL) {
531                         FilteringAction * first_action;
532                         
533                         first_action = action_list->data;
534                         
535                         if (first_action->type == MATCHACTION_CHANGE_SCORE)
536                                 prefs_filtering = &pre_global_processing;
537                 }
538         }
539         
540         cond = NULL;
541         action_list = NULL;
542         
543         if ((matcher_parse_op == MATCHER_PARSE_FILE) &&
544             (prefs_filtering != NULL)) {
545                 *prefs_filtering = g_slist_append(*prefs_filtering,
546                                                   filtering);
547                 filtering = NULL;
548         } else if (!filtering_ptr_externally_managed) {
549                 /* If filtering_ptr_externally_managed was TRUE, it
550                  * would mean that some function higher in the stack is
551                  * interested in the data "filtering" is pointing at, so
552                  * we would not free it. That function has to free it itself.
553                  * At the time of writing this, the only function that
554                  * does this is matcher_parser_get_filtering(). */
555                 filteringprop_free(filtering);
556                 filtering = NULL;
557         }
558 }
559 ;
560
561 filtering_action_list:
562 filtering_action_b filtering_action_list
563 | filtering_action_b
564 ;
565
566 filtering_action_b:
567 filtering_action
568 {
569         action_list = g_slist_append(action_list, action);
570         action = NULL;
571 }
572 ;
573
574 match_type:
575 MATCHER_MATCHCASE
576 {
577         match_type = MATCHTYPE_MATCHCASE;
578 }
579 | MATCHER_MATCH
580 {
581         match_type = MATCHTYPE_MATCH;
582 }
583 | MATCHER_REGEXPCASE
584 {
585         match_type = MATCHTYPE_REGEXPCASE;
586 }
587 | MATCHER_REGEXP
588 {
589         match_type = MATCHTYPE_REGEXP;
590 }
591 ;
592
593 condition:
594 condition_list
595 {
596         cond = matcherlist_new(matchers_list, (bool_op == MATCHERBOOL_AND));
597         matchers_list = NULL;
598 }
599 ;
600
601 condition_list:
602 condition_list bool_op one_condition
603 {
604         matchers_list = g_slist_append(matchers_list, prop);
605 }
606 | one_condition
607 {
608         matchers_list = NULL;
609         matchers_list = g_slist_append(matchers_list, prop);
610 }
611 ;
612
613 bool_op:
614 MATCHER_AND
615 {
616         bool_op = MATCHERBOOL_AND;
617 }
618 | MATCHER_OR
619 {
620         bool_op = MATCHERBOOL_OR;
621 }
622 ;
623
624 one_condition:
625 MATCHER_ALL
626 {
627         gint criteria = 0;
628
629         criteria = MATCHCRITERIA_ALL;
630         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
631 }
632 | MATCHER_UNREAD
633 {
634         gint criteria = 0;
635
636         criteria = MATCHCRITERIA_UNREAD;
637         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
638 }
639 | MATCHER_NOT_UNREAD 
640 {
641         gint criteria = 0;
642
643         criteria = MATCHCRITERIA_NOT_UNREAD;
644         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
645 }
646 | MATCHER_NEW
647 {
648         gint criteria = 0;
649
650         criteria = MATCHCRITERIA_NEW;
651         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
652 }
653 | MATCHER_NOT_NEW
654 {
655         gint criteria = 0;
656
657         criteria = MATCHCRITERIA_NOT_NEW;
658         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
659 }
660 | MATCHER_MARKED
661 {
662         gint criteria = 0;
663
664         criteria = MATCHCRITERIA_MARKED;
665         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
666 }
667 | MATCHER_NOT_MARKED
668 {
669         gint criteria = 0;
670
671         criteria = MATCHCRITERIA_NOT_MARKED;
672         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
673 }
674 | MATCHER_DELETED
675 {
676         gint criteria = 0;
677
678         criteria = MATCHCRITERIA_DELETED;
679         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
680 }
681 | MATCHER_NOT_DELETED
682 {
683         gint criteria = 0;
684
685         criteria = MATCHCRITERIA_NOT_DELETED;
686         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
687 }
688 | MATCHER_REPLIED
689 {
690         gint criteria = 0;
691
692         criteria = MATCHCRITERIA_REPLIED;
693         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
694 }
695 | MATCHER_NOT_REPLIED
696 {
697         gint criteria = 0;
698
699         criteria = MATCHCRITERIA_NOT_REPLIED;
700         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
701 }
702 | MATCHER_FORWARDED
703 {
704         gint criteria = 0;
705
706         criteria = MATCHCRITERIA_FORWARDED;
707         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
708 }
709 | MATCHER_NOT_FORWARDED
710 {
711         gint criteria = 0;
712
713         criteria = MATCHCRITERIA_NOT_FORWARDED;
714         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
715 }
716 | MATCHER_LOCKED
717 {
718         gint criteria = 0;
719
720         criteria = MATCHCRITERIA_LOCKED;
721         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
722 }
723 | MATCHER_NOT_LOCKED
724 {
725         gint criteria = 0;
726
727         criteria = MATCHCRITERIA_NOT_LOCKED;
728         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
729 }
730 | MATCHER_SPAM
731 {
732         gint criteria = 0;
733
734         criteria = MATCHCRITERIA_SPAM;
735         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
736 }
737 | MATCHER_NOT_SPAM 
738 {
739         gint criteria = 0;
740
741         criteria = MATCHCRITERIA_NOT_SPAM;
742         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
743 }
744 | MATCHER_HAS_ATTACHMENT
745 {
746         gint criteria = 0;
747
748         criteria = MATCHCRITERIA_HAS_ATTACHMENT;
749         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
750 }
751 | MATCHER_HAS_NO_ATTACHMENT
752 {
753         gint criteria = 0;
754
755         criteria = MATCHCRITERIA_HAS_NO_ATTACHMENT;
756         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
757 }
758 | MATCHER_SIGNED
759 {
760         gint criteria = 0;
761
762         criteria = MATCHCRITERIA_SIGNED;
763         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
764 }
765 | MATCHER_NOT_SIGNED
766 {
767         gint criteria = 0;
768
769         criteria = MATCHCRITERIA_NOT_SIGNED;
770         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
771 }
772 | MATCHER_PARTIAL
773 {
774         gint criteria = 0;
775
776         criteria = MATCHCRITERIA_PARTIAL;
777         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
778 }
779 | MATCHER_NOT_PARTIAL
780 {
781         gint criteria = 0;
782
783         criteria = MATCHCRITERIA_NOT_PARTIAL;
784         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
785 }
786 | MATCHER_COLORLABEL MATCHER_INTEGER
787 {
788         gint criteria = 0;
789         gint value = 0;
790
791         criteria = MATCHCRITERIA_COLORLABEL;
792         value = strtol($2, NULL, 10);
793         if (value < 0) value = 0;
794         else if (value > COLORLABELS) value = COLORLABELS;
795         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
796 }
797 | MATCHER_NOT_COLORLABEL MATCHER_INTEGER
798 {
799         gint criteria = 0;
800         gint value = 0;
801
802         criteria = MATCHCRITERIA_NOT_COLORLABEL;
803         value = strtol($2, NULL, 0);
804         if (value < 0) value = 0;
805         else if (value > COLORLABELS) value = COLORLABELS;
806         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
807 }
808 | MATCHER_IGNORE_THREAD
809 {
810         gint criteria = 0;
811
812         criteria = MATCHCRITERIA_IGNORE_THREAD;
813         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
814 }
815 | MATCHER_NOT_IGNORE_THREAD
816 {
817         gint criteria = 0;
818
819         criteria = MATCHCRITERIA_NOT_IGNORE_THREAD;
820         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
821 }
822 | MATCHER_WATCH_THREAD
823 {
824         gint criteria = 0;
825
826         criteria = MATCHCRITERIA_WATCH_THREAD;
827         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
828 }
829 | MATCHER_NOT_WATCH_THREAD
830 {
831         gint criteria = 0;
832
833         criteria = MATCHCRITERIA_NOT_WATCH_THREAD;
834         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
835 }
836 | MATCHER_SUBJECT match_type MATCHER_STRING
837 {
838         gint criteria = 0;
839         gchar *expr = NULL;
840
841         criteria = MATCHCRITERIA_SUBJECT;
842         expr = $3;
843         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
844 }
845 | MATCHER_NOT_SUBJECT match_type MATCHER_STRING
846 {
847         gint criteria = 0;
848         gchar *expr = NULL;
849
850         criteria = MATCHCRITERIA_NOT_SUBJECT;
851         expr = $3;
852         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
853 }
854 | MATCHER_FROM match_type MATCHER_STRING
855 {
856         gint criteria = 0;
857         gchar *expr = NULL;
858
859         criteria = MATCHCRITERIA_FROM;
860         expr = $3;
861         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
862 }
863 | MATCHER_NOT_FROM match_type MATCHER_STRING
864 {
865         gint criteria = 0;
866         gchar *expr = NULL;
867
868         criteria = MATCHCRITERIA_NOT_FROM;
869         expr = $3;
870         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
871 }
872 | MATCHER_TO match_type MATCHER_STRING
873 {
874         gint criteria = 0;
875         gchar *expr = NULL;
876
877         criteria = MATCHCRITERIA_TO;
878         expr = $3;
879         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
880 }
881 | MATCHER_NOT_TO match_type MATCHER_STRING
882 {
883         gint criteria = 0;
884         gchar *expr = NULL;
885
886         criteria = MATCHCRITERIA_NOT_TO;
887         expr = $3;
888         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
889 }
890 | MATCHER_CC match_type MATCHER_STRING
891 {
892         gint criteria = 0;
893         gchar *expr = NULL;
894
895         criteria = MATCHCRITERIA_CC;
896         expr = $3;
897         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
898 }
899 | MATCHER_NOT_CC match_type MATCHER_STRING
900 {
901         gint criteria = 0;
902         gchar *expr = NULL;
903
904         criteria = MATCHCRITERIA_NOT_CC;
905         expr = $3;
906         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
907 }
908 | MATCHER_TO_OR_CC match_type MATCHER_STRING
909 {
910         gint criteria = 0;
911         gchar *expr = NULL;
912
913         criteria = MATCHCRITERIA_TO_OR_CC;
914         expr = $3;
915         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
916 }
917 | MATCHER_NOT_TO_AND_NOT_CC match_type MATCHER_STRING
918 {
919         gint criteria = 0;
920         gchar *expr = NULL;
921
922         criteria = MATCHCRITERIA_NOT_TO_AND_NOT_CC;
923         expr = $3;
924         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
925 }
926 | MATCHER_TAG match_type MATCHER_STRING
927 {
928         gint criteria = 0;
929         gchar *expr = NULL;
930
931         criteria = MATCHCRITERIA_TAG;
932         expr = $3;
933         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
934 }
935 | MATCHER_NOT_TAG match_type MATCHER_STRING
936 {
937         gint criteria = 0;
938         gchar *expr = NULL;
939
940         criteria = MATCHCRITERIA_NOT_TAG;
941         expr = $3;
942         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
943 }
944 | MATCHER_TAGGED
945 {
946         gint criteria = 0;
947
948         criteria = MATCHCRITERIA_TAGGED;
949         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
950 }
951 | MATCHER_NOT_TAGGED
952 {
953         gint criteria = 0;
954
955         criteria = MATCHCRITERIA_NOT_TAGGED;
956         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
957 }
958 | MATCHER_AGE_GREATER MATCHER_INTEGER
959 {
960         gint criteria = 0;
961         gint value = 0;
962
963         criteria = MATCHCRITERIA_AGE_GREATER;
964         value = strtol($2, NULL, 0);
965         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
966 }
967 | MATCHER_AGE_LOWER MATCHER_INTEGER
968 {
969         gint criteria = 0;
970         gint value = 0;
971
972         criteria = MATCHCRITERIA_AGE_LOWER;
973         value = strtol($2, NULL, 0);
974         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
975 }
976 | MATCHER_AGE_GREATER_HOURS MATCHER_INTEGER
977 {
978         gint criteria = 0;
979         gint value = 0;
980
981         criteria = MATCHCRITERIA_AGE_GREATER_HOURS;
982         value = strtol($2, NULL, 0);
983         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
984 }
985 | MATCHER_AGE_LOWER_HOURS MATCHER_INTEGER
986 {
987         gint criteria = 0;
988         gint value = 0;
989
990         criteria = MATCHCRITERIA_AGE_LOWER_HOURS;
991         value = strtol($2, NULL, 0);
992         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
993 }
994 | MATCHER_DATE_AFTER MATCHER_STRING
995 {
996         gint criteria = 0;
997         gchar *expr = NULL;
998         time_t value;
999
1000         criteria = MATCHCRITERIA_DATE_AFTER;
1001         expr = $2;
1002         value = procheader_date_parse(NULL, expr, 0);
1003         prop = matcherprop_new(criteria, NULL, 0, expr, value);
1004 }
1005 | MATCHER_DATE_BEFORE MATCHER_STRING
1006 {
1007         gint criteria = 0;
1008         gchar *expr = NULL;
1009         time_t value;
1010
1011         criteria = MATCHCRITERIA_DATE_BEFORE;
1012         expr = $2;
1013         value = procheader_date_parse(NULL, expr, 0);
1014         prop = matcherprop_new(criteria, NULL, 0, expr, value);
1015 }
1016 | MATCHER_NEWSGROUPS match_type MATCHER_STRING
1017 {
1018         gint criteria = 0;
1019         gchar *expr = NULL;
1020
1021         criteria = MATCHCRITERIA_NEWSGROUPS;
1022         expr = $3;
1023         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1024 }
1025 | MATCHER_NOT_NEWSGROUPS match_type MATCHER_STRING
1026 {
1027         gint criteria = 0;
1028         gchar *expr = NULL;
1029
1030         criteria = MATCHCRITERIA_NOT_NEWSGROUPS;
1031         expr = $3;
1032         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1033 }
1034 | MATCHER_MESSAGEID match_type MATCHER_STRING
1035 {
1036         gint criteria = 0;
1037         gchar *expr = NULL;
1038
1039         criteria = MATCHCRITERIA_MESSAGEID;
1040         expr = $3;
1041         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1042 }
1043 | MATCHER_NOT_MESSAGEID match_type MATCHER_STRING
1044 {
1045         gint criteria = 0;
1046         gchar *expr = NULL;
1047
1048         criteria = MATCHCRITERIA_NOT_MESSAGEID;
1049         expr = $3;
1050         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1051 }
1052 | MATCHER_INREPLYTO match_type MATCHER_STRING
1053 {
1054         gint criteria = 0;
1055         gchar *expr = NULL;
1056
1057         criteria = MATCHCRITERIA_INREPLYTO;
1058         expr = $3;
1059         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1060 }
1061 | MATCHER_NOT_INREPLYTO match_type MATCHER_STRING
1062 {
1063         gint criteria = 0;
1064         gchar *expr = NULL;
1065
1066         criteria = MATCHCRITERIA_NOT_INREPLYTO;
1067         expr = $3;
1068         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1069 }
1070 | MATCHER_REFERENCES match_type MATCHER_STRING
1071 {
1072         gint criteria = 0;
1073         gchar *expr = NULL;
1074
1075         criteria = MATCHCRITERIA_REFERENCES;
1076         expr = $3;
1077         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1078 }
1079 | MATCHER_NOT_REFERENCES match_type MATCHER_STRING
1080 {
1081         gint criteria = 0;
1082         gchar *expr = NULL;
1083
1084         criteria = MATCHCRITERIA_NOT_REFERENCES;
1085         expr = $3;
1086         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1087 }
1088 | MATCHER_SCORE_GREATER MATCHER_INTEGER
1089 {
1090         gint criteria = 0;
1091         gint value = 0;
1092
1093         criteria = MATCHCRITERIA_SCORE_GREATER;
1094         value = strtol($2, NULL, 0);
1095         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1096 }
1097 | MATCHER_SCORE_LOWER MATCHER_INTEGER
1098 {
1099         gint criteria = 0;
1100         gint value = 0;
1101
1102         criteria = MATCHCRITERIA_SCORE_LOWER;
1103         value = strtol($2, NULL, 0);
1104         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1105 }
1106 | MATCHER_SCORE_EQUAL MATCHER_INTEGER
1107 {
1108         gint criteria = 0;
1109         gint value = 0;
1110
1111         criteria = MATCHCRITERIA_SCORE_EQUAL;
1112         value = strtol($2, NULL, 0);
1113         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1114 }
1115 | MATCHER_SIZE_GREATER MATCHER_INTEGER 
1116 {
1117         gint criteria = 0;
1118         gint value    = 0;
1119         criteria = MATCHCRITERIA_SIZE_GREATER;
1120         value = strtol($2, NULL, 0);
1121         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1122 }
1123 | MATCHER_SIZE_SMALLER MATCHER_INTEGER
1124 {
1125         gint criteria = 0;
1126         gint value    = 0;
1127         criteria = MATCHCRITERIA_SIZE_SMALLER;
1128         value = strtol($2, NULL, 0);
1129         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1130 }
1131 | MATCHER_SIZE_EQUAL MATCHER_INTEGER
1132 {
1133         gint criteria = 0;
1134         gint value    = 0;
1135         criteria = MATCHCRITERIA_SIZE_EQUAL;
1136         value = strtol($2, NULL, 0);
1137         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1138 }
1139 | MATCHER_HEADER MATCHER_STRING
1140 {
1141         header = g_strdup($2);
1142 } match_type MATCHER_STRING
1143 {
1144         gint criteria = 0;
1145         gchar *expr = NULL;
1146         matcher_is_fast = FALSE;
1147         criteria = MATCHCRITERIA_HEADER;
1148         expr = $2;
1149         prop = matcherprop_new(criteria, header, match_type, expr, 0);
1150         g_free(header);
1151 }
1152 | MATCHER_NOT_HEADER MATCHER_STRING
1153 {
1154         header = g_strdup($2);
1155 } match_type MATCHER_STRING
1156 {
1157         gint criteria = 0;
1158         gchar *expr = NULL;
1159         matcher_is_fast = FALSE;
1160         criteria = MATCHCRITERIA_NOT_HEADER;
1161         expr = $2;
1162         prop = matcherprop_new(criteria, header, match_type, expr, 0);
1163         g_free(header);
1164 }
1165 | MATCHER_HEADERS_PART match_type MATCHER_STRING
1166 {
1167         gint criteria = 0;
1168         gchar *expr = NULL;
1169         matcher_is_fast = FALSE;
1170         criteria = MATCHCRITERIA_HEADERS_PART;
1171         expr = $3;
1172         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1173 }
1174 | MATCHER_NOT_HEADERS_PART match_type MATCHER_STRING
1175 {
1176         gint criteria = 0;
1177         gchar *expr = NULL;
1178         matcher_is_fast = FALSE;
1179         criteria = MATCHCRITERIA_NOT_HEADERS_PART;
1180         expr = $3;
1181         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1182 }
1183 | MATCHER_HEADERS_CONT match_type MATCHER_STRING
1184 {
1185         gint criteria = 0;
1186         gchar *expr = NULL;
1187         matcher_is_fast = FALSE;
1188         criteria = MATCHCRITERIA_HEADERS_CONT;
1189         expr = $3;
1190         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1191 }
1192 | MATCHER_NOT_HEADERS_CONT match_type MATCHER_STRING
1193 {
1194         gint criteria = 0;
1195         gchar *expr = NULL;
1196         matcher_is_fast = FALSE;
1197         criteria = MATCHCRITERIA_NOT_HEADERS_CONT;
1198         expr = $3;
1199         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1200 }
1201 | MATCHER_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1202 {
1203         header = g_strdup($2);
1204 } MATCHER_IN MATCHER_STRING
1205 {
1206         gint criteria = 0;
1207         gchar *expr = NULL;
1208
1209         criteria = MATCHCRITERIA_FOUND_IN_ADDRESSBOOK;
1210         expr = $2;
1211         prop = matcherprop_new(criteria, header, match_type, expr, 0);
1212         g_free(header);
1213 }
1214 | MATCHER_NOT_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1215 {
1216         header = g_strdup($2);
1217 } MATCHER_IN MATCHER_STRING
1218 {
1219         gint criteria = 0;
1220         gchar *expr = NULL;
1221
1222         criteria = MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK;
1223         expr = $2;
1224         prop = matcherprop_new(criteria, header, match_type, expr, 0);
1225         g_free(header);
1226 }
1227 | MATCHER_MESSAGE match_type MATCHER_STRING
1228 {
1229         gint criteria = 0;
1230         gchar *expr = NULL;
1231         matcher_is_fast = FALSE;
1232         criteria = MATCHCRITERIA_MESSAGE;
1233         expr = $3;
1234         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1235 }
1236 | MATCHER_NOT_MESSAGE match_type MATCHER_STRING
1237 {
1238         gint criteria = 0;
1239         gchar *expr = NULL;
1240         matcher_is_fast = FALSE;
1241         criteria = MATCHCRITERIA_NOT_MESSAGE;
1242         expr = $3;
1243         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1244 }
1245 | MATCHER_BODY_PART match_type MATCHER_STRING
1246 {
1247         gint criteria = 0;
1248         gchar *expr = NULL;
1249         matcher_is_fast = FALSE;
1250         criteria = MATCHCRITERIA_BODY_PART;
1251         expr = $3;
1252         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1253 }
1254 | MATCHER_NOT_BODY_PART match_type MATCHER_STRING
1255 {
1256         gint criteria = 0;
1257         gchar *expr = NULL;
1258         matcher_is_fast = FALSE;
1259         criteria = MATCHCRITERIA_NOT_BODY_PART;
1260         expr = $3;
1261         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1262 }
1263 | MATCHER_TEST MATCHER_STRING
1264 {
1265         gint criteria = 0;
1266         gchar *expr = NULL;
1267         matcher_is_fast = FALSE;
1268         criteria = MATCHCRITERIA_TEST;
1269         expr = $2;
1270         prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, expr, 0);
1271 }
1272 | MATCHER_NOT_TEST MATCHER_STRING
1273 {
1274         gint criteria = 0;
1275         gchar *expr = NULL;
1276         matcher_is_fast = FALSE;
1277         criteria = MATCHCRITERIA_NOT_TEST;
1278         expr = $2;
1279         prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, expr, 0);
1280 }
1281 ;
1282
1283 filtering_action:
1284 MATCHER_EXECUTE MATCHER_STRING
1285 {
1286         gchar *cmd = NULL;
1287         gint action_type = 0;
1288
1289         action_type = MATCHACTION_EXECUTE;
1290         cmd = $2;
1291         action = filteringaction_new(action_type, 0, cmd, 0, 0, NULL);
1292 }
1293 | MATCHER_MOVE MATCHER_STRING
1294 {
1295         gchar *destination = NULL;
1296         gint action_type = 0;
1297
1298         action_type = MATCHACTION_MOVE;
1299         destination = $2;
1300         action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1301 }
1302 | MATCHER_SET_TAG MATCHER_STRING
1303 {
1304         gchar *destination = NULL;
1305         gint action_type = 0;
1306
1307         action_type = MATCHACTION_SET_TAG;
1308         destination = $2;
1309         action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1310 }
1311 | MATCHER_UNSET_TAG MATCHER_STRING
1312 {
1313         gchar *destination = NULL;
1314         gint action_type = 0;
1315
1316         action_type = MATCHACTION_UNSET_TAG;
1317         destination = $2;
1318         action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1319 }
1320 | MATCHER_CLEAR_TAGS
1321 {
1322         gint action_type = 0;
1323
1324         action_type = MATCHACTION_CLEAR_TAGS;
1325         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1326 }
1327 | MATCHER_COPY MATCHER_STRING
1328 {
1329         gchar *destination = NULL;
1330         gint action_type = 0;
1331
1332         action_type = MATCHACTION_COPY;
1333         destination = $2;
1334         action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1335 }
1336 | MATCHER_DELETE
1337 {
1338         gint action_type = 0;
1339
1340         action_type = MATCHACTION_DELETE;
1341         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1342 }
1343 | MATCHER_MARK
1344 {
1345         gint action_type = 0;
1346
1347         action_type = MATCHACTION_MARK;
1348         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1349 }
1350 | MATCHER_UNMARK
1351 {
1352         gint action_type = 0;
1353
1354         action_type = MATCHACTION_UNMARK;
1355         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1356 }
1357 | MATCHER_LOCK
1358 {
1359         gint action_type = 0;
1360
1361         action_type = MATCHACTION_LOCK;
1362         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1363 }
1364 | MATCHER_UNLOCK
1365 {
1366         gint action_type = 0;
1367
1368         action_type = MATCHACTION_UNLOCK;
1369         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1370 }
1371 | MATCHER_MARK_AS_READ
1372 {
1373         gint action_type = 0;
1374
1375         action_type = MATCHACTION_MARK_AS_READ;
1376         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1377 }
1378 | MATCHER_MARK_AS_UNREAD
1379 {
1380         gint action_type = 0;
1381
1382         action_type = MATCHACTION_MARK_AS_UNREAD;
1383         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1384 }
1385 | MATCHER_MARK_AS_SPAM
1386 {
1387         gint action_type = 0;
1388
1389         action_type = MATCHACTION_MARK_AS_SPAM;
1390         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1391 }
1392 | MATCHER_MARK_AS_HAM
1393 {
1394         gint action_type = 0;
1395
1396         action_type = MATCHACTION_MARK_AS_HAM;
1397         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1398 }
1399 | MATCHER_FORWARD MATCHER_INTEGER MATCHER_STRING
1400 {
1401         gchar *destination = NULL;
1402         gint action_type = 0;
1403         gint account_id = 0;
1404
1405         action_type = MATCHACTION_FORWARD;
1406         account_id = strtol($2, NULL, 10);
1407         destination = $3;
1408         action = filteringaction_new(action_type,
1409             account_id, destination, 0, 0, NULL);
1410 }
1411 | MATCHER_FORWARD_AS_ATTACHMENT MATCHER_INTEGER MATCHER_STRING
1412 {
1413         gchar *destination = NULL;
1414         gint action_type = 0;
1415         gint account_id = 0;
1416
1417         action_type = MATCHACTION_FORWARD_AS_ATTACHMENT;
1418         account_id = strtol($2, NULL, 10);
1419         destination = $3;
1420         action = filteringaction_new(action_type,
1421             account_id, destination, 0, 0, NULL);
1422 }
1423 | MATCHER_REDIRECT MATCHER_INTEGER MATCHER_STRING
1424 {
1425         gchar *destination = NULL;
1426         gint action_type = 0;
1427         gint account_id = 0;
1428
1429         action_type = MATCHACTION_REDIRECT;
1430         account_id = strtol($2, NULL, 10);
1431         destination = $3;
1432         action = filteringaction_new(action_type,
1433             account_id, destination, 0, 0, NULL);
1434 }
1435 | MATCHER_COLOR MATCHER_INTEGER
1436 {
1437         gint action_type = 0;
1438         gint color = 0;
1439
1440         action_type = MATCHACTION_COLOR;
1441         color = strtol($2, NULL, 10);
1442         action = filteringaction_new(action_type, 0, NULL, color, 0, NULL);
1443 }
1444 | MATCHER_CHANGE_SCORE MATCHER_INTEGER
1445 {
1446         gint score = 0;
1447         
1448         score = strtol($2, NULL, 10);
1449         action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1450                                      NULL, 0, score, NULL);
1451 }
1452 /* backward compatibility */
1453 | MATCHER_SCORE MATCHER_INTEGER
1454 {
1455         gint score = 0;
1456         
1457         score = strtol($2, NULL, 10);
1458         action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1459                                      NULL, 0, score, NULL);
1460 }
1461 | MATCHER_SET_SCORE MATCHER_INTEGER
1462 {
1463         gint score = 0;
1464         
1465         score = strtol($2, NULL, 10);
1466         action = filteringaction_new(MATCHACTION_SET_SCORE, 0,
1467                                      NULL, 0, score, NULL);
1468 }
1469 | MATCHER_HIDE
1470 {
1471         action = filteringaction_new(MATCHACTION_HIDE, 0, NULL, 0, 0, NULL);
1472 }
1473 | MATCHER_IGNORE
1474 {
1475         action = filteringaction_new(MATCHACTION_IGNORE, 0, NULL, 0, 0, NULL);
1476 }
1477 | MATCHER_WATCH
1478 {
1479         action = filteringaction_new(MATCHACTION_WATCH, 0, NULL, 0, 0, NULL);
1480 }
1481 | MATCHER_ADD_TO_ADDRESSBOOK MATCHER_STRING
1482 {
1483         header = g_strdup($2);
1484 } MATCHER_STRING
1485 {
1486         gchar *addressbook = NULL;
1487         gint action_type = 0;
1488
1489         action_type = MATCHACTION_ADD_TO_ADDRESSBOOK;
1490         addressbook = $2;
1491         action = filteringaction_new(action_type, 0, addressbook, 0, 0, header);
1492         g_free(header);
1493 }
1494 | MATCHER_STOP
1495 {
1496         action = filteringaction_new(MATCHACTION_STOP, 0, NULL, 0, 0, NULL);
1497 }
1498 ;