1 |
#ifndef DATA_H |
2 |
#define DATA_H |
3 |
|
4 |
#include <sys/types.h> |
5 |
#include <regex.h> |
6 |
|
7 |
/* String lengths of account settings. */ |
8 |
#define SERVER_LEN (635 + 1) /* Section 2.5 RFC 1123. */ |
9 |
#define USERNAME_LEN 128 |
10 |
#define PASSWORD_LEN 128 |
11 |
|
12 |
#ifdef SSL_TLS |
13 |
/* Secure Socket Layer protocols. */ |
14 |
#define SSL_DISABLED 0 |
15 |
#define SSL_SSL_V2 1 |
16 |
#define SSL_SSL_V3 2 |
17 |
#define SSL_TLS_V1 3 |
18 |
#endif |
19 |
|
20 |
/* String length of keys (aliases). */ |
21 |
#define KEY_LEN 32 |
22 |
|
23 |
/* String length of action's arguments. */ |
24 |
#define ARGS_LEN 256 |
25 |
|
26 |
/* String length of mailbox's name. */ |
27 |
#define MBOX_NAME_LEN 128 |
28 |
|
29 |
/* String length of mask's body. */ |
30 |
#define MASK_BODY_LEN 256 |
31 |
|
32 |
/* Maximum filters assigned to a mailbox. */ |
33 |
#define MBOX_FILTERS_MAX 64 |
34 |
|
35 |
/* Maximum mailboxes contained in a mailbox-group. */ |
36 |
#define MBOXGRP_MBOXES_MAX 64 |
37 |
|
38 |
/* |
39 |
* Mode for masks that comprise a filter. So if a filter is of AND type then |
40 |
* as default masks are ANDed. |
41 |
*/ |
42 |
#define FILTER_MODE_OR 1 |
43 |
#define FILTER_MODE_AND 2 |
44 |
|
45 |
/* Action to do in case of filter matching. */ |
46 |
#define FILTER_ACTION_DELETE 1 |
47 |
#define FILTER_ACTION_COPY 2 |
48 |
#define FILTER_ACTION_MOVE 3 |
49 |
#define FILTER_ACTION_LIST 4 |
50 |
|
51 |
/* Type of mask. This overrides the default filter mode (AND/OR). */ |
52 |
#define MASK_TYPE_OR 1 |
53 |
#define MASK_TYPE_AND 2 |
54 |
|
55 |
|
56 |
/* |
57 |
* Find last node of linked list and append at the end of the list the |
58 |
* supplied node. |
59 |
*/ |
60 |
#define APPEND_LINKED_LIST(f, n, p, a) \ |
61 |
a = &f; \ |
62 |
p = f; \ |
63 |
while (p) { \ |
64 |
a = &(p->next); \ |
65 |
p = p->next; \ |
66 |
} \ |
67 |
*a = n; |
68 |
|
69 |
/* |
70 |
* Find, based on the key of the supplied node, the apropriate position for it |
71 |
* in the tree, and then insert it there. |
72 |
*/ |
73 |
#define INSERT_TREE(r, n, p, i, c) \ |
74 |
i = &r; \ |
75 |
p = r; \ |
76 |
while (p) { \ |
77 |
c = strncmp(n->key, p->key, KEY_LEN); \ |
78 |
if (c < 0) { \ |
79 |
i = &(p->left); \ |
80 |
p = p->left; \ |
81 |
} else if (c > 0) { \ |
82 |
i = &(p->right); \ |
83 |
p = p->right; \ |
84 |
} else \ |
85 |
return; \ |
86 |
} \ |
87 |
*i = n; |
88 |
|
89 |
/* |
90 |
* Find, based on the supplied key, the position of a node, and return a |
91 |
* pointer directing to that node. |
92 |
*/ |
93 |
#define FIND_TREE(r, k, p, c) \ |
94 |
p = r; \ |
95 |
while (p) { \ |
96 |
c = strncmp(k, p->key, KEY_LEN); \ |
97 |
if (c < 0) \ |
98 |
p = p->left; \ |
99 |
else if (c > 0) \ |
100 |
p = p->right; \ |
101 |
else \ |
102 |
return p; \ |
103 |
} \ |
104 |
return NULL; |
105 |
|
106 |
#define create_node(A) xmalloc(A) |
107 |
|
108 |
|
109 |
/* Account. */ |
110 |
typedef struct account_t { |
111 |
char server[SERVER_LEN]; /* Hostname of mail server. */ |
112 |
unsigned short int port; /* Port to connect. */ |
113 |
|
114 |
char username[USERNAME_LEN];/* Username. */ |
115 |
char password[PASSWORD_LEN];/* Password. */ |
116 |
#ifdef SSL_TLS |
117 |
unsigned int ssl; /* Secure Socket Layer support. */ |
118 |
#endif |
119 |
struct mbox_t *mboxes; /* Mailboxes. */ |
120 |
struct account_t *next; /* Next node of linked list. */ |
121 |
} account_t; |
122 |
|
123 |
/* Mailbox. */ |
124 |
typedef struct mbox_t { |
125 |
char name[MBOX_NAME_LEN]; /* Name of mailbox. */ |
126 |
struct filter_t *filters[MBOX_FILTERS_MAX]; /* Filters to be applied. */ |
127 |
struct mbox_t *next; /* Next node of linked list. */ |
128 |
} mbox_t; |
129 |
|
130 |
/* Group of mailboxes. */ |
131 |
typedef struct mboxgrp_t { |
132 |
char key[KEY_LEN]; /* Alias of mailbox group. */ |
133 |
struct mbox_t *mboxes[MBOXGRP_MBOXES_MAX]; /* Mailboxes of group. */ |
134 |
struct mboxgrp_t *left, *right; /* Left/right nodes of tree. */ |
135 |
} mboxgrp_t; |
136 |
|
137 |
/* Filter. */ |
138 |
typedef struct filter_t { |
139 |
char key[KEY_LEN]; /* Alias of filter. */ |
140 |
unsigned int mode; /* AND/OR mode. */ |
141 |
|
142 |
struct { /* What to do on filter match. */ |
143 |
unsigned int type; /* Action. */ |
144 |
char destmbox[MBOX_NAME_LEN]; /* Destination mailbox. */ |
145 |
char args[ARGS_LEN]; /* Action's arguments. */ |
146 |
} action; |
147 |
|
148 |
struct mask_t *masks; /* Masks comprising the filter. */ |
149 |
unsigned int masknum; /* Total number of masks. */ |
150 |
unsigned int masklen; /* Total length of body of masks. */ |
151 |
|
152 |
struct filter_t *left, *right; /* Left/right node of tree. */ |
153 |
} filter_t; |
154 |
|
155 |
/* Mask. */ |
156 |
typedef struct mask_t { |
157 |
char body[MASK_BODY_LEN]; /* Body of mask. */ |
158 |
unsigned int type; /* AND/OR type. */ |
159 |
struct mask_t *next; /* Next node of linked list. */ |
160 |
} mask_t; |
161 |
|
162 |
|
163 |
/* data.c */ |
164 |
void init_account(account_t * node); |
165 |
void append_account(account_t * node); |
166 |
int set_account(char *line, regmatch_t * match); |
167 |
|
168 |
void init_mboxgrp(mboxgrp_t * node); |
169 |
void ins_mboxgrp(mboxgrp_t * node); |
170 |
int set_mboxgrp(char *line, regmatch_t * match); |
171 |
void process_mboxgrp(mboxgrp_t * node, char *mboxs); |
172 |
mboxgrp_t *find_mboxgrp(char *key); |
173 |
|
174 |
void init_mbox(mbox_t * node); |
175 |
void append_mbox(mbox_t * node); |
176 |
mbox_t *set_mbox(char *name); |
177 |
|
178 |
void init_filter(filter_t * node); |
179 |
void ins_filter(filter_t * node); |
180 |
int set_filter(char *line, regmatch_t * match); |
181 |
filter_t *find_filter(char *key); |
182 |
int set_action(char *line, regmatch_t * match); |
183 |
|
184 |
void init_mask(mask_t * node); |
185 |
void append_mask(mask_t * node); |
186 |
int set_mask(char *line, regmatch_t * match); |
187 |
void convert_date(mask_t * node); |
188 |
|
189 |
int set_job(char *line, regmatch_t * match); |
190 |
void link_mbox_filter(filter_t * cf, mboxgrp_t * cg); |
191 |
|
192 |
void destroy_data(void); |
193 |
void destroy_mboxgrp(mboxgrp_t * node); |
194 |
void overwrite_passwords(void); |
195 |
|
196 |
void string_upper(char *str, size_t size); |
197 |
int string_decode(char *str); |
198 |
|
199 |
#endif /* DATA_H */ |