-
Notifications
You must be signed in to change notification settings - Fork 8
/
filter.h
364 lines (312 loc) · 8.32 KB
/
filter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/***************************************************************************
SimpleMail - Copyright (C) 2000 Hynek Schlawack and Sebastian Bauer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
#ifndef SM__FILTER_H
#define SM__FILTER_H
#include <stdio.h>
#ifndef SM__LISTS_H
#include "lists.h"
#endif
#ifndef SM__BAYERMOORE_H
#include "boyermoore.h"
#endif
#define RULE_FROM_MATCH 0
#define RULE_RCPT_MATCH 1
#define RULE_SUBJECT_MATCH 2
#define RULE_HEADER_MATCH 3
#define RULE_ATTACHMENT_MATCH 4
#define RULE_STATUS_MATCH 5
#define RULE_BODY_MATCH 6
#define RULE_STATUS_NEW 0
#define RULE_STATUS_READ 1
#define RULE_STATUS_UNREAD 2
#define RULE_STATUS_REPLIED 3
#define RULE_STATUS_FORWARDED 4
#define RULE_STATUS_PENDING 5
#define RULE_STATUS_SENT 6
/**
* @brief A processed filter rule.
*/
struct filter_rule_parsed
{
struct boyermoore_context *bm_context;
char *parsed; /* result from sm_parse_pattern() */
};
struct filter_rule
{
struct node node; /* embedded node structure */
int type; /* type of the rule */
int flags; /* flags for the pattern matching rules (see indep-include/support.h/SM_PATTERN_#?) */
union
{
struct {
char **from; /* NULL terminated array */
char **from_pat; /* NULL terminated array, result from sm_parse_pattern() */
} from;
struct {
char **rcpt; /* NULL terminated array */
char **rcpt_pat; /* NULL terminated array, result from sm_parse_pattern() */
} rcpt;
struct {
char **subject; /* NULL terminated array */
char **subject_pat; /* NULL terminated array, result from sm_parse_pattern() */
} subject;
struct {
char *name;
char *name_pat; /* result from sm_parse_pattern() */
char **contents; /* NULL terminated array */
char **contents_pat; /* NULL terminated array, result from sm_parse_pattern() */
} header;
struct {
char *body; /* string */
struct filter_rule_parsed body_parsed;
} body;
struct {
int status;
} status;
} u;
};
struct filter_action
{
struct node node; /* embedded node structure */
int type; /* type of that action */
};
#define FILTER_FLAG_REQUEST (1<<0)
#define FILTER_FLAG_NEW (1<<1)
#define FILTER_FLAG_SENT (1<<2)
#define FILTER_FLAG_REMOTE (1<<3)
struct filter
{
struct node node; /* embedded node structure */
char *name; /* name of the filter */
int flags; /* activity flags of the filter */
int mode; /* 0=and - 1=or */
struct list rules_list; /* list of rules */
char *dest_folder; /* Move the mail into the given folder */
int use_dest_folder; /* If set to 1 */
char *sound_file; /* Play a sound file */
int use_sound_file; /* If set to 1 */
char *arexx_file; /* Execute ARexx Script */
int use_arexx_file; /* If set to 1 */
int search_filter; /* filter is a search filter (used for the search function) */
struct list action_list; /* list of actions */
};
/**
* Creates a new filter instance with default values.
*
* @return
*/
struct filter *filter_create(void);
/**
* Duplicates a filter instance.
*
* @param filter
* @return
*/
struct filter *filter_duplicate(struct filter *filter);
/**
* Disposes the filter and all associated rules.
*
* @param f
*/
void filter_dispose(struct filter *filter);
/**
* Deinitializes the parsed filter rule. Does not free the rule!
*
* @param p
*/
void filter_deinit_rule(struct filter_rule_parsed *p);
/**
* Initializes the given filter rule for the given str with flags.
*
* @param p
* @param str
* @param flags
*/
void filter_init_rule(struct filter_rule_parsed *p, char *str, int flags);
/**
* Match the given str againt the parsed filter.
*
* @param p
* @param str should be 0-byte terminated even if strl is given.
* @param strl length of the string.
* @param flags
* @return
*/
int filter_match_rule_len(struct filter_rule_parsed *p, char *str, int strl, int flags);
/**
* Adds the given rule to the filter.
*
* @param filter
* @param fr
*/
void filter_add_rule(struct filter *filter, struct filter_rule *fr);
/**
* Creates and adds a rule of the given type to the given filter.
*
* @param filter
* @param type
* @return
*/
struct filter_rule *filter_create_and_add_rule(struct filter *filter, int type);
/**
* Adds the copy of the given text to the filter rule if rule
* is a text rule.
*
* @param r
* @param text
*/
void filter_rule_add_copy_of_string(struct filter_rule *fr, char *text);
/**
* Create a filter rule that matches the given set of strings.
*
* @param strings
* @param num_strings
* @param flags
* @return
*/
struct filter_rule *filter_rule_create_from_strings(char **strings, int num_strings, int flags);
/**
* Create a filter rule from common sorted recipients.
*
* @param addresses an array to an array of sorted recipients.
* @param num_addresses length of addresses.
* @param type
* @return
*/
struct filter_rule *filter_rule_create_from_common_sorted_recipients(char ***addresses, unsigned int num_addresses);
enum filter_rule_create_type
{
FRCT_RECEPIENTS,
FRCT_SUBJECT,
FRCT_FROM
};
struct mail_info;
/**
* Create filter rule of the specific type from a mail iteration.
*
* @param get_first_mail_info
* @param get_next_mail_info
* @param num_mails
* @param type
* @return
*/
struct filter_rule *filter_rule_create_from_mail_iterator(enum filter_rule_create_type type, int num_mails,
struct mail_info * (*get_first_mail_info)(void *handle, void *userdata),
struct mail_info * (*get_next_mail_info)(void *handle, void *userdata),
void *userdata);
/**
* Return the num-th rule of the given filter.
*
* @param filter
* @param num
* @return
*/
struct filter_rule *filter_find_rule(struct filter *filter, int num);
/**
* Remove the rule from its filter.
*
* @param fr
*/
void filter_remove_rule(struct filter_rule *fr);
/**
* Preprocesses the pattern of all rules of the given filter
*
* @param f the filter of which the rules should be processed
*/
void filter_parse_filter_rules(struct filter *f);
/**
* Preparse the pattern of all filters.
*/
void filter_parse_all_filters(void);
/**
* Returns the num-th action of the given filter.
*
* @param filter
* @param num
* @return
*/
struct filter_action *filter_find_action(struct filter *filter, int num);
/**
* Clear the global configuration filter list.
*/
void filter_list_clear(void);
/**
* Adds a duplicate of the filter to the global filter list
*
* @param f
*/
void filter_list_add_duplicate(struct filter *);
/**
* Get the first filter of the global filter list.
*
* @return
*/
struct filter *filter_list_first(void);
/**
* Returns the next filter of the given filter.
*
* @param f
* @return
*/
struct filter *filter_list_next(struct filter *f);
/**
* Returns whether the global filter list contains any remote filters.
*
* @return
*/
int filter_list_has_remote(void);
/**
* Loads the filter list from the already fopen()'ed filehandle.
*
* @param fh
*/
void filter_list_load(FILE *fh);
/**
* Saves the filter list into the given handle that has been opened with
* fopen() before.
*
* @param fh
*/
void filter_list_save(FILE *fh);
struct search_options
{
char *folder; /* NULL means all folders */
char *from;
char *to;
char *subject;
char *body;
};
/**
* Duplicates the given search option.
*
* @param so
* @return
*/
struct search_options *search_options_duplicate(struct search_options *so);
/**
* Frees all memory associated with the given search options.
*
* @param so
*/
void search_options_free(struct search_options *so);
/**
* Create a filter from search options.
*
* @param sopt the search options from which to create the filter.
*
* @return the created filter
*/
struct filter *filter_create_from_search_options(struct search_options *sopt);
#endif