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