Committing reverts
[claws.git] / src / matcher.h
1 #ifndef MATCHER_H
2
3 #define MATCHER_H
4
5 #include <sys/types.h>
6 #include <regex.h>
7 #include <glib.h>
8 #include "procmsg.h"
9
10 enum {
11         /* msginfo flags */
12         MATCHING_ALL,
13         MATCHING_UNREAD,
14         MATCHING_NOT_UNREAD,
15         MATCHING_NEW,
16         MATCHING_NOT_NEW,
17         MATCHING_MARKED,
18         MATCHING_NOT_MARKED,
19         MATCHING_DELETED,
20         MATCHING_NOT_DELETED,
21         MATCHING_REPLIED,
22         MATCHING_NOT_REPLIED,
23         MATCHING_FORWARDED,
24         MATCHING_NOT_FORWARDED,
25
26         /* msginfo headers */
27         MATCHING_SUBJECT,
28         MATCHING_NOT_SUBJECT,
29         MATCHING_FROM,
30         MATCHING_NOT_FROM,
31         MATCHING_TO,
32         MATCHING_NOT_TO,
33         MATCHING_CC,
34         MATCHING_NOT_CC,
35         MATCHING_TO_OR_CC,
36         MATCHING_NOT_TO_AND_NOT_CC,
37         MATCHING_AGE_GREATER,
38         MATCHING_AGE_LOWER,
39         MATCHING_NEWSGROUPS,
40         MATCHING_NOT_NEWSGROUPS,
41         MATCHING_INREPLYTO,
42         MATCHING_NOT_INREPLYTO,
43         MATCHING_REFERENCES,
44         MATCHING_NOT_REFERENCES,
45         MATCHING_SCORE_GREATER,
46         MATCHING_SCORE_LOWER,
47
48         /* file content */
49         MATCHING_HEADER,
50         MATCHING_NOT_HEADER,
51         MATCHING_MESSAGE,
52         MATCHING_NOT_MESSAGE,
53         MATCHING_HEADERS_PART,
54         MATCHING_NOT_HEADERS_PART,
55         MATCHING_BODY_PART,
56         MATCHING_NOT_BODY_PART,
57         MATCHING_EXECUTE,
58         MATCHING_NOT_EXECUTE,
59
60         /* scoring */
61         MATCHING_SCORE,
62
63         /* filtering */
64         MATCHING_ACTION_MOVE,
65         MATCHING_ACTION_COPY,
66         MATCHING_ACTION_DELETE,
67         MATCHING_ACTION_MARK,
68         MATCHING_ACTION_MARK_AS_READ,
69         MATCHING_ACTION_UNMARK,
70         MATCHING_ACTION_MARK_AS_UNREAD,
71         MATCHING_ACTION_FORWARD,
72         MATCHING_ACTION_FORWARD_AS_ATTACHMENT,
73         /* MATCHING_ACTION_EXECUTE, */
74
75         MATCHING_MATCH,
76         MATCHING_REGEXP,
77         MATCHING_MATCHCASE,
78         MATCHING_REGEXPCASE
79 };
80
81 struct _MatcherProp {
82         int matchtype;
83         int criteria;
84         gchar * header;
85         gchar * expr;
86         int value;
87         regex_t * preg;
88         int error;
89         gboolean result;
90 };
91
92 typedef struct _MatcherProp MatcherProp;
93
94 struct _MatcherList {
95         GSList * matchers;
96         gboolean bool_and;
97 };
98
99 typedef struct _MatcherList MatcherList;
100
101 gchar * get_matchparser_tab_str(gint id);
102 MatcherProp * matcherprop_new(gint criteria, gchar * header,
103                               gint matchtype, gchar * expr,
104                               int age);
105 void matcherprop_free(MatcherProp * prop);
106 MatcherProp * matcherprop_parse(gchar ** str);
107
108 gboolean matcherprop_match(MatcherProp * prop, MsgInfo * info);
109
110 MatcherList * matcherlist_new(GSList * matchers, gboolean bool_and);
111 void matcherlist_free(MatcherList * cond);
112 MatcherList * matcherlist_parse(gchar ** str);
113
114 gboolean matcherlist_match(MatcherList * cond, MsgInfo * info);
115
116 gint matcher_parse_keyword(gchar ** str);
117 gint matcher_parse_number(gchar ** str);
118 gboolean matcher_parse_boolean_op(gchar ** str);
119 gchar * matcher_parse_regexp(gchar ** str);
120 gchar * matcher_parse_str(gchar ** str);
121 gchar * matcherprop_to_string(MatcherProp * matcher);
122 gchar * matcherlist_to_string(MatcherList * matchers);
123 gchar * matching_build_command(gchar * cmd, MsgInfo * info);
124
125 #endif