5 #include "matcher_parser.h"
6 #include "matcher_parser_lex.h"
12 static gint error = 0;
13 static gint bool_op = 0;
14 static gint match_type = 0;
15 static gchar * header = NULL;
17 static MatcherProp * prop;
19 static GSList * matchers_list = NULL;
21 static MatcherList * cond;
22 static gint score = 0;
23 static FilteringAction * action = NULL;
25 static FilteringProp * filtering;
26 static ScoringProp * scoring = NULL;
28 static GSList ** prefs_scoring = NULL;
29 static GSList ** prefs_filtering = NULL;
31 static int matcher_parser_dialog = 0;
34 /* ******************************************************************** */
38 void matcher_parser_start_parsing(FILE * f)
40 matcher_parserrestart(f);
41 matcher_parserparse();
44 FilteringProp * matcher_parser_get_filtering(gchar * str)
48 /* bad coding to enable the sub-grammar matching
50 matcher_parserlineno = 1;
51 matcher_parser_dialog = 1;
52 bufstate = matcher_parser_scan_string(str);
53 if (matcher_parserparse() != 0)
55 matcher_parser_dialog = 0;
56 matcher_parser_delete_buffer(bufstate);
60 ScoringProp * matcher_parser_get_scoring(gchar * str)
64 /* bad coding to enable the sub-grammar matching
66 matcher_parserlineno = 1;
67 matcher_parser_dialog = 1;
68 bufstate = matcher_parser_scan_string(str);
69 if (matcher_parserparse() != 0)
71 matcher_parser_dialog = 0;
72 matcher_parser_delete_buffer(bufstate);
76 MatcherList * matcher_parser_get_cond(gchar * str)
80 /* bad coding to enable the sub-grammar matching
82 matcher_parserlineno = 1;
83 matcher_parser_dialog = 1;
84 bufstate = matcher_parser_scan_string(str);
85 matcher_parserparse();
86 matcher_parser_dialog = 0;
87 matcher_parser_delete_buffer(bufstate);
91 MatcherProp * matcher_parser_get_prop(gchar * str)
96 matcher_parserlineno = 1;
97 list = matcher_parser_get_cond(str);
101 if (list->matchers == NULL)
104 if (list->matchers->next != NULL)
107 prop = list->matchers->data;
109 g_slist_free(list->matchers);
115 void matcher_parsererror(char * str)
120 for(l = matchers_list ; l != NULL ;
122 matcherprop_free((MatcherProp *)
124 g_slist_free(matchers_list);
125 matchers_list = NULL;
128 g_warning(_("scoring / filtering parsing: %i: %s\n"),
129 matcher_parserlineno, str);
133 int matcher_parserwrap(void)
144 %token MATCHER_ALL MATCHER_UNREAD MATCHER_NOT_UNREAD
145 %token MATCHER_NEW MATCHER_NOT_NEW MATCHER_MARKED
146 %token MATCHER_NOT_MARKED MATCHER_DELETED MATCHER_NOT_DELETED
147 %token MATCHER_REPLIED MATCHER_NOT_REPLIED MATCHER_FORWARDED
148 %token MATCHER_NOT_FORWARDED MATCHER_SUBJECT MATCHER_NOT_SUBJECT
149 %token MATCHER_FROM MATCHER_NOT_FROM MATCHER_TO MATCHER_NOT_TO
150 %token MATCHER_CC MATCHER_NOT_CC MATCHER_TO_OR_CC MATCHER_NOT_TO_AND_NOT_CC
151 %token MATCHER_AGE_GREATER MATCHER_AGE_LOWER MATCHER_NEWSGROUPS
152 %token MATCHER_NOT_NEWSGROUPS MATCHER_INREPLYTO MATCHER_NOT_INREPLYTO
153 %token MATCHER_REFERENCES MATCHER_NOT_REFERENCES MATCHER_SCORE_GREATER
154 %token MATCHER_SCORE_LOWER MATCHER_HEADER MATCHER_NOT_HEADER
155 %token MATCHER_HEADERS_PART MATCHER_NOT_HEADERS_PART MATCHER_MESSAGE
156 %token MATCHER_NOT_MESSAGE MATCHER_BODY_PART MATCHER_NOT_BODY_PART
157 %token MATCHER_EXECUTE MATCHER_NOT_EXECUTE MATCHER_MATCHCASE MATCHER_MATCH
158 %token MATCHER_REGEXPCASE MATCHER_REGEXP MATCHER_SCORE MATCHER_MOVE
159 %token MATCHER_COPY MATCHER_DELETE MATCHER_MARK MATCHER_UNMARK
160 %token MATCHER_MARK_AS_READ MATCHER_MARK_AS_UNREAD MATCHER_FORWARD
161 %token MATCHER_FORWARD_AS_ATTACHMENT MATCHER_EOL MATCHER_STRING
162 %token MATCHER_OR MATCHER_AND
163 %token MATCHER_COLOR MATCHER_SCORE_EQUAL MATCHER_BOUNCE
167 %token <str> MATCHER_STRING
168 %token <str> MATCHER_SECTION
169 %token <value> MATCHER_INTEGER
175 if (!matcher_parser_dialog) {
176 prefs_scoring = &global_scoring;
177 prefs_filtering = &global_processing;
196 section_notification:
197 MATCHER_SECTION MATCHER_EOL
200 FolderItem * item = NULL;
202 if (!matcher_parser_dialog) {
203 item = folder_find_item_from_identifier(folder);
205 prefs_scoring = &global_scoring;
206 prefs_filtering = &global_processing;
209 prefs_scoring = &item->prefs->scoring;
210 prefs_filtering = &item->prefs->processing;
217 condition end_instr_opt
222 filtering_or_scoring end_action
225 if (matcher_parser_dialog)
228 matcher_parsererror("parse error");
238 if (matcher_parser_dialog)
241 matcher_parsererror("parse error");
247 filtering_or_scoring:
250 filtering = filteringprop_new(cond, action);
253 if (!matcher_parser_dialog) {
254 * prefs_filtering = g_slist_append(* prefs_filtering,
261 scoring = scoringprop_new(cond, score);
264 if (!matcher_parser_dialog) {
265 * prefs_scoring = g_slist_append(* prefs_scoring, scoring);
274 match_type = MATCHTYPE_MATCHCASE;
278 match_type = MATCHTYPE_MATCH;
282 match_type = MATCHTYPE_REGEXPCASE;
286 match_type = MATCHTYPE_REGEXP;
293 cond = matcherlist_new(matchers_list, (bool_op == MATCHERBOOL_AND));
294 matchers_list = NULL;
299 condition_list bool_op one_condition
301 matchers_list = g_slist_append(matchers_list, prop);
305 matchers_list = NULL;
306 matchers_list = g_slist_append(matchers_list, prop);
313 bool_op = MATCHERBOOL_AND;
317 bool_op = MATCHERBOOL_OR;
326 criteria = MATCHCRITERIA_ALL;
327 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
333 criteria = MATCHCRITERIA_UNREAD;
334 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
340 criteria = MATCHCRITERIA_NOT_UNREAD;
341 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
347 criteria = MATCHCRITERIA_NEW;
348 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
354 criteria = MATCHCRITERIA_NOT_NEW;
355 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
361 criteria = MATCHCRITERIA_MARKED;
362 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
368 criteria = MATCHCRITERIA_NOT_MARKED;
369 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
375 criteria = MATCHCRITERIA_DELETED;
376 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
378 | MATCHER_NOT_DELETED
382 criteria = MATCHCRITERIA_NOT_DELETED;
383 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
389 criteria = MATCHCRITERIA_REPLIED;
390 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
392 | MATCHER_NOT_REPLIED
396 criteria = MATCHCRITERIA_NOT_REPLIED;
397 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
403 criteria = MATCHCRITERIA_FORWARDED;
404 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
406 | MATCHER_NOT_FORWARDED
410 criteria = MATCHCRITERIA_NOT_FORWARDED;
411 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
413 | MATCHER_SUBJECT match_type MATCHER_STRING
418 criteria = MATCHCRITERIA_SUBJECT;
420 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
422 | MATCHER_NOT_SUBJECT match_type MATCHER_STRING
427 criteria = MATCHCRITERIA_NOT_SUBJECT;
429 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
431 | MATCHER_FROM match_type MATCHER_STRING
436 criteria = MATCHCRITERIA_FROM;
438 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
440 | MATCHER_NOT_FROM match_type MATCHER_STRING
445 criteria = MATCHCRITERIA_NOT_FROM;
447 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
449 | MATCHER_TO match_type MATCHER_STRING
454 criteria = MATCHCRITERIA_TO;
456 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
458 | MATCHER_NOT_TO match_type MATCHER_STRING
463 criteria = MATCHCRITERIA_NOT_TO;
465 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
467 | MATCHER_CC match_type MATCHER_STRING
472 criteria = MATCHCRITERIA_CC;
474 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
476 | MATCHER_NOT_CC match_type MATCHER_STRING
481 criteria = MATCHCRITERIA_NOT_CC;
483 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
485 | MATCHER_TO_OR_CC match_type MATCHER_STRING
490 criteria = MATCHCRITERIA_TO_OR_CC;
492 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
494 | MATCHER_NOT_TO_AND_NOT_CC match_type MATCHER_STRING
499 criteria = MATCHCRITERIA_NOT_TO_AND_NOT_CC;
501 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
503 | MATCHER_AGE_GREATER MATCHER_INTEGER
508 criteria = MATCHCRITERIA_AGE_GREATER;
510 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
512 | MATCHER_AGE_LOWER MATCHER_INTEGER
517 criteria = MATCHCRITERIA_AGE_LOWER;
519 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
521 | MATCHER_NEWSGROUPS match_type MATCHER_STRING
526 criteria = MATCHCRITERIA_NEWSGROUPS;
528 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
530 | MATCHER_NOT_NEWSGROUPS match_type MATCHER_STRING
535 criteria = MATCHCRITERIA_NOT_NEWSGROUPS;
537 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
539 | MATCHER_INREPLYTO match_type MATCHER_STRING
544 criteria = MATCHCRITERIA_INREPLYTO;
546 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
548 | MATCHER_NOT_INREPLYTO match_type MATCHER_STRING
553 criteria = MATCHCRITERIA_NOT_INREPLYTO;
555 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
557 | MATCHER_REFERENCES match_type MATCHER_STRING
562 criteria = MATCHCRITERIA_REFERENCES;
564 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
566 | MATCHER_NOT_REFERENCES match_type MATCHER_STRING
571 criteria = MATCHCRITERIA_NOT_REFERENCES;
573 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
575 | MATCHER_SCORE_GREATER MATCHER_INTEGER
580 criteria = MATCHCRITERIA_SCORE_GREATER;
582 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
584 | MATCHER_SCORE_LOWER MATCHER_INTEGER
589 criteria = MATCHCRITERIA_SCORE_LOWER;
591 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
593 | MATCHER_SCORE_EQUAL MATCHER_INTEGER
598 criteria = MATCHCRITERIA_SCORE_EQUAL;
600 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
602 | MATCHER_HEADER MATCHER_STRING
604 header = g_strdup($2);
605 } match_type MATCHER_STRING
610 criteria = MATCHCRITERIA_HEADER;
612 prop = matcherprop_new(criteria, header, match_type, expr, 0);
615 | MATCHER_NOT_HEADER MATCHER_STRING
617 header = g_strdup($2);
618 } match_type MATCHER_STRING
623 criteria = MATCHCRITERIA_NOT_HEADER;
625 prop = matcherprop_new(criteria, header, match_type, expr, 0);
628 | MATCHER_HEADERS_PART match_type MATCHER_STRING
633 criteria = MATCHCRITERIA_HEADERS_PART;
635 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
637 | MATCHER_NOT_HEADERS_PART match_type MATCHER_STRING
642 criteria = MATCHCRITERIA_NOT_HEADERS_PART;
644 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
646 | MATCHER_MESSAGE match_type MATCHER_STRING
651 criteria = MATCHCRITERIA_MESSAGE;
653 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
655 | MATCHER_NOT_MESSAGE match_type MATCHER_STRING
660 criteria = MATCHCRITERIA_NOT_MESSAGE;
662 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
664 | MATCHER_BODY_PART match_type MATCHER_STRING
669 criteria = MATCHCRITERIA_BODY_PART;
671 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
673 | MATCHER_NOT_BODY_PART match_type MATCHER_STRING
678 criteria = MATCHCRITERIA_NOT_BODY_PART;
680 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
682 | MATCHER_EXECUTE MATCHER_STRING
687 criteria = MATCHCRITERIA_EXECUTE;
689 prop = matcherprop_new(criteria, NULL, 0, expr, 0);
691 | MATCHER_NOT_EXECUTE MATCHER_STRING
696 criteria = MATCHCRITERIA_NOT_EXECUTE;
698 prop = matcherprop_new(criteria, NULL, 0, expr, 0);
703 MATCHER_EXECUTE MATCHER_STRING
706 gint action_type = 0;
708 action_type = MATCHACTION_EXECUTE;
710 action = filteringaction_new(action_type, 0, cmd, 0);
712 | MATCHER_MOVE MATCHER_STRING
714 gchar * destination = NULL;
715 gint action_type = 0;
717 action_type = MATCHACTION_MOVE;
719 action = filteringaction_new(action_type, 0, destination, 0);
721 | MATCHER_COPY MATCHER_STRING
723 gchar * destination = NULL;
724 gint action_type = 0;
726 action_type = MATCHACTION_COPY;
728 action = filteringaction_new(action_type, 0, destination, 0);
732 gint action_type = 0;
734 action_type = MATCHACTION_DELETE;
735 action = filteringaction_new(action_type, 0, NULL, 0);
739 gint action_type = 0;
741 action_type = MATCHACTION_MARK;
742 action = filteringaction_new(action_type, 0, NULL, 0);
746 gint action_type = 0;
748 action_type = MATCHACTION_UNMARK;
749 action = filteringaction_new(action_type, 0, NULL, 0);
751 | MATCHER_MARK_AS_READ
753 gint action_type = 0;
755 action_type = MATCHACTION_MARK_AS_READ;
756 action = filteringaction_new(action_type, 0, NULL, 0);
758 | MATCHER_MARK_AS_UNREAD
760 gint action_type = 0;
762 action_type = MATCHACTION_MARK_AS_UNREAD;
763 action = filteringaction_new(action_type, 0, NULL, 0);
765 | MATCHER_FORWARD MATCHER_INTEGER MATCHER_STRING
767 gchar * destination = NULL;
768 gint action_type = 0;
771 action_type = MATCHACTION_FORWARD;
772 account_id = atoi($2);
774 action = filteringaction_new(action_type, account_id, destination, 0);
776 | MATCHER_FORWARD_AS_ATTACHMENT MATCHER_INTEGER MATCHER_STRING
778 gchar * destination = NULL;
779 gint action_type = 0;
782 action_type = MATCHACTION_FORWARD_AS_ATTACHMENT;
783 account_id = atoi($2);
785 action = filteringaction_new(action_type, account_id, destination, 0);
787 | MATCHER_BOUNCE MATCHER_INTEGER MATCHER_STRING
789 gchar * destination = NULL;
790 gint action_type = 0;
793 action_type = MATCHACTION_BOUNCE;
794 account_id = atoi($2);
796 action = filteringaction_new(action_type, account_id, destination, 0);
798 | MATCHER_COLOR MATCHER_INTEGER
800 gint action_type = 0;
803 action_type = MATCHACTION_COLOR;
805 action = filteringaction_new(action_type, 0, NULL, color);
810 MATCHER_SCORE MATCHER_INTEGER