New icons for LDAP static search
[claws.git] / src / matcher.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2002 by the Sylpheed Claws 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 2 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, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 "procmsg.h"
27
28 /* constants generated by yacc */
29 #if !defined(YYBISON) && !defined(MATCHER_ALL)
30 #       include "matcher_parser_parse.h"
31 #endif
32
33 struct _MatcherProp {
34         int matchtype;
35         int criteria;
36         gchar *header;
37         gchar *expr;
38         int value;
39         regex_t *preg;
40         int error;
41         gboolean result;
42 };
43
44 typedef struct _MatcherProp MatcherProp;
45
46 struct _MatcherList {
47         GSList *matchers;
48         gboolean bool_and;
49 };
50
51 typedef struct _MatcherList MatcherList;
52
53
54 /* map MATCHCRITERIA_ to yacc's MATCHER_ */
55 #define MC_(name) \
56         MATCHCRITERIA_ ## name = MATCHER_ ## name
57
58 /* map MATCHTYPE_ to yacc's MATCHER_ */
59 #define MT_(name) \
60         MATCHTYPE_ ## name = MATCHER_ ## name
61
62 /* map MATCHACTION_ to yacc's MATCHER_ */
63 #define MA_(name) \
64         MATCHACTION_ ## name = MATCHER_ ## name
65
66 /* map MATCHBOOL_ to yacc's MATCHER_ */
67 #define MB_(name) \
68         MATCHERBOOL_ ## name = MATCHER_ ## name
69
70 enum {
71         /* match */
72         MC_(ALL),
73         MC_(UNREAD), MC_(NOT_UNREAD),
74         MC_(NEW), MC_(NOT_NEW),
75         MC_(MARKED), MC_(NOT_MARKED),
76         MC_(DELETED), MC_(NOT_DELETED),
77         MC_(REPLIED), MC_(NOT_REPLIED),
78         MC_(FORWARDED), MC_(NOT_FORWARDED),
79         MC_(LOCKED), MC_(NOT_LOCKED),
80         MC_(COLORLABEL), MC_(NOT_COLORLABEL),
81         MC_(IGNORE_THREAD), MC_(NOT_IGNORE_THREAD),
82         MC_(SUBJECT), MC_(NOT_SUBJECT),
83         MC_(FROM), MC_(NOT_FROM),
84         MC_(TO), MC_(NOT_TO),
85         MC_(CC), MC_(NOT_CC),
86         MC_(TO_OR_CC), MC_(NOT_TO_AND_NOT_CC),
87         MC_(AGE_GREATER), MC_(AGE_LOWER),
88         MC_(NEWSGROUPS), MC_(NOT_NEWSGROUPS),
89         MC_(INREPLYTO), MC_(NOT_INREPLYTO),
90         MC_(REFERENCES), MC_(NOT_REFERENCES),
91         MC_(SCORE_GREATER), MC_(SCORE_LOWER),
92         MC_(HEADER), MC_(NOT_HEADER),
93         MC_(HEADERS_PART), MC_(NOT_HEADERS_PART),
94         MC_(MESSAGE), MC_(NOT_MESSAGE),
95         MC_(BODY_PART), MC_(NOT_BODY_PART),
96         MC_(EXECUTE), MC_(NOT_EXECUTE),
97         MC_(SCORE_EQUAL),
98         MC_(SIZE_GREATER), 
99         MC_(SIZE_SMALLER),
100         MC_(SIZE_EQUAL),
101         /* match type */
102         MT_(MATCHCASE),
103         MT_(MATCH),
104         MT_(REGEXPCASE),
105         MT_(REGEXP),
106         /* actions */
107         MA_(SCORE),
108         MA_(EXECUTE),
109         MA_(MOVE),
110         MA_(COPY),
111         MA_(DELETE),
112         MA_(MARK),
113         MA_(UNMARK),
114         MA_(LOCK),
115         MA_(UNLOCK),
116         MA_(MARK_AS_READ),
117         MA_(MARK_AS_UNREAD),
118         MA_(FORWARD),
119         MA_(FORWARD_AS_ATTACHMENT),
120         MA_(COLOR),
121         MA_(REDIRECT),
122         MA_(CHANGE_SCORE),
123         /* boolean operations */
124         MB_(OR),
125         MB_(AND)
126 };
127
128 const gchar *get_matchparser_tab_str    (gint id);
129 gint get_matchparser_tab_id             (const gchar *str); 
130
131 MatcherProp *matcherprop_new            (gint            criteria, 
132                                          const gchar    *header,
133                                          gint            matchtype, 
134                                          const gchar    *expr,
135                                          int             value);
136 MatcherProp *matcherprop_unquote_new    (gint            criteria, 
137                                          const gchar    *header,
138                                          gint            matchtype, 
139                                          const gchar    *expr,
140                                          int             value);
141 void matcherprop_free                   (MatcherProp *prop);
142
143 MatcherProp *matcherprop_parse          (gchar  **str);
144
145 MatcherProp *matcherprop_copy           (const MatcherProp *src);
146
147 gboolean matcherprop_match              (MatcherProp    *prop, 
148                                          MsgInfo        *info);
149
150 MatcherList * matcherlist_new           (GSList         *matchers, 
151                                          gboolean       bool_and);
152 void matcherlist_free                   (MatcherList    *cond);
153
154 MatcherList *matcherlist_parse          (gchar          **str);
155
156 gboolean matcherlist_match              (MatcherList    *cond, 
157                                          MsgInfo        *info);
158
159 gint matcher_parse_keyword              (gchar          **str);
160 gint matcher_parse_number               (gchar          **str);
161 gboolean matcher_parse_boolean_op       (gchar          **str);
162 gchar *matcher_parse_regexp             (gchar          **str);
163 gchar *matcher_parse_str                (gchar          **str);
164 gchar *matcher_escape_str               (const gchar    *str);
165 gchar *matcher_unescape_str             (gchar          *str);
166 gchar *matcherprop_to_string            (MatcherProp    *matcher);
167 gchar *matcherlist_to_string            (const MatcherList      *matchers);
168 gchar *matching_build_command           (const gchar    *cmd, 
169                                          MsgInfo        *info);
170
171 void prefs_matcher_read_config          (void);
172 void prefs_matcher_write_config         (void);
173 void *matcher_parser_scan_string        (gchar          *str);
174
175 #endif