check for return value when setting G_MESSAGES_DEBUG
[claws.git] / src / matcher.h
blob8a068bb19927e63cb445f7eb18f5f6d79d67c6ab
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2002-2014 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 3 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, see <http://www.gnu.org/licenses/>.
20 #ifndef MATCHER_H
21 #define MATCHER_H
23 #include <sys/types.h>
24 #include <regex.h>
25 #include <glib.h>
26 #include "proctypes.h"
27 #include "matchertypes.h"
29 /* constants generated by yacc */
30 #include "matcher_parser_lex.h"
31 #include "matcher_parser_parse.h"
33 struct _MatcherProp {
34 int matchtype;
35 int criteria;
36 gchar *header;
37 gchar *expr;
38 int value;
39 int error;
40 gboolean result;
41 gboolean done;
42 /* Allows recompiling expr each time */
43 regex_t *preg;
44 /* Allows casefolding expr each time */
45 gchar *casefold_expr;
48 struct _MatcherList {
49 GSList *matchers;
50 gboolean bool_and;
54 /* map MATCHCRITERIA_ to yacc's MATCHER_ */
55 #define MC_(name) \
56 MATCHCRITERIA_ ## name = MATCHER_ ## name
58 /* map MATCHTYPE_ to yacc's MATCHER_ */
59 #define MT_(name) \
60 MATCHTYPE_ ## name = MATCHER_ ## name
62 /* map MATCHACTION_ to yacc's MATCHER_ */
63 #define MA_(name) \
64 MATCHACTION_ ## name = MATCHER_ ## name
66 /* map MATCHBOOL_ to yacc's MATCHER_ */
67 #define MB_(name) \
68 MATCHERBOOL_ ## name = MATCHER_ ## name
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_(SPAM),MC_(NOT_SPAM),
81 MC_(HAS_ATTACHMENT), MC_(HAS_NO_ATTACHMENT),
82 MC_(SIGNED), MC_(NOT_SIGNED),
83 MC_(PARTIAL), MC_(NOT_PARTIAL),
84 MC_(COLORLABEL), MC_(NOT_COLORLABEL),
85 MC_(IGNORE_THREAD), MC_(NOT_IGNORE_THREAD),
86 MC_(WATCH_THREAD), MC_(NOT_WATCH_THREAD),
87 MC_(SUBJECT), MC_(NOT_SUBJECT),
88 MC_(FROM), MC_(NOT_FROM),
89 MC_(TO), MC_(NOT_TO),
90 MC_(CC), MC_(NOT_CC),
91 MC_(TO_OR_CC), MC_(NOT_TO_AND_NOT_CC),
92 MC_(AGE_GREATER), MC_(AGE_LOWER),
93 MC_(AGE_GREATER_HOURS), MC_(AGE_LOWER_HOURS),
94 MC_(DATE_AFTER), MC_(DATE_BEFORE),
95 MC_(NEWSGROUPS), MC_(NOT_NEWSGROUPS),
96 MC_(MESSAGEID), MC_(NOT_MESSAGEID),
97 MC_(INREPLYTO), MC_(NOT_INREPLYTO),
98 MC_(REFERENCES), MC_(NOT_REFERENCES),
99 MC_(SCORE_GREATER), MC_(SCORE_LOWER),
100 MC_(HEADER), MC_(NOT_HEADER),
101 MC_(HEADERS_PART), MC_(NOT_HEADERS_PART),
102 MC_(HEADERS_CONT), MC_(NOT_HEADERS_CONT),
103 MC_(MESSAGE), MC_(NOT_MESSAGE),
104 MC_(BODY_PART), MC_(NOT_BODY_PART),
105 MC_(TEST), MC_(NOT_TEST),
106 MC_(SCORE_EQUAL),
107 MC_(SIZE_GREATER),
108 MC_(SIZE_SMALLER),
109 MC_(SIZE_EQUAL),
110 MC_(FOUND_IN_ADDRESSBOOK),MC_(NOT_FOUND_IN_ADDRESSBOOK),
111 MC_(TAG),MC_(NOT_TAG),
112 MC_(TAGGED),MC_(NOT_TAGGED),
114 /* match type */
115 MT_(MATCHCASE),
116 MT_(MATCH),
117 MT_(REGEXPCASE),
118 MT_(REGEXP),
119 /* actions */
120 MA_(SCORE),
121 MA_(EXECUTE),
122 MA_(MOVE),
123 MA_(COPY),
124 MA_(DELETE),
125 MA_(MARK),
126 MA_(UNMARK),
127 MA_(LOCK),
128 MA_(UNLOCK),
129 MA_(MARK_AS_READ),
130 MA_(MARK_AS_UNREAD),
131 MA_(MARK_AS_SPAM),
132 MA_(MARK_AS_HAM),
133 MA_(FORWARD),
134 MA_(FORWARD_AS_ATTACHMENT),
135 MA_(COLOR),
136 MA_(REDIRECT),
137 MA_(CHANGE_SCORE),
138 MA_(SET_SCORE),
139 MA_(STOP),
140 MA_(HIDE),
141 MA_(IGNORE),
142 MA_(WATCH),
143 MA_(ADD_TO_ADDRESSBOOK),
144 MA_(SET_TAG),
145 MA_(UNSET_TAG),
146 MA_(CLEAR_TAGS),
147 /* boolean operations */
148 MB_(OR),
149 MB_(AND)
152 void matcher_init(void);
153 void matcher_done(void);
155 const gchar *get_matchparser_tab_str (gint id);
156 gint get_matchparser_tab_id (const gchar *str);
158 MatcherProp *matcherprop_new (gint criteria,
159 const gchar *header,
160 gint matchtype,
161 const gchar *expr,
162 int value);
163 void matcherprop_free (MatcherProp *prop);
165 MatcherProp *matcherprop_parse (gchar **str);
167 MatcherProp *matcherprop_copy (const MatcherProp *src);
169 MatcherList * matcherlist_new (GSList *matchers,
170 gboolean bool_and);
171 MatcherList * matcherlist_new_from_lines(gchar *lines,
172 gboolean bool_and,
173 gboolean case_sensitive);
174 void matcherlist_free (MatcherList *cond);
176 MatcherList *matcherlist_parse (gchar **str);
178 gboolean matcherlist_match (MatcherList *cond,
179 MsgInfo *info);
181 gint matcher_parse_keyword (gchar **str);
182 gint matcher_parse_number (gchar **str);
183 gboolean matcher_parse_boolean_op (gchar **str);
184 gchar *matcher_parse_regexp (gchar **str);
185 gchar *matcher_parse_str (gchar **str);
186 gchar *matcherprop_to_string (MatcherProp *matcher);
187 gchar *matcherlist_to_string (const MatcherList *matchers);
188 gchar *matching_build_command (const gchar *cmd,
189 MsgInfo *info);
191 void prefs_matcher_read_config (void);
192 void prefs_matcher_write_config (void);
194 gchar * matcher_quote_str(const gchar * src);
196 #endif