revise label colouring, add filter action for label colouring, fix filtering issues
[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_COLOR,
74         /* MATCHING_ACTION_EXECUTE, */
75
76         MATCHING_MATCH,
77         MATCHING_REGEXP,
78         MATCHING_MATCHCASE,
79         MATCHING_REGEXPCASE
80 };
81
82 struct _MatcherProp {
83         int matchtype;
84         int criteria;
85         gchar * header;
86         gchar * expr;
87         int value;
88         regex_t * preg;
89         int error;
90         gboolean result;
91 };
92
93 typedef struct _MatcherProp MatcherProp;
94
95 struct _MatcherList {
96         GSList * matchers;
97         gboolean bool_and;
98 };
99
100 typedef struct _MatcherList MatcherList;
101
102 gchar * get_matchparser_tab_str(gint id);
103 MatcherProp * matcherprop_new(gint criteria, gchar * header,
104                               gint matchtype, gchar * expr,
105                               int age);
106 void matcherprop_free(MatcherProp * prop);
107 MatcherProp * matcherprop_parse(gchar ** str);
108
109 gboolean matcherprop_match(MatcherProp * prop, MsgInfo * info);
110
111 MatcherList * matcherlist_new(GSList * matchers, gboolean bool_and);
112 void matcherlist_free(MatcherList * cond);
113 MatcherList * matcherlist_parse(gchar ** str);
114
115 gboolean matcherlist_match(MatcherList * cond, MsgInfo * info);
116
117 gint matcher_parse_keyword(gchar ** str);
118 gint matcher_parse_number(gchar ** str);
119 gboolean matcher_parse_boolean_op(gchar ** str);
120 gchar * matcher_parse_regexp(gchar ** str);
121 gchar * matcher_parse_str(gchar ** str);
122 gchar * matcher_unescape_str(gchar *str);
123 gchar * matcherprop_to_string(MatcherProp * matcher);
124 gchar * matcherlist_to_string(MatcherList * matchers);
125 gchar * matching_build_command(gchar * cmd, MsgInfo * info);
126
127 #endif