Wow. Such data, so leak, very unfreed
[claws.git] / src / matcher.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2002-2014 by the Claws Mail Team and Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifndef MATCHER_H
21 #define MATCHER_H
22
23 #include <sys/types.h>
24 #include <regex.h>
25 #include <glib.h>
26 #include "proctypes.h"
27 #include "matchertypes.h"
28
29 /* constants generated by yacc */
30 #include "matcher_parser_lex.h"
31 #include "matcher_parser_parse.h"
32
33 struct _MatcherProp {
34         int matchtype;
35         int criteria;
36         gchar *header;
37         gchar *expr;
38         int value;
39 #ifndef G_OS_WIN32
40         regex_t *preg;
41 #endif
42         int error;
43         gboolean result;
44         gboolean done;
45 };
46
47 struct _MatcherList {
48         GSList *matchers;
49         gboolean bool_and;
50 };
51
52
53 /* map MATCHCRITERIA_ to yacc's MATCHER_ */
54 #define MC_(name) \
55         MATCHCRITERIA_ ## name = MATCHER_ ## name
56
57 /* map MATCHTYPE_ to yacc's MATCHER_ */
58 #define MT_(name) \
59         MATCHTYPE_ ## name = MATCHER_ ## name
60
61 /* map MATCHACTION_ to yacc's MATCHER_ */
62 #define MA_(name) \
63         MATCHACTION_ ## name = MATCHER_ ## name
64
65 /* map MATCHBOOL_ to yacc's MATCHER_ */
66 #define MB_(name) \
67         MATCHERBOOL_ ## name = MATCHER_ ## name
68
69 enum {
70         /* match */
71         MC_(ALL),
72         MC_(UNREAD), MC_(NOT_UNREAD),
73         MC_(NEW), MC_(NOT_NEW),
74         MC_(MARKED), MC_(NOT_MARKED),
75         MC_(DELETED), MC_(NOT_DELETED),
76         MC_(REPLIED), MC_(NOT_REPLIED),
77         MC_(FORWARDED), MC_(NOT_FORWARDED),
78         MC_(LOCKED), MC_(NOT_LOCKED),
79         MC_(SPAM),MC_(NOT_SPAM),
80         MC_(HAS_ATTACHMENT), MC_(HAS_NO_ATTACHMENT),
81         MC_(SIGNED), MC_(NOT_SIGNED),
82         MC_(PARTIAL), MC_(NOT_PARTIAL),
83         MC_(COLORLABEL), MC_(NOT_COLORLABEL),
84         MC_(IGNORE_THREAD), MC_(NOT_IGNORE_THREAD),
85         MC_(WATCH_THREAD), MC_(NOT_WATCH_THREAD),
86         MC_(SUBJECT), MC_(NOT_SUBJECT),
87         MC_(FROM), MC_(NOT_FROM),
88         MC_(TO), MC_(NOT_TO),
89         MC_(CC), MC_(NOT_CC),
90         MC_(TO_OR_CC), MC_(NOT_TO_AND_NOT_CC),
91         MC_(AGE_GREATER), MC_(AGE_LOWER),
92         MC_(AGE_GREATER_HOURS), MC_(AGE_LOWER_HOURS),
93         MC_(NEWSGROUPS), MC_(NOT_NEWSGROUPS),
94         MC_(MESSAGEID), MC_(NOT_MESSAGEID),
95         MC_(INREPLYTO), MC_(NOT_INREPLYTO),
96         MC_(REFERENCES), MC_(NOT_REFERENCES),
97         MC_(SCORE_GREATER), MC_(SCORE_LOWER),
98         MC_(HEADER), MC_(NOT_HEADER),
99         MC_(HEADERS_PART), MC_(NOT_HEADERS_PART),
100         MC_(HEADERS_CONT), MC_(NOT_HEADERS_CONT),
101         MC_(MESSAGE), MC_(NOT_MESSAGE),
102         MC_(BODY_PART), MC_(NOT_BODY_PART),
103         MC_(TEST), MC_(NOT_TEST),
104         MC_(SCORE_EQUAL),
105         MC_(SIZE_GREATER), 
106         MC_(SIZE_SMALLER),
107         MC_(SIZE_EQUAL),
108         MC_(FOUND_IN_ADDRESSBOOK),MC_(NOT_FOUND_IN_ADDRESSBOOK),
109         MC_(TAG),MC_(NOT_TAG),
110         MC_(TAGGED),MC_(NOT_TAGGED),
111
112         /* match type */
113         MT_(MATCHCASE),
114         MT_(MATCH),
115         MT_(REGEXPCASE),
116         MT_(REGEXP),
117         /* actions */
118         MA_(SCORE),
119         MA_(EXECUTE),
120         MA_(MOVE),
121         MA_(COPY),
122         MA_(DELETE),
123         MA_(MARK),
124         MA_(UNMARK),
125         MA_(LOCK),
126         MA_(UNLOCK),
127         MA_(MARK_AS_READ),
128         MA_(MARK_AS_UNREAD),
129         MA_(MARK_AS_SPAM),
130         MA_(MARK_AS_HAM),
131         MA_(FORWARD),
132         MA_(FORWARD_AS_ATTACHMENT),
133         MA_(COLOR),
134         MA_(REDIRECT),
135         MA_(CHANGE_SCORE),
136         MA_(SET_SCORE),
137         MA_(STOP),
138         MA_(HIDE),
139         MA_(IGNORE),
140         MA_(WATCH),
141         MA_(ADD_TO_ADDRESSBOOK),
142         MA_(SET_TAG),
143         MA_(UNSET_TAG),
144         MA_(CLEAR_TAGS),
145         /* boolean operations */
146         MB_(OR),
147         MB_(AND)
148 };
149
150 void matcher_init(void);
151 void matcher_done(void);
152
153 const gchar *get_matchparser_tab_str    (gint id);
154 gint get_matchparser_tab_id             (const gchar *str); 
155
156 MatcherProp *matcherprop_new            (gint            criteria, 
157                                          const gchar    *header,
158                                          gint            matchtype, 
159                                          const gchar    *expr,
160                                          int             value);
161 void matcherprop_free                   (MatcherProp *prop);
162
163 MatcherProp *matcherprop_parse          (gchar  **str);
164
165 MatcherProp *matcherprop_copy           (const MatcherProp *src);
166
167 MatcherList * matcherlist_new           (GSList         *matchers, 
168                                          gboolean       bool_and);
169 MatcherList * matcherlist_new_from_lines(gchar          *lines,
170                                          gboolean       bool_and,
171                                          gboolean       case_sensitive);
172 void matcherlist_free                   (MatcherList    *cond);
173
174 MatcherList *matcherlist_parse          (gchar          **str);
175
176 gboolean matcherlist_match              (MatcherList    *cond, 
177                                          MsgInfo        *info);
178
179 gint matcher_parse_keyword              (gchar          **str);
180 gint matcher_parse_number               (gchar          **str);
181 gboolean matcher_parse_boolean_op       (gchar          **str);
182 gchar *matcher_parse_regexp             (gchar          **str);
183 gchar *matcher_parse_str                (gchar          **str);
184 gchar *matcherprop_to_string            (MatcherProp    *matcher);
185 gchar *matcherlist_to_string            (const MatcherList      *matchers);
186 gchar *matching_build_command           (const gchar    *cmd, 
187                                          MsgInfo        *info);
188
189 void prefs_matcher_read_config          (void);
190 void prefs_matcher_write_config         (void);
191
192 gchar * matcher_quote_str(const gchar * src);
193
194 #endif