1 |
lefcha |
1.1 |
#ifndef FILTER_H |
2 |
|
|
#define FILTER_H |
3 |
|
|
|
4 |
|
|
|
5 |
|
|
#include <regex.h> |
6 |
|
|
|
7 |
|
|
#include "account.h" |
8 |
|
|
|
9 |
|
|
|
10 |
|
|
/* |
11 |
|
|
* Mode for masks that comprise a filter. So if a filter is of AND type then |
12 |
|
|
* as default masks are ANDed. |
13 |
|
|
*/ |
14 |
|
|
#define FILTER_MODE_OR 1 |
15 |
|
|
#define FILTER_MODE_AND 2 |
16 |
|
|
|
17 |
|
|
/* Action to do in case of filter matching. */ |
18 |
|
|
#define FILTER_ACTION_DELETE 1 |
19 |
|
|
#define FILTER_ACTION_COPY 2 |
20 |
|
|
#define FILTER_ACTION_MOVE 3 |
21 |
|
|
#define FILTER_ACTION_RCOPY 4 |
22 |
|
|
#define FILTER_ACTION_RMOVE 5 |
23 |
|
|
#define FILTER_ACTION_FLAG_REPLACE 6 |
24 |
|
|
#define FILTER_ACTION_FLAG_ADD 7 |
25 |
|
|
#define FILTER_ACTION_FLAG_REMOVE 8 |
26 |
|
|
#define FILTER_ACTION_LIST 9 |
27 |
|
|
|
28 |
|
|
/* Message flags to replace/add/remove. */ |
29 |
|
|
#define MESSAGE_FLAG_NONE 0x00 |
30 |
|
|
#define MESSAGE_FLAG_SEEN 0x01 |
31 |
|
|
#define MESSAGE_FLAG_ANSWERED 0x02 |
32 |
|
|
#define MESSAGE_FLAG_FLAGGED 0x04 |
33 |
|
|
#define MESSAGE_FLAG_DELETED 0x08 |
34 |
|
|
#define MESSAGE_FLAG_DRAFT 0x10 |
35 |
|
|
|
36 |
|
|
/* Type of mask. This overrides the default filter mode (AND/OR). */ |
37 |
|
|
#define MASK_TYPE_OR 1 |
38 |
|
|
#define MASK_TYPE_AND 2 |
39 |
|
|
|
40 |
|
|
/* Type of mask match according to the four different regular expressions. */ |
41 |
|
|
#define MASK_MATCH_1 1 |
42 |
|
|
#define MASK_MATCH_2 2 |
43 |
|
|
#define MASK_MATCH_3 3 |
44 |
|
|
#define MASK_MATCH_4 4 |
45 |
|
|
|
46 |
|
|
/* String length of action's arguments. */ |
47 |
|
|
#define ARGS_LEN 256 |
48 |
|
|
|
49 |
|
|
/* String length of mask's body. */ |
50 |
|
|
#define MASK_BODY_LEN 256 |
51 |
|
|
|
52 |
|
|
/* Maximum filters assigned to a mailbox. */ |
53 |
|
|
#define MBOX_FILTERS_MAX 64 |
54 |
|
|
|
55 |
|
|
|
56 |
|
|
/* Filter. */ |
57 |
|
|
typedef struct filter { |
58 |
|
|
char key[KEY_LEN]; /* Alias of filter. */ |
59 |
|
|
unsigned int mode; /* AND/OR mode. */ |
60 |
|
|
|
61 |
|
|
struct { /* What to do on filter match. */ |
62 |
|
|
unsigned int type; /* Action. */ |
63 |
|
|
account_t *raccount; /* Remote account to rcopy/rmove |
64 |
|
|
* message. */ |
65 |
|
|
char destmbox[MBOX_NAME_LEN]; /* Destination mailbox. */ |
66 |
|
|
unsigned int msgflags; /* Message flags to |
67 |
|
|
* replace/add/remove. */ |
68 |
|
|
char args[ARGS_LEN]; /* Action's arguments. */ |
69 |
|
|
} action; |
70 |
|
|
|
71 |
|
|
struct mask *masks; /* Masks comprising the filter. */ |
72 |
|
|
unsigned int masknum; /* Total number of masks. */ |
73 |
|
|
unsigned int masklen; /* Total length of body of masks. */ |
74 |
|
|
|
75 |
|
|
struct filter *left, *right; /* Left/right node of tree. */ |
76 |
|
|
} filter_t; |
77 |
|
|
|
78 |
|
|
/* Mask. */ |
79 |
|
|
typedef struct mask { |
80 |
|
|
char body[MASK_BODY_LEN]; /* Body of mask. */ |
81 |
|
|
unsigned int type; /* AND/OR type. */ |
82 |
|
|
struct mask *next; /* Next node of linked list. */ |
83 |
|
|
} mask_t; |
84 |
|
|
|
85 |
|
|
|
86 |
|
|
/* filter.c */ |
87 |
|
|
int set_filter(char *line, regmatch_t * match); |
88 |
|
|
int set_action(char *line, regmatch_t * match); |
89 |
|
|
int set_mask(char *line, regmatch_t * match, int mmt); |
90 |
|
|
int set_job(char *line, regmatch_t * match); |
91 |
|
|
|
92 |
|
|
|
93 |
|
|
#endif /* FILTER_H */ |