11 #include "matcher_parser.h"
12 #include "matcher_parser_lex.h"
14 static gint error = 0;
15 static gint bool_op = 0;
16 static gint match_type = 0;
17 static gchar * header = NULL;
19 static MatcherProp * prop;
21 static GSList * matchers_list = NULL;
23 static MatcherList * cond;
24 static gint score = 0;
25 static FilteringAction * action = NULL;
27 static FilteringProp * filtering;
28 static ScoringProp * scoring = NULL;
30 static GSList ** prefs_scoring = NULL;
31 static GSList ** prefs_filtering = NULL;
33 static int matcher_parser_dialog = 0;
36 /* ******************************************************************** */
40 void matcher_parser_start_parsing(FILE * f)
42 matcher_parserrestart(f);
43 matcher_parserparse();
46 FilteringProp * matcher_parser_get_filtering(gchar * str)
50 /* bad coding to enable the sub-grammar matching
52 matcher_parserlineno = 1;
53 matcher_parser_dialog = 1;
54 bufstate = matcher_parser_scan_string(str);
55 if (matcher_parserparse() != 0)
57 matcher_parser_dialog = 0;
58 matcher_parser_delete_buffer(bufstate);
62 ScoringProp * matcher_parser_get_scoring(gchar * str)
66 /* bad coding to enable the sub-grammar matching
68 matcher_parserlineno = 1;
69 matcher_parser_dialog = 1;
70 bufstate = matcher_parser_scan_string(str);
71 if (matcher_parserparse() != 0)
73 matcher_parser_dialog = 0;
74 matcher_parser_delete_buffer(bufstate);
78 MatcherList * matcher_parser_get_cond(gchar * str)
82 /* bad coding to enable the sub-grammar matching
84 matcher_parserlineno = 1;
85 matcher_parser_dialog = 1;
86 bufstate = matcher_parser_scan_string(str);
87 matcher_parserparse();
88 matcher_parser_dialog = 0;
89 matcher_parser_delete_buffer(bufstate);
93 MatcherProp * matcher_parser_get_prop(gchar * str)
98 matcher_parserlineno = 1;
99 list = matcher_parser_get_cond(str);
103 if (list->matchers == NULL)
106 if (list->matchers->next != NULL)
109 prop = list->matchers->data;
111 g_slist_free(list->matchers);
117 void matcher_parsererror(char * str)
122 for(l = matchers_list ; l != NULL ;
124 matcherprop_free((MatcherProp *)
126 g_slist_free(matchers_list);
127 matchers_list = NULL;
130 g_warning(_("scoring / filtering parsing: %i: %s\n"),
131 matcher_parserlineno, str);
135 int matcher_parserwrap(void)
146 %token MATCHER_ALL MATCHER_UNREAD MATCHER_NOT_UNREAD
147 %token MATCHER_NEW MATCHER_NOT_NEW MATCHER_MARKED
148 %token MATCHER_NOT_MARKED MATCHER_DELETED MATCHER_NOT_DELETED
149 %token MATCHER_REPLIED MATCHER_NOT_REPLIED MATCHER_FORWARDED
150 %token MATCHER_NOT_FORWARDED MATCHER_SUBJECT MATCHER_NOT_SUBJECT
151 %token MATCHER_FROM MATCHER_NOT_FROM MATCHER_TO MATCHER_NOT_TO
152 %token MATCHER_CC MATCHER_NOT_CC MATCHER_TO_OR_CC MATCHER_NOT_TO_AND_NOT_CC
153 %token MATCHER_AGE_GREATER MATCHER_AGE_LOWER MATCHER_NEWSGROUPS
154 %token MATCHER_NOT_NEWSGROUPS MATCHER_INREPLYTO MATCHER_NOT_INREPLYTO
155 %token MATCHER_REFERENCES MATCHER_NOT_REFERENCES MATCHER_SCORE_GREATER
156 %token MATCHER_SCORE_LOWER MATCHER_HEADER MATCHER_NOT_HEADER
157 %token MATCHER_HEADERS_PART MATCHER_NOT_HEADERS_PART MATCHER_MESSAGE
158 %token MATCHER_NOT_MESSAGE MATCHER_BODY_PART MATCHER_NOT_BODY_PART
159 %token MATCHER_EXECUTE MATCHER_NOT_EXECUTE MATCHER_MATCHCASE MATCHER_MATCH
160 %token MATCHER_REGEXPCASE MATCHER_REGEXP MATCHER_SCORE MATCHER_MOVE
161 %token MATCHER_COPY MATCHER_DELETE MATCHER_MARK MATCHER_UNMARK
162 %token MATCHER_MARK_AS_READ MATCHER_MARK_AS_UNREAD MATCHER_FORWARD
163 %token MATCHER_FORWARD_AS_ATTACHMENT MATCHER_EOL MATCHER_STRING
164 %token MATCHER_OR MATCHER_AND
165 %token MATCHER_COLOR MATCHER_SCORE_EQUAL MATCHER_BOUNCE MATCHER_DELETE_ON_SERVER
169 %token <str> MATCHER_STRING
170 %token <str> MATCHER_SECTION
171 %token <value> MATCHER_INTEGER
177 if (!matcher_parser_dialog) {
178 prefs_scoring = &global_scoring;
179 prefs_filtering = &global_processing;
198 section_notification:
199 MATCHER_SECTION MATCHER_EOL
202 FolderItem * item = NULL;
204 if (!matcher_parser_dialog) {
205 item = folder_find_item_from_identifier(folder);
207 prefs_scoring = &global_scoring;
208 prefs_filtering = &global_processing;
211 prefs_scoring = &item->prefs->scoring;
212 prefs_filtering = &item->prefs->processing;
219 condition end_instr_opt
224 filtering_or_scoring end_action
227 if (matcher_parser_dialog)
230 matcher_parsererror("parse error");
240 if (matcher_parser_dialog)
243 matcher_parsererror("parse error");
249 filtering_or_scoring:
252 filtering = filteringprop_new(cond, action);
255 if (!matcher_parser_dialog) {
256 * prefs_filtering = g_slist_append(* prefs_filtering,
263 scoring = scoringprop_new(cond, score);
266 if (!matcher_parser_dialog) {
267 * prefs_scoring = g_slist_append(* prefs_scoring, scoring);
276 match_type = MATCHTYPE_MATCHCASE;
280 match_type = MATCHTYPE_MATCH;
284 match_type = MATCHTYPE_REGEXPCASE;
288 match_type = MATCHTYPE_REGEXP;
295 cond = matcherlist_new(matchers_list, (bool_op == MATCHERBOOL_AND));
296 matchers_list = NULL;
301 condition_list bool_op one_condition
303 matchers_list = g_slist_append(matchers_list, prop);
307 matchers_list = NULL;
308 matchers_list = g_slist_append(matchers_list, prop);
315 bool_op = MATCHERBOOL_AND;
319 bool_op = MATCHERBOOL_OR;
328 criteria = MATCHCRITERIA_ALL;
329 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
335 criteria = MATCHCRITERIA_UNREAD;
336 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
342 criteria = MATCHCRITERIA_NOT_UNREAD;
343 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
349 criteria = MATCHCRITERIA_NEW;
350 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
356 criteria = MATCHCRITERIA_NOT_NEW;
357 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
363 criteria = MATCHCRITERIA_MARKED;
364 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
370 criteria = MATCHCRITERIA_NOT_MARKED;
371 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
377 criteria = MATCHCRITERIA_DELETED;
378 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
380 | MATCHER_NOT_DELETED
384 criteria = MATCHCRITERIA_NOT_DELETED;
385 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
391 criteria = MATCHCRITERIA_REPLIED;
392 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
394 | MATCHER_NOT_REPLIED
398 criteria = MATCHCRITERIA_NOT_REPLIED;
399 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
405 criteria = MATCHCRITERIA_FORWARDED;
406 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
408 | MATCHER_NOT_FORWARDED
412 criteria = MATCHCRITERIA_NOT_FORWARDED;
413 prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
415 | MATCHER_SUBJECT match_type MATCHER_STRING
420 criteria = MATCHCRITERIA_SUBJECT;
422 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
424 | MATCHER_NOT_SUBJECT match_type MATCHER_STRING
429 criteria = MATCHCRITERIA_NOT_SUBJECT;
431 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
433 | MATCHER_FROM match_type MATCHER_STRING
438 criteria = MATCHCRITERIA_FROM;
440 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
442 | MATCHER_NOT_FROM match_type MATCHER_STRING
447 criteria = MATCHCRITERIA_NOT_FROM;
449 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
451 | MATCHER_TO match_type MATCHER_STRING
456 criteria = MATCHCRITERIA_TO;
458 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
460 | MATCHER_NOT_TO match_type MATCHER_STRING
465 criteria = MATCHCRITERIA_NOT_TO;
467 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
469 | MATCHER_CC match_type MATCHER_STRING
474 criteria = MATCHCRITERIA_CC;
476 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
478 | MATCHER_NOT_CC match_type MATCHER_STRING
483 criteria = MATCHCRITERIA_NOT_CC;
485 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
487 | MATCHER_TO_OR_CC match_type MATCHER_STRING
492 criteria = MATCHCRITERIA_TO_OR_CC;
494 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
496 | MATCHER_NOT_TO_AND_NOT_CC match_type MATCHER_STRING
501 criteria = MATCHCRITERIA_NOT_TO_AND_NOT_CC;
503 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
505 | MATCHER_AGE_GREATER MATCHER_INTEGER
510 criteria = MATCHCRITERIA_AGE_GREATER;
512 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
514 | MATCHER_AGE_LOWER MATCHER_INTEGER
519 criteria = MATCHCRITERIA_AGE_LOWER;
521 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
523 | MATCHER_NEWSGROUPS match_type MATCHER_STRING
528 criteria = MATCHCRITERIA_NEWSGROUPS;
530 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
532 | MATCHER_NOT_NEWSGROUPS match_type MATCHER_STRING
537 criteria = MATCHCRITERIA_NOT_NEWSGROUPS;
539 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
541 | MATCHER_INREPLYTO match_type MATCHER_STRING
546 criteria = MATCHCRITERIA_INREPLYTO;
548 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
550 | MATCHER_NOT_INREPLYTO match_type MATCHER_STRING
555 criteria = MATCHCRITERIA_NOT_INREPLYTO;
557 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
559 | MATCHER_REFERENCES match_type MATCHER_STRING
564 criteria = MATCHCRITERIA_REFERENCES;
566 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
568 | MATCHER_NOT_REFERENCES match_type MATCHER_STRING
573 criteria = MATCHCRITERIA_NOT_REFERENCES;
575 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
577 | MATCHER_SCORE_GREATER MATCHER_INTEGER
582 criteria = MATCHCRITERIA_SCORE_GREATER;
584 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
586 | MATCHER_SCORE_LOWER MATCHER_INTEGER
591 criteria = MATCHCRITERIA_SCORE_LOWER;
593 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
595 | MATCHER_SCORE_EQUAL MATCHER_INTEGER
600 criteria = MATCHCRITERIA_SCORE_EQUAL;
602 prop = matcherprop_new(criteria, NULL, 0, NULL, value);
604 | MATCHER_HEADER MATCHER_STRING
606 header = g_strdup($2);
607 } match_type MATCHER_STRING
612 criteria = MATCHCRITERIA_HEADER;
614 prop = matcherprop_new(criteria, header, match_type, expr, 0);
617 | MATCHER_NOT_HEADER MATCHER_STRING
619 header = g_strdup($2);
620 } match_type MATCHER_STRING
625 criteria = MATCHCRITERIA_NOT_HEADER;
627 prop = matcherprop_new(criteria, header, match_type, expr, 0);
630 | MATCHER_HEADERS_PART match_type MATCHER_STRING
635 criteria = MATCHCRITERIA_HEADERS_PART;
637 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
639 | MATCHER_NOT_HEADERS_PART match_type MATCHER_STRING
644 criteria = MATCHCRITERIA_NOT_HEADERS_PART;
646 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
648 | MATCHER_MESSAGE match_type MATCHER_STRING
653 criteria = MATCHCRITERIA_MESSAGE;
655 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
657 | MATCHER_NOT_MESSAGE match_type MATCHER_STRING
662 criteria = MATCHCRITERIA_NOT_MESSAGE;
664 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
666 | MATCHER_BODY_PART match_type MATCHER_STRING
671 criteria = MATCHCRITERIA_BODY_PART;
673 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
675 | MATCHER_NOT_BODY_PART match_type MATCHER_STRING
680 criteria = MATCHCRITERIA_NOT_BODY_PART;
682 prop = matcherprop_new(criteria, NULL, match_type, expr, 0);
684 | MATCHER_EXECUTE MATCHER_STRING
689 criteria = MATCHCRITERIA_EXECUTE;
691 prop = matcherprop_new(criteria, NULL, 0, expr, 0);
693 | MATCHER_NOT_EXECUTE MATCHER_STRING
698 criteria = MATCHCRITERIA_NOT_EXECUTE;
700 prop = matcherprop_new(criteria, NULL, 0, expr, 0);
705 MATCHER_EXECUTE MATCHER_STRING
708 gint action_type = 0;
710 action_type = MATCHACTION_EXECUTE;
712 action = filteringaction_new(action_type, 0, cmd, 0);
714 | MATCHER_MOVE MATCHER_STRING
716 gchar * destination = NULL;
717 gint action_type = 0;
719 action_type = MATCHACTION_MOVE;
721 action = filteringaction_new(action_type, 0, destination, 0);
723 | MATCHER_COPY MATCHER_STRING
725 gchar * destination = NULL;
726 gint action_type = 0;
728 action_type = MATCHACTION_COPY;
730 action = filteringaction_new(action_type, 0, destination, 0);
734 gint action_type = 0;
736 action_type = MATCHACTION_DELETE;
737 action = filteringaction_new(action_type, 0, NULL, 0);
741 gint action_type = 0;
743 action_type = MATCHACTION_MARK;
744 action = filteringaction_new(action_type, 0, NULL, 0);
748 gint action_type = 0;
750 action_type = MATCHACTION_UNMARK;
751 action = filteringaction_new(action_type, 0, NULL, 0);
753 | MATCHER_MARK_AS_READ
755 gint action_type = 0;
757 action_type = MATCHACTION_MARK_AS_READ;
758 action = filteringaction_new(action_type, 0, NULL, 0);
760 | MATCHER_MARK_AS_UNREAD
762 gint action_type = 0;
764 action_type = MATCHACTION_MARK_AS_UNREAD;
765 action = filteringaction_new(action_type, 0, NULL, 0);
767 | MATCHER_FORWARD MATCHER_INTEGER MATCHER_STRING
769 gchar * destination = NULL;
770 gint action_type = 0;
773 action_type = MATCHACTION_FORWARD;
774 account_id = atoi($2);
776 action = filteringaction_new(action_type, account_id, destination, 0);
778 | MATCHER_FORWARD_AS_ATTACHMENT MATCHER_INTEGER MATCHER_STRING
780 gchar * destination = NULL;
781 gint action_type = 0;
784 action_type = MATCHACTION_FORWARD_AS_ATTACHMENT;
785 account_id = atoi($2);
787 action = filteringaction_new(action_type, account_id, destination, 0);
789 | MATCHER_BOUNCE MATCHER_INTEGER MATCHER_STRING
791 gchar * destination = NULL;
792 gint action_type = 0;
795 action_type = MATCHACTION_BOUNCE;
796 account_id = atoi($2);
798 action = filteringaction_new(action_type, account_id, destination, 0);
800 | MATCHER_COLOR MATCHER_INTEGER
802 gint action_type = 0;
805 action_type = MATCHACTION_COLOR;
807 action = filteringaction_new(action_type, 0, NULL, color);
809 | MATCHER_DELETE_ON_SERVER
811 gint action_type = 0;
812 action_type = MATCHACTION_DELETE_ON_SERVER;
813 action = filteringaction_new(action_type, 0, NULL, 0);
818 MATCHER_SCORE MATCHER_INTEGER