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