new filtering
[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
58         /* scoring */
59         MATCHING_SCORE,
60
61         /* filtering */
62         MATCHING_ACTION_MOVE,
63         MATCHING_ACTION_COPY,
64         MATCHING_ACTION_DELETE,
65         MATCHING_ACTION_MARK,
66         MATCHING_ACTION_MARK_AS_READ,
67         MATCHING_ACTION_UNMARK,
68         MATCHING_ACTION_MARK_AS_UNREAD,
69         MATCHING_ACTION_FORWARD,
70         MATCHING_ACTION_FORWARD_AS_ATTACHEMENT,
71         MATCHING_ACTION_FORWARD_NEWS,
72         MATCHING_ACTION_FORWARD_NEWS_AS_ATTACHEMENT,
73
74         MATCHING_MATCH,
75         MATCHING_REGEXP,
76         MATCHING_MATCHCASE,
77         MATCHING_REGEXPCASE
78 };
79
80 struct _MatcherProp {
81         int matchtype;
82         int criteria;
83         gchar * header;
84         gchar * expr;
85         int value;
86         regex_t * preg;
87         int error;
88 };
89
90 typedef struct _MatcherProp MatcherProp;
91
92 struct _MatcherList {
93         GSList * matchers;
94         gboolean bool_and;
95 };
96
97 typedef struct _MatcherList MatcherList;
98
99 gchar * get_matchparser_tab_str(gint id);
100 MatcherProp * matcherprop_new(gint criteria, gchar * header,
101                               gint matchtype, gchar * expr,
102                               int age);
103 void matcherprop_free(MatcherProp * prop);
104 MatcherProp * matcherprop_parse(gchar ** str);
105
106 gboolean matcherprop_match(MatcherProp * prop, MsgInfo * info);
107
108 MatcherList * matcherlist_new(GSList * matchers, gboolean bool_and);
109 void matcherlist_free(MatcherList * cond);
110 MatcherList * matcherlist_parse(gchar ** str);
111
112 gboolean matcherlist_match(MatcherList * cond, MsgInfo * info);
113
114 gint matcher_parse_keyword(gchar ** str);
115 gint matcher_parse_number(gchar ** str);
116 gboolean matcher_parse_boolean_op(gchar ** str);
117 gchar * matcher_parse_regexp(gchar ** str);
118 gchar * matcher_parse_str(gchar ** str);
119 gchar * matcherprop_to_string(MatcherProp * matcher);
120 gchar * matcherlist_to_string(MatcherList * matchers);
121
122 #endif