Clear statusbar's progressbar in case of NNTP xhdr/xover failure.
[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 "matcher.h"
29 #include "matcher_parser.h"
30 #include "matcher_parser_lex.h"
31 #include "colorlabel.h"
32 #include "folder_item_prefs.h"
33
34 static gint error = 0;
35 static gint bool_op = 0;
36 static gint match_type = 0;
37 static gchar *header = NULL;
38
39 static MatcherProp *prop;
40
41 static GSList *matchers_list = NULL;
42
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;
51
52 static FilteringProp *filtering;
53 static gboolean filtering_ptr_externally_managed = FALSE;
54
55 static GSList **prefs_filtering = NULL;
56 static int enable_compatibility = 0;
57
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,
66 };
67
68 static int matcher_parse_op = MATCHER_PARSE_FILE;
69
70
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);
79
80 void matcher_parser_disable_warnings(const gboolean disable)
81 {
82         disable_warnings = disable;
83 }
84
85 void matcher_parser_start_parsing(FILE *f)
86 {
87         matcher_parserlineno = 1;
88         matcher_parserrestart(f);
89         account_id = 0;
90         matcher_parserparse();
91 }
92
93  
94 void * matcher_parser_scan_string(const char * str);
95  
96 FilteringProp *matcher_parser_get_filtering(gchar *str)
97 {
98         void *bufstate;
99         void *tmp_str = NULL;
100         
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);
106
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;
127 }
128
129 static gboolean check_quote_symetry(gchar *str)
130 {
131         const gchar *walk;
132         int ret = 0;
133         
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 ++;
143                 }
144         }
145         return !(ret % 2);
146 }
147
148 MatcherList *matcher_parser_get_name(gchar *str)
149 {
150         void *bufstate;
151
152         if (!check_quote_symetry(str)) {
153                 cond = NULL;
154                 return cond;
155         }
156         
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;
169 }
170
171 MatcherList *matcher_parser_get_enabled(gchar *str)
172 {
173         void *bufstate;
174
175         if (!check_quote_symetry(str)) {
176                 cond = NULL;
177                 return cond;
178         }
179         
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;
192 }
193
194 MatcherList *matcher_parser_get_account(gchar *str)
195 {
196         void *bufstate;
197
198         if (!check_quote_symetry(str)) {
199                 cond = NULL;
200                 return cond;
201         }
202         
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;
215 }
216
217 MatcherList *matcher_parser_get_cond(gchar *str, gboolean *is_fast)
218 {
219         void *bufstate;
220
221         if (!check_quote_symetry(str)) {
222                 cond = NULL;
223                 return cond;
224         }
225         
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;
241 }
242
243 GSList *matcher_parser_get_action_list(gchar *str)
244 {
245         void *bufstate;
246
247         if (!check_quote_symetry(str)) {
248                 action_list = NULL;
249                 return action_list;
250         }
251         
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;
264 }
265
266 MatcherProp *matcher_parser_get_prop(gchar *str)
267 {
268         MatcherList *list;
269         MatcherProp *prop;
270
271         matcher_parserlineno = 1;
272         list = matcher_parser_get_cond(str, NULL);
273         if (list == NULL)
274                 return NULL;
275
276         if (list->matchers == NULL)
277                 return NULL;
278
279         if (list->matchers->next != NULL)
280                 return NULL;
281
282         prop = list->matchers->data;
283
284         g_slist_free(list->matchers);
285         g_free(list);
286
287         return prop;
288 }
289
290 void matcher_parsererror(char *str)
291 {
292         GSList *l;
293
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;
299                 }
300                 g_slist_free(matchers_list);
301                 matchers_list = NULL;
302         }
303         cond = NULL;
304         if (!disable_warnings)
305                 g_warning("filtering parsing: %i: %s",
306                         matcher_parserlineno, str);
307         error = 1;
308 }
309
310 int matcher_parserwrap(void)
311 {
312         return 1;
313 }
314 %}
315
316 %union {
317         char *str;
318         int value;
319 }
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
361
362 %start file
363
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
370
371 %%
372
373 file:
374 {
375         if (matcher_parse_op == MATCHER_PARSE_FILE) {
376                 prefs_filtering = &pre_global_processing;
377         }
378 }
379 file_line_list;
380
381 file_line_list:
382 file_line
383 file_line_list
384 | file_line
385 ;
386
387 file_line:
388 section_notification
389
390 { action_list = NULL; }
391 instruction
392 | error MATCHER_EOL
393 {
394         yyerrok;
395 };
396
397 section_notification:
398 MATCHER_SECTION MATCHER_EOL
399 {
400         gchar *folder = $1;
401         FolderItem *item = NULL;
402
403         if (matcher_parse_op == MATCHER_PARSE_FILE) {
404                 enable_compatibility = 0;
405                 if (!strcmp(folder, "global")) {
406                         /* backward compatibility */
407                         enable_compatibility = 1;
408                 }
409                 else if (!strcmp(folder, "preglobal")) {
410                         prefs_filtering = &pre_global_processing;
411                 }
412                 else if (!strcmp(folder, "postglobal")) {
413                         prefs_filtering = &post_global_processing;
414                 }
415                 else if (!strcmp(folder, "filtering")) {
416                         prefs_filtering = &filtering_rules;
417                 }
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;
424                         }
425                 }
426         }
427 }
428 ;
429
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
437 {
438         if (matcher_parse_op == MATCHER_PARSE_NO_EOL)
439                 YYACCEPT;
440         else {
441                 matcher_parsererror("parse error [no eol]");
442                 YYERROR;
443         }
444 }
445 | enabled
446 {
447         if (matcher_parse_op == MATCHER_PARSE_ENABLED)
448                 YYACCEPT;
449         else {
450                 matcher_parsererror("parse error [enabled]");
451                 YYERROR;
452         }
453 }
454 | account
455 {
456         if (matcher_parse_op == MATCHER_PARSE_ACCOUNT)
457                 YYACCEPT;
458         else {
459                 matcher_parsererror("parse error [account]");
460                 YYERROR;
461         }
462 }
463 | name
464 {
465         if (matcher_parse_op == MATCHER_PARSE_NAME)
466                 YYACCEPT;
467         else {
468                 matcher_parsererror("parse error [name]");
469                 YYERROR;
470         }
471 }
472 | condition
473 {
474         if (matcher_parse_op == MATCHER_PARSE_CONDITION)
475                 YYACCEPT;
476         else {
477                 matcher_parsererror("parse error [condition]");
478                 YYERROR;
479         }
480 }
481 | filtering_action_list
482 {
483         if (matcher_parse_op == MATCHER_PARSE_FILTERING_ACTION)
484                 YYACCEPT;
485         else {
486                 matcher_parsererror("parse error [filtering action]");
487                 YYERROR;
488         }
489 }
490 | MATCHER_EOL
491 ;
492
493 enabled:
494 MATCHER_ENABLED
495 {
496         enabled = TRUE;
497 }
498 | MATCHER_DISABLED
499 {
500         enabled = FALSE;
501 }
502 ;
503
504 name:
505 MATCHER_RULENAME MATCHER_STRING
506 {
507         name = g_strdup($2);
508 }
509 ;
510
511 account:
512 MATCHER_ACCOUNT MATCHER_INTEGER
513 {
514         account_id = strtol($2, NULL, 10);
515 }
516 ;
517
518 filtering:
519 filtering_action_list
520 {
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;
530                         
531                         first_action = action_list->data;
532                         
533                         if (first_action->type == MATCHACTION_CHANGE_SCORE)
534                                 prefs_filtering = &pre_global_processing;
535                 }
536         }
537         
538         cond = NULL;
539         action_list = NULL;
540         
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;
555         }
556 }
557 ;
558
559 filtering_action_list:
560 filtering_action_b filtering_action_list
561 | filtering_action_b
562 ;
563
564 filtering_action_b:
565 filtering_action
566 {
567         action_list = g_slist_append(action_list, action);
568         action = NULL;
569 }
570 ;
571
572 match_type:
573 MATCHER_MATCHCASE
574 {
575         match_type = MATCHTYPE_MATCHCASE;
576 }
577 | MATCHER_MATCH
578 {
579         match_type = MATCHTYPE_MATCH;
580 }
581 | MATCHER_REGEXPCASE
582 {
583         match_type = MATCHTYPE_REGEXPCASE;
584 }
585 | MATCHER_REGEXP
586 {
587         match_type = MATCHTYPE_REGEXP;
588 }
589 ;
590
591 condition:
592 condition_list
593 {
594         cond = matcherlist_new(matchers_list, (bool_op == MATCHERBOOL_AND));
595         matchers_list = NULL;
596 }
597 ;
598
599 condition_list:
600 condition_list bool_op one_condition
601 {
602         matchers_list = g_slist_append(matchers_list, prop);
603 }
604 | one_condition
605 {
606         matchers_list = NULL;
607         matchers_list = g_slist_append(matchers_list, prop);
608 }
609 ;
610
611 bool_op:
612 MATCHER_AND
613 {
614         bool_op = MATCHERBOOL_AND;
615 }
616 | MATCHER_OR
617 {
618         bool_op = MATCHERBOOL_OR;
619 }
620 ;
621
622 one_condition:
623 MATCHER_ALL
624 {
625         gint criteria = 0;
626
627         criteria = MATCHCRITERIA_ALL;
628         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
629 }
630 | MATCHER_UNREAD
631 {
632         gint criteria = 0;
633
634         criteria = MATCHCRITERIA_UNREAD;
635         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
636 }
637 | MATCHER_NOT_UNREAD 
638 {
639         gint criteria = 0;
640
641         criteria = MATCHCRITERIA_NOT_UNREAD;
642         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
643 }
644 | MATCHER_NEW
645 {
646         gint criteria = 0;
647
648         criteria = MATCHCRITERIA_NEW;
649         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
650 }
651 | MATCHER_NOT_NEW
652 {
653         gint criteria = 0;
654
655         criteria = MATCHCRITERIA_NOT_NEW;
656         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
657 }
658 | MATCHER_MARKED
659 {
660         gint criteria = 0;
661
662         criteria = MATCHCRITERIA_MARKED;
663         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
664 }
665 | MATCHER_NOT_MARKED
666 {
667         gint criteria = 0;
668
669         criteria = MATCHCRITERIA_NOT_MARKED;
670         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
671 }
672 | MATCHER_DELETED
673 {
674         gint criteria = 0;
675
676         criteria = MATCHCRITERIA_DELETED;
677         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
678 }
679 | MATCHER_NOT_DELETED
680 {
681         gint criteria = 0;
682
683         criteria = MATCHCRITERIA_NOT_DELETED;
684         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
685 }
686 | MATCHER_REPLIED
687 {
688         gint criteria = 0;
689
690         criteria = MATCHCRITERIA_REPLIED;
691         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
692 }
693 | MATCHER_NOT_REPLIED
694 {
695         gint criteria = 0;
696
697         criteria = MATCHCRITERIA_NOT_REPLIED;
698         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
699 }
700 | MATCHER_FORWARDED
701 {
702         gint criteria = 0;
703
704         criteria = MATCHCRITERIA_FORWARDED;
705         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
706 }
707 | MATCHER_NOT_FORWARDED
708 {
709         gint criteria = 0;
710
711         criteria = MATCHCRITERIA_NOT_FORWARDED;
712         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
713 }
714 | MATCHER_LOCKED
715 {
716         gint criteria = 0;
717
718         criteria = MATCHCRITERIA_LOCKED;
719         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
720 }
721 | MATCHER_NOT_LOCKED
722 {
723         gint criteria = 0;
724
725         criteria = MATCHCRITERIA_NOT_LOCKED;
726         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
727 }
728 | MATCHER_SPAM
729 {
730         gint criteria = 0;
731
732         criteria = MATCHCRITERIA_SPAM;
733         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
734 }
735 | MATCHER_NOT_SPAM 
736 {
737         gint criteria = 0;
738
739         criteria = MATCHCRITERIA_NOT_SPAM;
740         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
741 }
742 | MATCHER_HAS_ATTACHMENT
743 {
744         gint criteria = 0;
745
746         criteria = MATCHCRITERIA_HAS_ATTACHMENT;
747         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
748 }
749 | MATCHER_HAS_NO_ATTACHMENT
750 {
751         gint criteria = 0;
752
753         criteria = MATCHCRITERIA_HAS_NO_ATTACHMENT;
754         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
755 }
756 | MATCHER_SIGNED
757 {
758         gint criteria = 0;
759
760         criteria = MATCHCRITERIA_SIGNED;
761         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
762 }
763 | MATCHER_NOT_SIGNED
764 {
765         gint criteria = 0;
766
767         criteria = MATCHCRITERIA_NOT_SIGNED;
768         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
769 }
770 | MATCHER_PARTIAL
771 {
772         gint criteria = 0;
773
774         criteria = MATCHCRITERIA_PARTIAL;
775         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
776 }
777 | MATCHER_NOT_PARTIAL
778 {
779         gint criteria = 0;
780
781         criteria = MATCHCRITERIA_NOT_PARTIAL;
782         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
783 }
784 | MATCHER_COLORLABEL MATCHER_INTEGER
785 {
786         gint criteria = 0;
787         gint value = 0;
788
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);
794 }
795 | MATCHER_NOT_COLORLABEL MATCHER_INTEGER
796 {
797         gint criteria = 0;
798         gint value = 0;
799
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);
805 }
806 | MATCHER_IGNORE_THREAD
807 {
808         gint criteria = 0;
809
810         criteria = MATCHCRITERIA_IGNORE_THREAD;
811         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
812 }
813 | MATCHER_NOT_IGNORE_THREAD
814 {
815         gint criteria = 0;
816
817         criteria = MATCHCRITERIA_NOT_IGNORE_THREAD;
818         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
819 }
820 | MATCHER_WATCH_THREAD
821 {
822         gint criteria = 0;
823
824         criteria = MATCHCRITERIA_WATCH_THREAD;
825         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
826 }
827 | MATCHER_NOT_WATCH_THREAD
828 {
829         gint criteria = 0;
830
831         criteria = MATCHCRITERIA_NOT_WATCH_THREAD;
832         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
833 }
834 | MATCHER_SUBJECT match_type MATCHER_STRING
835 {
836         gint criteria = 0;
837         gchar *expr = NULL;
838
839         criteria = MATCHCRITERIA_SUBJECT;
840         expr = $3;
841         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
842 }
843 | MATCHER_NOT_SUBJECT match_type MATCHER_STRING
844 {
845         gint criteria = 0;
846         gchar *expr = NULL;
847
848         criteria = MATCHCRITERIA_NOT_SUBJECT;
849         expr = $3;
850         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
851 }
852 | MATCHER_FROM match_type MATCHER_STRING
853 {
854         gint criteria = 0;
855         gchar *expr = NULL;
856
857         criteria = MATCHCRITERIA_FROM;
858         expr = $3;
859         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
860 }
861 | MATCHER_NOT_FROM match_type MATCHER_STRING
862 {
863         gint criteria = 0;
864         gchar *expr = NULL;
865
866         criteria = MATCHCRITERIA_NOT_FROM;
867         expr = $3;
868         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
869 }
870 | MATCHER_TO match_type MATCHER_STRING
871 {
872         gint criteria = 0;
873         gchar *expr = NULL;
874
875         criteria = MATCHCRITERIA_TO;
876         expr = $3;
877         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
878 }
879 | MATCHER_NOT_TO match_type MATCHER_STRING
880 {
881         gint criteria = 0;
882         gchar *expr = NULL;
883
884         criteria = MATCHCRITERIA_NOT_TO;
885         expr = $3;
886         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
887 }
888 | MATCHER_CC match_type MATCHER_STRING
889 {
890         gint criteria = 0;
891         gchar *expr = NULL;
892
893         criteria = MATCHCRITERIA_CC;
894         expr = $3;
895         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
896 }
897 | MATCHER_NOT_CC match_type MATCHER_STRING
898 {
899         gint criteria = 0;
900         gchar *expr = NULL;
901
902         criteria = MATCHCRITERIA_NOT_CC;
903         expr = $3;
904         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
905 }
906 | MATCHER_TO_OR_CC match_type MATCHER_STRING
907 {
908         gint criteria = 0;
909         gchar *expr = NULL;
910
911         criteria = MATCHCRITERIA_TO_OR_CC;
912         expr = $3;
913         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
914 }
915 | MATCHER_NOT_TO_AND_NOT_CC match_type MATCHER_STRING
916 {
917         gint criteria = 0;
918         gchar *expr = NULL;
919
920         criteria = MATCHCRITERIA_NOT_TO_AND_NOT_CC;
921         expr = $3;
922         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
923 }
924 | MATCHER_TAG match_type MATCHER_STRING
925 {
926         gint criteria = 0;
927         gchar *expr = NULL;
928
929         criteria = MATCHCRITERIA_TAG;
930         expr = $3;
931         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
932 }
933 | MATCHER_NOT_TAG match_type MATCHER_STRING
934 {
935         gint criteria = 0;
936         gchar *expr = NULL;
937
938         criteria = MATCHCRITERIA_NOT_TAG;
939         expr = $3;
940         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
941 }
942 | MATCHER_TAGGED
943 {
944         gint criteria = 0;
945
946         criteria = MATCHCRITERIA_TAGGED;
947         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
948 }
949 | MATCHER_NOT_TAGGED
950 {
951         gint criteria = 0;
952
953         criteria = MATCHCRITERIA_NOT_TAGGED;
954         prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
955 }
956 | MATCHER_AGE_GREATER MATCHER_INTEGER
957 {
958         gint criteria = 0;
959         gint value = 0;
960
961         criteria = MATCHCRITERIA_AGE_GREATER;
962         value = strtol($2, NULL, 0);
963         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
964 }
965 | MATCHER_AGE_LOWER MATCHER_INTEGER
966 {
967         gint criteria = 0;
968         gint value = 0;
969
970         criteria = MATCHCRITERIA_AGE_LOWER;
971         value = strtol($2, NULL, 0);
972         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
973 }
974 | MATCHER_AGE_GREATER_HOURS MATCHER_INTEGER
975 {
976         gint criteria = 0;
977         gint value = 0;
978
979         criteria = MATCHCRITERIA_AGE_GREATER_HOURS;
980         value = strtol($2, NULL, 0);
981         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
982 }
983 | MATCHER_AGE_LOWER_HOURS MATCHER_INTEGER
984 {
985         gint criteria = 0;
986         gint value = 0;
987
988         criteria = MATCHCRITERIA_AGE_LOWER_HOURS;
989         value = strtol($2, NULL, 0);
990         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
991 }
992 | MATCHER_NEWSGROUPS match_type MATCHER_STRING
993 {
994         gint criteria = 0;
995         gchar *expr = NULL;
996
997         criteria = MATCHCRITERIA_NEWSGROUPS;
998         expr = $3;
999         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1000 }
1001 | MATCHER_NOT_NEWSGROUPS match_type MATCHER_STRING
1002 {
1003         gint criteria = 0;
1004         gchar *expr = NULL;
1005
1006         criteria = MATCHCRITERIA_NOT_NEWSGROUPS;
1007         expr = $3;
1008         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1009 }
1010 | MATCHER_MESSAGEID match_type MATCHER_STRING
1011 {
1012         gint criteria = 0;
1013         gchar *expr = NULL;
1014
1015         criteria = MATCHCRITERIA_MESSAGEID;
1016         expr = $3;
1017         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1018 }
1019 | MATCHER_NOT_MESSAGEID match_type MATCHER_STRING
1020 {
1021         gint criteria = 0;
1022         gchar *expr = NULL;
1023
1024         criteria = MATCHCRITERIA_NOT_MESSAGEID;
1025         expr = $3;
1026         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1027 }
1028 | MATCHER_INREPLYTO match_type MATCHER_STRING
1029 {
1030         gint criteria = 0;
1031         gchar *expr = NULL;
1032
1033         criteria = MATCHCRITERIA_INREPLYTO;
1034         expr = $3;
1035         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1036 }
1037 | MATCHER_NOT_INREPLYTO match_type MATCHER_STRING
1038 {
1039         gint criteria = 0;
1040         gchar *expr = NULL;
1041
1042         criteria = MATCHCRITERIA_NOT_INREPLYTO;
1043         expr = $3;
1044         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1045 }
1046 | MATCHER_REFERENCES match_type MATCHER_STRING
1047 {
1048         gint criteria = 0;
1049         gchar *expr = NULL;
1050
1051         criteria = MATCHCRITERIA_REFERENCES;
1052         expr = $3;
1053         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1054 }
1055 | MATCHER_NOT_REFERENCES match_type MATCHER_STRING
1056 {
1057         gint criteria = 0;
1058         gchar *expr = NULL;
1059
1060         criteria = MATCHCRITERIA_NOT_REFERENCES;
1061         expr = $3;
1062         prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1063 }
1064 | MATCHER_SCORE_GREATER MATCHER_INTEGER
1065 {
1066         gint criteria = 0;
1067         gint value = 0;
1068
1069         criteria = MATCHCRITERIA_SCORE_GREATER;
1070         value = strtol($2, NULL, 0);
1071         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1072 }
1073 | MATCHER_SCORE_LOWER MATCHER_INTEGER
1074 {
1075         gint criteria = 0;
1076         gint value = 0;
1077
1078         criteria = MATCHCRITERIA_SCORE_LOWER;
1079         value = strtol($2, NULL, 0);
1080         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1081 }
1082 | MATCHER_SCORE_EQUAL MATCHER_INTEGER
1083 {
1084         gint criteria = 0;
1085         gint value = 0;
1086
1087         criteria = MATCHCRITERIA_SCORE_EQUAL;
1088         value = strtol($2, NULL, 0);
1089         prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1090 }
1091 | MATCHER_SIZE_GREATER MATCHER_INTEGER 
1092 {
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);
1098 }
1099 | MATCHER_SIZE_SMALLER MATCHER_INTEGER
1100 {
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);
1106 }
1107 | MATCHER_SIZE_EQUAL MATCHER_INTEGER
1108 {
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);
1114 }
1115 | MATCHER_HEADER MATCHER_STRING
1116 {
1117         header = g_strdup($2);
1118 } match_type MATCHER_STRING
1119 {
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);
1127 }
1128 | MATCHER_NOT_HEADER MATCHER_STRING
1129 {
1130         header = g_strdup($2);
1131 } match_type MATCHER_STRING
1132 {
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);
1140 }
1141 | MATCHER_HEADERS_PART match_type MATCHER_STRING
1142 {
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);
1149 }
1150 | MATCHER_NOT_HEADERS_PART match_type MATCHER_STRING
1151 {
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);
1158 }
1159 | MATCHER_HEADERS_CONT match_type MATCHER_STRING
1160 {
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);
1167 }
1168 | MATCHER_NOT_HEADERS_CONT match_type MATCHER_STRING
1169 {
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);
1176 }
1177 | MATCHER_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1178 {
1179         header = g_strdup($2);
1180 } MATCHER_IN MATCHER_STRING
1181 {
1182         gint criteria = 0;
1183         gchar *expr = NULL;
1184
1185         criteria = MATCHCRITERIA_FOUND_IN_ADDRESSBOOK;
1186         expr = $2;
1187         prop = matcherprop_new(criteria, header, match_type, expr, 0);
1188         g_free(header);
1189 }
1190 | MATCHER_NOT_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1191 {
1192         header = g_strdup($2);
1193 } MATCHER_IN MATCHER_STRING
1194 {
1195         gint criteria = 0;
1196         gchar *expr = NULL;
1197
1198         criteria = MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK;
1199         expr = $2;
1200         prop = matcherprop_new(criteria, header, match_type, expr, 0);
1201         g_free(header);
1202 }
1203 | MATCHER_MESSAGE match_type MATCHER_STRING
1204 {
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);
1211 }
1212 | MATCHER_NOT_MESSAGE match_type MATCHER_STRING
1213 {
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);
1220 }
1221 | MATCHER_BODY_PART match_type MATCHER_STRING
1222 {
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);
1229 }
1230 | MATCHER_NOT_BODY_PART match_type MATCHER_STRING
1231 {
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);
1238 }
1239 | MATCHER_TEST MATCHER_STRING
1240 {
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);
1247 }
1248 | MATCHER_NOT_TEST MATCHER_STRING
1249 {
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);
1256 }
1257 ;
1258
1259 filtering_action:
1260 MATCHER_EXECUTE MATCHER_STRING
1261 {
1262         gchar *cmd = NULL;
1263         gint action_type = 0;
1264
1265         action_type = MATCHACTION_EXECUTE;
1266         cmd = $2;
1267         action = filteringaction_new(action_type, 0, cmd, 0, 0, NULL);
1268 }
1269 | MATCHER_MOVE MATCHER_STRING
1270 {
1271         gchar *destination = NULL;
1272         gint action_type = 0;
1273
1274         action_type = MATCHACTION_MOVE;
1275         destination = $2;
1276         action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1277 }
1278 | MATCHER_SET_TAG MATCHER_STRING
1279 {
1280         gchar *destination = NULL;
1281         gint action_type = 0;
1282
1283         action_type = MATCHACTION_SET_TAG;
1284         destination = $2;
1285         action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1286 }
1287 | MATCHER_UNSET_TAG MATCHER_STRING
1288 {
1289         gchar *destination = NULL;
1290         gint action_type = 0;
1291
1292         action_type = MATCHACTION_UNSET_TAG;
1293         destination = $2;
1294         action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1295 }
1296 | MATCHER_CLEAR_TAGS
1297 {
1298         gint action_type = 0;
1299
1300         action_type = MATCHACTION_CLEAR_TAGS;
1301         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1302 }
1303 | MATCHER_COPY MATCHER_STRING
1304 {
1305         gchar *destination = NULL;
1306         gint action_type = 0;
1307
1308         action_type = MATCHACTION_COPY;
1309         destination = $2;
1310         action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1311 }
1312 | MATCHER_DELETE
1313 {
1314         gint action_type = 0;
1315
1316         action_type = MATCHACTION_DELETE;
1317         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1318 }
1319 | MATCHER_MARK
1320 {
1321         gint action_type = 0;
1322
1323         action_type = MATCHACTION_MARK;
1324         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1325 }
1326 | MATCHER_UNMARK
1327 {
1328         gint action_type = 0;
1329
1330         action_type = MATCHACTION_UNMARK;
1331         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1332 }
1333 | MATCHER_LOCK
1334 {
1335         gint action_type = 0;
1336
1337         action_type = MATCHACTION_LOCK;
1338         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1339 }
1340 | MATCHER_UNLOCK
1341 {
1342         gint action_type = 0;
1343
1344         action_type = MATCHACTION_UNLOCK;
1345         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1346 }
1347 | MATCHER_MARK_AS_READ
1348 {
1349         gint action_type = 0;
1350
1351         action_type = MATCHACTION_MARK_AS_READ;
1352         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1353 }
1354 | MATCHER_MARK_AS_UNREAD
1355 {
1356         gint action_type = 0;
1357
1358         action_type = MATCHACTION_MARK_AS_UNREAD;
1359         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1360 }
1361 | MATCHER_MARK_AS_SPAM
1362 {
1363         gint action_type = 0;
1364
1365         action_type = MATCHACTION_MARK_AS_SPAM;
1366         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1367 }
1368 | MATCHER_MARK_AS_HAM
1369 {
1370         gint action_type = 0;
1371
1372         action_type = MATCHACTION_MARK_AS_HAM;
1373         action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1374 }
1375 | MATCHER_FORWARD MATCHER_INTEGER MATCHER_STRING
1376 {
1377         gchar *destination = NULL;
1378         gint action_type = 0;
1379         gint account_id = 0;
1380
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);
1386 }
1387 | MATCHER_FORWARD_AS_ATTACHMENT MATCHER_INTEGER MATCHER_STRING
1388 {
1389         gchar *destination = NULL;
1390         gint action_type = 0;
1391         gint account_id = 0;
1392
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);
1398 }
1399 | MATCHER_REDIRECT MATCHER_INTEGER MATCHER_STRING
1400 {
1401         gchar *destination = NULL;
1402         gint action_type = 0;
1403         gint account_id = 0;
1404
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);
1410 }
1411 | MATCHER_COLOR MATCHER_INTEGER
1412 {
1413         gint action_type = 0;
1414         gint color = 0;
1415
1416         action_type = MATCHACTION_COLOR;
1417         color = strtol($2, NULL, 10);
1418         action = filteringaction_new(action_type, 0, NULL, color, 0, NULL);
1419 }
1420 | MATCHER_CHANGE_SCORE MATCHER_INTEGER
1421 {
1422         gint score = 0;
1423         
1424         score = strtol($2, NULL, 10);
1425         action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1426                                      NULL, 0, score, NULL);
1427 }
1428 /* backward compatibility */
1429 | MATCHER_SCORE MATCHER_INTEGER
1430 {
1431         gint score = 0;
1432         
1433         score = strtol($2, NULL, 10);
1434         action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1435                                      NULL, 0, score, NULL);
1436 }
1437 | MATCHER_SET_SCORE MATCHER_INTEGER
1438 {
1439         gint score = 0;
1440         
1441         score = strtol($2, NULL, 10);
1442         action = filteringaction_new(MATCHACTION_SET_SCORE, 0,
1443                                      NULL, 0, score, NULL);
1444 }
1445 | MATCHER_HIDE
1446 {
1447         action = filteringaction_new(MATCHACTION_HIDE, 0, NULL, 0, 0, NULL);
1448 }
1449 | MATCHER_IGNORE
1450 {
1451         action = filteringaction_new(MATCHACTION_IGNORE, 0, NULL, 0, 0, NULL);
1452 }
1453 | MATCHER_WATCH
1454 {
1455         action = filteringaction_new(MATCHACTION_WATCH, 0, NULL, 0, 0, NULL);
1456 }
1457 | MATCHER_ADD_TO_ADDRESSBOOK MATCHER_STRING
1458 {
1459         header = g_strdup($2);
1460 } MATCHER_STRING
1461 {
1462         gchar *addressbook = NULL;
1463         gint action_type = 0;
1464
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);
1469 }
1470 | MATCHER_STOP
1471 {
1472         action = filteringaction_new(MATCHACTION_STOP, 0, NULL, 0, 0, NULL);
1473 }
1474 ;