Remove wrong initialization from max_message_size
[claws.git] / src / matcher_parser_parse.y
blob7bde1430a16b2d9cdf6f58cec113e8fb996201c7
1 %{
2 /*
3 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
4 * Copyright (c) 2001-2014 by Hiroyuki Yamamoto & The Claws Mail Team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "defs.h"
23 #include <glib.h>
24 #include <glib/gi18n.h>
26 #include "utils.h"
27 #include "filtering.h"
28 #include "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"
35 static gint error = 0;
36 static gint bool_op = 0;
37 static gint match_type = 0;
38 static gchar *header = NULL;
40 static MatcherProp *prop;
42 static GSList *matchers_list = NULL;
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;
53 static FilteringProp *filtering;
54 static gboolean filtering_ptr_externally_managed = FALSE;
56 static GSList **prefs_filtering = NULL;
57 static int enable_compatibility = 0;
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,
69 static int matcher_parse_op = MATCHER_PARSE_FILE;
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);
81 void matcher_parser_disable_warnings(const gboolean disable)
83 disable_warnings = disable;
86 void matcher_parser_start_parsing(FILE *f)
88 matcher_parserlineno = 1;
89 matcher_parserrestart(f);
90 account_id = 0;
91 matcher_parserparse();
95 void * matcher_parser_scan_string(const char * str);
97 FilteringProp *matcher_parser_get_filtering(gchar *str)
99 void *bufstate;
100 void *tmp_str = NULL;
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);
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;
130 static gboolean check_quote_symetry(gchar *str)
132 const gchar *walk;
133 int ret = 0;
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 ++;
146 return !(ret % 2);
149 MatcherList *matcher_parser_get_name(gchar *str)
151 void *bufstate;
153 if (!check_quote_symetry(str)) {
154 cond = NULL;
155 return cond;
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;
172 MatcherList *matcher_parser_get_enabled(gchar *str)
174 void *bufstate;
176 if (!check_quote_symetry(str)) {
177 cond = NULL;
178 return cond;
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;
195 MatcherList *matcher_parser_get_account(gchar *str)
197 void *bufstate;
199 if (!check_quote_symetry(str)) {
200 cond = NULL;
201 return cond;
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;
218 MatcherList *matcher_parser_get_cond(gchar *str, gboolean *is_fast)
220 void *bufstate;
222 if (!check_quote_symetry(str)) {
223 cond = NULL;
224 return cond;
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;
244 GSList *matcher_parser_get_action_list(gchar *str)
246 void *bufstate;
248 if (!check_quote_symetry(str)) {
249 action_list = NULL;
250 return action_list;
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;
267 MatcherProp *matcher_parser_get_prop(gchar *str)
269 MatcherList *list;
270 MatcherProp *prop;
272 matcher_parserlineno = 1;
273 list = matcher_parser_get_cond(str, NULL);
274 if (list == NULL)
275 return NULL;
277 if (list->matchers == NULL)
278 return NULL;
280 if (list->matchers->next != NULL)
281 return NULL;
283 prop = list->matchers->data;
285 g_slist_free(list->matchers);
286 g_free(list);
288 return prop;
291 void matcher_parsererror(char *str)
293 GSList *l;
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;
301 g_slist_free(matchers_list);
302 matchers_list = NULL;
304 cond = NULL;
305 if (!disable_warnings)
306 g_warning("filtering parsing: %i: %s",
307 matcher_parserlineno, str);
308 error = 1;
311 int matcher_parserwrap(void)
313 return 1;
317 %union {
318 char *str;
319 int value;
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
364 %start file
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
375 file:
377 if (matcher_parse_op == MATCHER_PARSE_FILE) {
378 prefs_filtering = &pre_global_processing;
381 file_line_list;
383 file_line_list:
384 file_line
385 file_line_list
386 | file_line
389 file_line:
390 section_notification
392 { action_list = NULL; }
393 instruction
394 | error MATCHER_EOL
396 yyerrok;
399 section_notification:
400 MATCHER_SECTION MATCHER_EOL
402 gchar *folder = $1;
403 FolderItem *item = NULL;
405 if (matcher_parse_op == MATCHER_PARSE_FILE) {
406 enable_compatibility = 0;
407 if (!strcmp(folder, "global")) {
408 /* backward compatibility */
409 enable_compatibility = 1;
411 else if (!strcmp(folder, "preglobal")) {
412 prefs_filtering = &pre_global_processing;
414 else if (!strcmp(folder, "postglobal")) {
415 prefs_filtering = &post_global_processing;
417 else if (!strcmp(folder, "filtering")) {
418 prefs_filtering = &filtering_rules;
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;
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
440 if (matcher_parse_op == MATCHER_PARSE_NO_EOL)
441 YYACCEPT;
442 else {
443 matcher_parsererror("parse error [no eol]");
444 YYERROR;
447 | enabled
449 if (matcher_parse_op == MATCHER_PARSE_ENABLED)
450 YYACCEPT;
451 else {
452 matcher_parsererror("parse error [enabled]");
453 YYERROR;
456 | account
458 if (matcher_parse_op == MATCHER_PARSE_ACCOUNT)
459 YYACCEPT;
460 else {
461 matcher_parsererror("parse error [account]");
462 YYERROR;
465 | name
467 if (matcher_parse_op == MATCHER_PARSE_NAME)
468 YYACCEPT;
469 else {
470 matcher_parsererror("parse error [name]");
471 YYERROR;
474 | condition
476 if (matcher_parse_op == MATCHER_PARSE_CONDITION)
477 YYACCEPT;
478 else {
479 matcher_parsererror("parse error [condition]");
480 YYERROR;
483 | filtering_action_list
485 if (matcher_parse_op == MATCHER_PARSE_FILTERING_ACTION)
486 YYACCEPT;
487 else {
488 matcher_parsererror("parse error [filtering action]");
489 YYERROR;
492 | MATCHER_EOL
495 enabled:
496 MATCHER_ENABLED
498 enabled = TRUE;
500 | MATCHER_DISABLED
502 enabled = FALSE;
506 name:
507 MATCHER_RULENAME MATCHER_STRING
509 name = g_strdup($2);
513 account:
514 MATCHER_ACCOUNT MATCHER_INTEGER
516 account_id = strtol($2, NULL, 10);
520 filtering:
521 filtering_action_list
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;
533 first_action = action_list->data;
535 if (first_action->type == MATCHACTION_CHANGE_SCORE)
536 prefs_filtering = &pre_global_processing;
540 cond = NULL;
541 action_list = NULL;
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;
561 filtering_action_list:
562 filtering_action_b filtering_action_list
563 | filtering_action_b
566 filtering_action_b:
567 filtering_action
569 action_list = g_slist_append(action_list, action);
570 action = NULL;
574 match_type:
575 MATCHER_MATCHCASE
577 match_type = MATCHTYPE_MATCHCASE;
579 | MATCHER_MATCH
581 match_type = MATCHTYPE_MATCH;
583 | MATCHER_REGEXPCASE
585 match_type = MATCHTYPE_REGEXPCASE;
587 | MATCHER_REGEXP
589 match_type = MATCHTYPE_REGEXP;
593 condition:
594 condition_list
596 cond = matcherlist_new(matchers_list, (bool_op == MATCHERBOOL_AND));
597 matchers_list = NULL;
601 condition_list:
602 condition_list bool_op one_condition
604 matchers_list = g_slist_append(matchers_list, prop);
606 | one_condition
608 matchers_list = NULL;
609 matchers_list = g_slist_append(matchers_list, prop);
613 bool_op:
614 MATCHER_AND
616 bool_op = MATCHERBOOL_AND;
618 | MATCHER_OR
620 bool_op = MATCHERBOOL_OR;
624 one_condition:
625 MATCHER_ALL
627 gint criteria = 0;
629 criteria = MATCHCRITERIA_ALL;
630 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
632 | MATCHER_UNREAD
634 gint criteria = 0;
636 criteria = MATCHCRITERIA_UNREAD;
637 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
639 | MATCHER_NOT_UNREAD
641 gint criteria = 0;
643 criteria = MATCHCRITERIA_NOT_UNREAD;
644 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
646 | MATCHER_NEW
648 gint criteria = 0;
650 criteria = MATCHCRITERIA_NEW;
651 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
653 | MATCHER_NOT_NEW
655 gint criteria = 0;
657 criteria = MATCHCRITERIA_NOT_NEW;
658 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
660 | MATCHER_MARKED
662 gint criteria = 0;
664 criteria = MATCHCRITERIA_MARKED;
665 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
667 | MATCHER_NOT_MARKED
669 gint criteria = 0;
671 criteria = MATCHCRITERIA_NOT_MARKED;
672 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
674 | MATCHER_DELETED
676 gint criteria = 0;
678 criteria = MATCHCRITERIA_DELETED;
679 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
681 | MATCHER_NOT_DELETED
683 gint criteria = 0;
685 criteria = MATCHCRITERIA_NOT_DELETED;
686 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
688 | MATCHER_REPLIED
690 gint criteria = 0;
692 criteria = MATCHCRITERIA_REPLIED;
693 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
695 | MATCHER_NOT_REPLIED
697 gint criteria = 0;
699 criteria = MATCHCRITERIA_NOT_REPLIED;
700 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
702 | MATCHER_FORWARDED
704 gint criteria = 0;
706 criteria = MATCHCRITERIA_FORWARDED;
707 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
709 | MATCHER_NOT_FORWARDED
711 gint criteria = 0;
713 criteria = MATCHCRITERIA_NOT_FORWARDED;
714 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
716 | MATCHER_LOCKED
718 gint criteria = 0;
720 criteria = MATCHCRITERIA_LOCKED;
721 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
723 | MATCHER_NOT_LOCKED
725 gint criteria = 0;
727 criteria = MATCHCRITERIA_NOT_LOCKED;
728 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
730 | MATCHER_SPAM
732 gint criteria = 0;
734 criteria = MATCHCRITERIA_SPAM;
735 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
737 | MATCHER_NOT_SPAM
739 gint criteria = 0;
741 criteria = MATCHCRITERIA_NOT_SPAM;
742 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
744 | MATCHER_HAS_ATTACHMENT
746 gint criteria = 0;
748 criteria = MATCHCRITERIA_HAS_ATTACHMENT;
749 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
751 | MATCHER_HAS_NO_ATTACHMENT
753 gint criteria = 0;
755 criteria = MATCHCRITERIA_HAS_NO_ATTACHMENT;
756 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
758 | MATCHER_SIGNED
760 gint criteria = 0;
762 criteria = MATCHCRITERIA_SIGNED;
763 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
765 | MATCHER_NOT_SIGNED
767 gint criteria = 0;
769 criteria = MATCHCRITERIA_NOT_SIGNED;
770 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
772 | MATCHER_PARTIAL
774 gint criteria = 0;
776 criteria = MATCHCRITERIA_PARTIAL;
777 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
779 | MATCHER_NOT_PARTIAL
781 gint criteria = 0;
783 criteria = MATCHCRITERIA_NOT_PARTIAL;
784 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
786 | MATCHER_COLORLABEL MATCHER_INTEGER
788 gint criteria = 0;
789 gint value = 0;
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);
797 | MATCHER_NOT_COLORLABEL MATCHER_INTEGER
799 gint criteria = 0;
800 gint value = 0;
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);
808 | MATCHER_IGNORE_THREAD
810 gint criteria = 0;
812 criteria = MATCHCRITERIA_IGNORE_THREAD;
813 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
815 | MATCHER_NOT_IGNORE_THREAD
817 gint criteria = 0;
819 criteria = MATCHCRITERIA_NOT_IGNORE_THREAD;
820 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
822 | MATCHER_WATCH_THREAD
824 gint criteria = 0;
826 criteria = MATCHCRITERIA_WATCH_THREAD;
827 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
829 | MATCHER_NOT_WATCH_THREAD
831 gint criteria = 0;
833 criteria = MATCHCRITERIA_NOT_WATCH_THREAD;
834 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
836 | MATCHER_SUBJECT match_type MATCHER_STRING
838 gint criteria = 0;
839 gchar *expr = NULL;
841 criteria = MATCHCRITERIA_SUBJECT;
842 expr = $3;
843 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
845 | MATCHER_NOT_SUBJECT match_type MATCHER_STRING
847 gint criteria = 0;
848 gchar *expr = NULL;
850 criteria = MATCHCRITERIA_NOT_SUBJECT;
851 expr = $3;
852 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
854 | MATCHER_FROM match_type MATCHER_STRING
856 gint criteria = 0;
857 gchar *expr = NULL;
859 criteria = MATCHCRITERIA_FROM;
860 expr = $3;
861 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
863 | MATCHER_NOT_FROM match_type MATCHER_STRING
865 gint criteria = 0;
866 gchar *expr = NULL;
868 criteria = MATCHCRITERIA_NOT_FROM;
869 expr = $3;
870 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
872 | MATCHER_TO match_type MATCHER_STRING
874 gint criteria = 0;
875 gchar *expr = NULL;
877 criteria = MATCHCRITERIA_TO;
878 expr = $3;
879 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
881 | MATCHER_NOT_TO match_type MATCHER_STRING
883 gint criteria = 0;
884 gchar *expr = NULL;
886 criteria = MATCHCRITERIA_NOT_TO;
887 expr = $3;
888 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
890 | MATCHER_CC match_type MATCHER_STRING
892 gint criteria = 0;
893 gchar *expr = NULL;
895 criteria = MATCHCRITERIA_CC;
896 expr = $3;
897 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
899 | MATCHER_NOT_CC match_type MATCHER_STRING
901 gint criteria = 0;
902 gchar *expr = NULL;
904 criteria = MATCHCRITERIA_NOT_CC;
905 expr = $3;
906 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
908 | MATCHER_TO_OR_CC match_type MATCHER_STRING
910 gint criteria = 0;
911 gchar *expr = NULL;
913 criteria = MATCHCRITERIA_TO_OR_CC;
914 expr = $3;
915 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
917 | MATCHER_NOT_TO_AND_NOT_CC match_type MATCHER_STRING
919 gint criteria = 0;
920 gchar *expr = NULL;
922 criteria = MATCHCRITERIA_NOT_TO_AND_NOT_CC;
923 expr = $3;
924 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
926 | MATCHER_TAG match_type MATCHER_STRING
928 gint criteria = 0;
929 gchar *expr = NULL;
931 criteria = MATCHCRITERIA_TAG;
932 expr = $3;
933 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
935 | MATCHER_NOT_TAG match_type MATCHER_STRING
937 gint criteria = 0;
938 gchar *expr = NULL;
940 criteria = MATCHCRITERIA_NOT_TAG;
941 expr = $3;
942 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
944 | MATCHER_TAGGED
946 gint criteria = 0;
948 criteria = MATCHCRITERIA_TAGGED;
949 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
951 | MATCHER_NOT_TAGGED
953 gint criteria = 0;
955 criteria = MATCHCRITERIA_NOT_TAGGED;
956 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
958 | MATCHER_AGE_GREATER MATCHER_INTEGER
960 gint criteria = 0;
961 gint value = 0;
963 criteria = MATCHCRITERIA_AGE_GREATER;
964 value = strtol($2, NULL, 0);
965 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
967 | MATCHER_AGE_LOWER MATCHER_INTEGER
969 gint criteria = 0;
970 gint value = 0;
972 criteria = MATCHCRITERIA_AGE_LOWER;
973 value = strtol($2, NULL, 0);
974 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
976 | MATCHER_AGE_GREATER_HOURS MATCHER_INTEGER
978 gint criteria = 0;
979 gint value = 0;
981 criteria = MATCHCRITERIA_AGE_GREATER_HOURS;
982 value = strtol($2, NULL, 0);
983 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
985 | MATCHER_AGE_LOWER_HOURS MATCHER_INTEGER
987 gint criteria = 0;
988 gint value = 0;
990 criteria = MATCHCRITERIA_AGE_LOWER_HOURS;
991 value = strtol($2, NULL, 0);
992 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
994 | MATCHER_DATE_AFTER MATCHER_STRING
996 gint criteria = 0;
997 gchar *expr = NULL;
998 time_t value;
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);
1005 | MATCHER_DATE_BEFORE MATCHER_STRING
1007 gint criteria = 0;
1008 gchar *expr = NULL;
1009 time_t value;
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);
1016 | MATCHER_NEWSGROUPS match_type MATCHER_STRING
1018 gint criteria = 0;
1019 gchar *expr = NULL;
1021 criteria = MATCHCRITERIA_NEWSGROUPS;
1022 expr = $3;
1023 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1025 | MATCHER_NOT_NEWSGROUPS match_type MATCHER_STRING
1027 gint criteria = 0;
1028 gchar *expr = NULL;
1030 criteria = MATCHCRITERIA_NOT_NEWSGROUPS;
1031 expr = $3;
1032 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1034 | MATCHER_MESSAGEID match_type MATCHER_STRING
1036 gint criteria = 0;
1037 gchar *expr = NULL;
1039 criteria = MATCHCRITERIA_MESSAGEID;
1040 expr = $3;
1041 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1043 | MATCHER_NOT_MESSAGEID match_type MATCHER_STRING
1045 gint criteria = 0;
1046 gchar *expr = NULL;
1048 criteria = MATCHCRITERIA_NOT_MESSAGEID;
1049 expr = $3;
1050 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1052 | MATCHER_INREPLYTO match_type MATCHER_STRING
1054 gint criteria = 0;
1055 gchar *expr = NULL;
1057 criteria = MATCHCRITERIA_INREPLYTO;
1058 expr = $3;
1059 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1061 | MATCHER_NOT_INREPLYTO match_type MATCHER_STRING
1063 gint criteria = 0;
1064 gchar *expr = NULL;
1066 criteria = MATCHCRITERIA_NOT_INREPLYTO;
1067 expr = $3;
1068 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1070 | MATCHER_REFERENCES match_type MATCHER_STRING
1072 gint criteria = 0;
1073 gchar *expr = NULL;
1075 criteria = MATCHCRITERIA_REFERENCES;
1076 expr = $3;
1077 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1079 | MATCHER_NOT_REFERENCES match_type MATCHER_STRING
1081 gint criteria = 0;
1082 gchar *expr = NULL;
1084 criteria = MATCHCRITERIA_NOT_REFERENCES;
1085 expr = $3;
1086 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
1088 | MATCHER_SCORE_GREATER MATCHER_INTEGER
1090 gint criteria = 0;
1091 gint value = 0;
1093 criteria = MATCHCRITERIA_SCORE_GREATER;
1094 value = strtol($2, NULL, 0);
1095 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1097 | MATCHER_SCORE_LOWER MATCHER_INTEGER
1099 gint criteria = 0;
1100 gint value = 0;
1102 criteria = MATCHCRITERIA_SCORE_LOWER;
1103 value = strtol($2, NULL, 0);
1104 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1106 | MATCHER_SCORE_EQUAL MATCHER_INTEGER
1108 gint criteria = 0;
1109 gint value = 0;
1111 criteria = MATCHCRITERIA_SCORE_EQUAL;
1112 value = strtol($2, NULL, 0);
1113 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
1115 | MATCHER_SIZE_GREATER MATCHER_INTEGER
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);
1123 | MATCHER_SIZE_SMALLER MATCHER_INTEGER
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);
1131 | MATCHER_SIZE_EQUAL MATCHER_INTEGER
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);
1139 | MATCHER_HEADER MATCHER_STRING
1141 header = g_strdup($2);
1142 } match_type MATCHER_STRING
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);
1152 | MATCHER_NOT_HEADER MATCHER_STRING
1154 header = g_strdup($2);
1155 } match_type MATCHER_STRING
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);
1165 | MATCHER_HEADERS_PART match_type MATCHER_STRING
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);
1174 | MATCHER_NOT_HEADERS_PART match_type MATCHER_STRING
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);
1183 | MATCHER_HEADERS_CONT match_type MATCHER_STRING
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);
1192 | MATCHER_NOT_HEADERS_CONT match_type MATCHER_STRING
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);
1201 | MATCHER_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1203 header = g_strdup($2);
1204 } MATCHER_IN MATCHER_STRING
1206 gint criteria = 0;
1207 gchar *expr = NULL;
1209 criteria = MATCHCRITERIA_FOUND_IN_ADDRESSBOOK;
1210 expr = $2;
1211 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1212 g_free(header);
1214 | MATCHER_NOT_FOUND_IN_ADDRESSBOOK MATCHER_STRING
1216 header = g_strdup($2);
1217 } MATCHER_IN MATCHER_STRING
1219 gint criteria = 0;
1220 gchar *expr = NULL;
1222 criteria = MATCHCRITERIA_NOT_FOUND_IN_ADDRESSBOOK;
1223 expr = $2;
1224 prop = matcherprop_new(criteria, header, match_type, expr, 0);
1225 g_free(header);
1227 | MATCHER_MESSAGE match_type MATCHER_STRING
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);
1236 | MATCHER_NOT_MESSAGE match_type MATCHER_STRING
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);
1245 | MATCHER_BODY_PART match_type MATCHER_STRING
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);
1254 | MATCHER_NOT_BODY_PART match_type MATCHER_STRING
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);
1263 | MATCHER_TEST MATCHER_STRING
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);
1272 | MATCHER_NOT_TEST MATCHER_STRING
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);
1283 filtering_action:
1284 MATCHER_EXECUTE MATCHER_STRING
1286 gchar *cmd = NULL;
1287 gint action_type = 0;
1289 action_type = MATCHACTION_EXECUTE;
1290 cmd = $2;
1291 action = filteringaction_new(action_type, 0, cmd, 0, 0, NULL);
1293 | MATCHER_MOVE MATCHER_STRING
1295 gchar *destination = NULL;
1296 gint action_type = 0;
1298 action_type = MATCHACTION_MOVE;
1299 destination = $2;
1300 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1302 | MATCHER_SET_TAG MATCHER_STRING
1304 gchar *destination = NULL;
1305 gint action_type = 0;
1307 action_type = MATCHACTION_SET_TAG;
1308 destination = $2;
1309 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1311 | MATCHER_UNSET_TAG MATCHER_STRING
1313 gchar *destination = NULL;
1314 gint action_type = 0;
1316 action_type = MATCHACTION_UNSET_TAG;
1317 destination = $2;
1318 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1320 | MATCHER_CLEAR_TAGS
1322 gint action_type = 0;
1324 action_type = MATCHACTION_CLEAR_TAGS;
1325 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1327 | MATCHER_COPY MATCHER_STRING
1329 gchar *destination = NULL;
1330 gint action_type = 0;
1332 action_type = MATCHACTION_COPY;
1333 destination = $2;
1334 action = filteringaction_new(action_type, 0, destination, 0, 0, NULL);
1336 | MATCHER_DELETE
1338 gint action_type = 0;
1340 action_type = MATCHACTION_DELETE;
1341 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1343 | MATCHER_MARK
1345 gint action_type = 0;
1347 action_type = MATCHACTION_MARK;
1348 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1350 | MATCHER_UNMARK
1352 gint action_type = 0;
1354 action_type = MATCHACTION_UNMARK;
1355 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1357 | MATCHER_LOCK
1359 gint action_type = 0;
1361 action_type = MATCHACTION_LOCK;
1362 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1364 | MATCHER_UNLOCK
1366 gint action_type = 0;
1368 action_type = MATCHACTION_UNLOCK;
1369 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1371 | MATCHER_MARK_AS_READ
1373 gint action_type = 0;
1375 action_type = MATCHACTION_MARK_AS_READ;
1376 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1378 | MATCHER_MARK_AS_UNREAD
1380 gint action_type = 0;
1382 action_type = MATCHACTION_MARK_AS_UNREAD;
1383 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1385 | MATCHER_MARK_AS_SPAM
1387 gint action_type = 0;
1389 action_type = MATCHACTION_MARK_AS_SPAM;
1390 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1392 | MATCHER_MARK_AS_HAM
1394 gint action_type = 0;
1396 action_type = MATCHACTION_MARK_AS_HAM;
1397 action = filteringaction_new(action_type, 0, NULL, 0, 0, NULL);
1399 | MATCHER_FORWARD MATCHER_INTEGER MATCHER_STRING
1401 gchar *destination = NULL;
1402 gint action_type = 0;
1403 gint account_id = 0;
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);
1411 | MATCHER_FORWARD_AS_ATTACHMENT MATCHER_INTEGER MATCHER_STRING
1413 gchar *destination = NULL;
1414 gint action_type = 0;
1415 gint account_id = 0;
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);
1423 | MATCHER_REDIRECT MATCHER_INTEGER MATCHER_STRING
1425 gchar *destination = NULL;
1426 gint action_type = 0;
1427 gint account_id = 0;
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);
1435 | MATCHER_COLOR MATCHER_INTEGER
1437 gint action_type = 0;
1438 gint color = 0;
1440 action_type = MATCHACTION_COLOR;
1441 color = strtol($2, NULL, 10);
1442 action = filteringaction_new(action_type, 0, NULL, color, 0, NULL);
1444 | MATCHER_CHANGE_SCORE MATCHER_INTEGER
1446 gint score = 0;
1448 score = strtol($2, NULL, 10);
1449 action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1450 NULL, 0, score, NULL);
1452 /* backward compatibility */
1453 | MATCHER_SCORE MATCHER_INTEGER
1455 gint score = 0;
1457 score = strtol($2, NULL, 10);
1458 action = filteringaction_new(MATCHACTION_CHANGE_SCORE, 0,
1459 NULL, 0, score, NULL);
1461 | MATCHER_SET_SCORE MATCHER_INTEGER
1463 gint score = 0;
1465 score = strtol($2, NULL, 10);
1466 action = filteringaction_new(MATCHACTION_SET_SCORE, 0,
1467 NULL, 0, score, NULL);
1469 | MATCHER_HIDE
1471 action = filteringaction_new(MATCHACTION_HIDE, 0, NULL, 0, 0, NULL);
1473 | MATCHER_IGNORE
1475 action = filteringaction_new(MATCHACTION_IGNORE, 0, NULL, 0, 0, NULL);
1477 | MATCHER_WATCH
1479 action = filteringaction_new(MATCHACTION_WATCH, 0, NULL, 0, 0, NULL);
1481 | MATCHER_ADD_TO_ADDRESSBOOK MATCHER_STRING
1483 header = g_strdup($2);
1484 } MATCHER_STRING
1486 gchar *addressbook = NULL;
1487 gint action_type = 0;
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);
1494 | MATCHER_STOP
1496 action = filteringaction_new(MATCHACTION_STOP, 0, NULL, 0, 0, NULL);