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