2006-12-12 [paul] 2.6.1cvs21
[claws.git] / src / matcher.h
blob8b3f1ce984a24b80999f03dc29f3faccd28e2ead
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2002 by the Claws Mail Team and Hiroyuki Yamamoto
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #ifndef MATCHER_H
21 #define MATCHER_H
23 #include <sys/types.h>
24 #include <regex.h>
25 #include <glib.h>
26 #include "procmsg.h"
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
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 gboolean done;
46 typedef struct _MatcherProp MatcherProp;
48 struct _MatcherList {
49 GSList *matchers;
50 gboolean bool_and;
53 typedef struct _MatcherList MatcherList;
56 /* map MATCHCRITERIA_ to yacc's MATCHER_ */
57 #define MC_(name) \
58 MATCHCRITERIA_ ## name = MATCHER_ ## name
60 /* map MATCHTYPE_ to yacc's MATCHER_ */
61 #define MT_(name) \
62 MATCHTYPE_ ## name = MATCHER_ ## name
64 /* map MATCHACTION_ to yacc's MATCHER_ */
65 #define MA_(name) \
66 MATCHACTION_ ## name = MATCHER_ ## name
68 /* map MATCHBOOL_ to yacc's MATCHER_ */
69 #define MB_(name) \
70 MATCHERBOOL_ ## name = MATCHER_ ## name
72 enum {
73 /* match */
74 MC_(ALL),
75 MC_(UNREAD), MC_(NOT_UNREAD),
76 MC_(NEW), MC_(NOT_NEW),
77 MC_(MARKED), MC_(NOT_MARKED),
78 MC_(DELETED), MC_(NOT_DELETED),
79 MC_(REPLIED), MC_(NOT_REPLIED),
80 MC_(FORWARDED), MC_(NOT_FORWARDED),
81 MC_(LOCKED), MC_(NOT_LOCKED),
82 MC_(PARTIAL), MC_(NOT_PARTIAL),
83 MC_(COLORLABEL), MC_(NOT_COLORLABEL),
84 MC_(IGNORE_THREAD), MC_(NOT_IGNORE_THREAD),
85 MC_(SUBJECT), MC_(NOT_SUBJECT),
86 MC_(FROM), MC_(NOT_FROM),
87 MC_(TO), MC_(NOT_TO),
88 MC_(CC), MC_(NOT_CC),
89 MC_(TO_OR_CC), MC_(NOT_TO_AND_NOT_CC),
90 MC_(AGE_GREATER), MC_(AGE_LOWER),
91 MC_(NEWSGROUPS), MC_(NOT_NEWSGROUPS),
92 MC_(INREPLYTO), MC_(NOT_INREPLYTO),
93 MC_(REFERENCES), MC_(NOT_REFERENCES),
94 MC_(SCORE_GREATER), MC_(SCORE_LOWER),
95 MC_(HEADER), MC_(NOT_HEADER),
96 MC_(HEADERS_PART), MC_(NOT_HEADERS_PART),
97 MC_(MESSAGE), MC_(NOT_MESSAGE),
98 MC_(BODY_PART), MC_(NOT_BODY_PART),
99 MC_(TEST), MC_(NOT_TEST),
100 MC_(SCORE_EQUAL),
101 MC_(SIZE_GREATER),
102 MC_(SIZE_SMALLER),
103 MC_(SIZE_EQUAL),
104 MC_(FOUND_IN_ADDRESSBOOK),MC_(NOT_FOUND_IN_ADDRESSBOOK),
105 /* match type */
106 MT_(MATCHCASE),
107 MT_(MATCH),
108 MT_(REGEXPCASE),
109 MT_(REGEXP),
110 /* actions */
111 MA_(SCORE),
112 MA_(EXECUTE),
113 MA_(MOVE),
114 MA_(COPY),
115 MA_(DELETE),
116 MA_(MARK),
117 MA_(UNMARK),
118 MA_(LOCK),
119 MA_(UNLOCK),
120 MA_(MARK_AS_READ),
121 MA_(MARK_AS_UNREAD),
122 MA_(FORWARD),
123 MA_(FORWARD_AS_ATTACHMENT),
124 MA_(COLOR),
125 MA_(REDIRECT),
126 MA_(CHANGE_SCORE),
127 MA_(SET_SCORE),
128 MA_(STOP),
129 MA_(HIDE),
130 MA_(IGNORE),
131 /* boolean operations */
132 MB_(OR),
133 MB_(AND)
136 const gchar *get_matchparser_tab_str (gint id);
137 gint get_matchparser_tab_id (const gchar *str);
139 MatcherProp *matcherprop_new (gint criteria,
140 const gchar *header,
141 gint matchtype,
142 const gchar *expr,
143 int value);
144 void matcherprop_free (MatcherProp *prop);
146 MatcherProp *matcherprop_parse (gchar **str);
148 MatcherProp *matcherprop_copy (const MatcherProp *src);
150 gboolean matcherprop_match (MatcherProp *prop,
151 MsgInfo *info);
153 MatcherList * matcherlist_new (GSList *matchers,
154 gboolean bool_and);
155 void matcherlist_free (MatcherList *cond);
157 MatcherList *matcherlist_parse (gchar **str);
159 gboolean matcherlist_match (MatcherList *cond,
160 MsgInfo *info);
162 gint matcher_parse_keyword (gchar **str);
163 gint matcher_parse_number (gchar **str);
164 gboolean matcher_parse_boolean_op (gchar **str);
165 gchar *matcher_parse_regexp (gchar **str);
166 gchar *matcher_parse_str (gchar **str);
167 gchar *matcherprop_to_string (MatcherProp *matcher);
168 gchar *matcherlist_to_string (const MatcherList *matchers);
169 gchar *matching_build_command (const gchar *cmd,
170 MsgInfo *info);
172 void prefs_matcher_read_config (void);
173 void prefs_matcher_write_config (void);
175 gchar * matcher_quote_str(const gchar * src);
177 #endif