/[imapfilter]/imapfilter/data.h
ViewVC logotype

Annotation of /imapfilter/data.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (hide annotations)
Mon May 19 22:37:20 2003 UTC (20 years, 10 months ago) by lefcha
Branch: MAIN
Changes since 1.24: +2 -1 lines
File MIME type: text/plain
Added functions to free memory of unneeded or all data structures.

1 lefcha 1.1 #ifndef DATA_H
2     #define DATA_H
3    
4 lefcha 1.8 #include <sys/types.h>
5 lefcha 1.1 #include <regex.h>
6    
7     /* String lengths of account settings. */
8 lefcha 1.23 #define SERVER_LEN (635 + 1) /* Section 2.5 RFC 1123. */
9     #define USERNAME_LEN 128
10     #define PASSWORD_LEN 128
11 lefcha 1.1
12 lefcha 1.15 /* String lengths of master password and encrypted passwords. */
13 lefcha 1.23 #define PASSPHRASE_LEN 256
14     #define ENCRYPTED_PASSWORD_LEN 128
15 lefcha 1.15
16     /* Attributes of a password. */
17 lefcha 1.23 #define PASSWORD_NONE 0
18     #define PASSWORD_PLAIN 1
19     #define PASSWORD_ENCRYPTED 2
20 lefcha 1.15
21 lefcha 1.9 /* Secure Socket Layer protocols. */
22 lefcha 1.23 #define SSL_DISABLED 0
23     #define SSL_SSL_V2 1
24     #define SSL_SSL_V3 2
25     #define SSL_TLS_V1 3
26 lefcha 1.9
27 lefcha 1.1 /* String length of keys (aliases). */
28 lefcha 1.23 #define KEY_LEN 32
29 lefcha 1.1
30     /* String length of action's arguments. */
31 lefcha 1.23 #define ARGS_LEN 256
32 lefcha 1.1
33     /* String length of mailbox's name. */
34 lefcha 1.23 #define MBOX_NAME_LEN 128
35 lefcha 1.1
36     /* String length of mask's body. */
37 lefcha 1.23 #define MASK_BODY_LEN 256
38 lefcha 1.1
39     /* Maximum filters assigned to a mailbox. */
40 lefcha 1.23 #define MBOX_FILTERS_MAX 64
41 lefcha 1.1
42     /* Maximum mailboxes contained in a mailbox-group. */
43 lefcha 1.23 #define MBOXGRP_MBOXES_MAX 64
44 lefcha 1.1
45 lefcha 1.5 /*
46 lefcha 1.1 * Mode for masks that comprise a filter. So if a filter is of AND type then
47     * as default masks are ANDed.
48     */
49 lefcha 1.23 #define FILTER_MODE_OR 1
50     #define FILTER_MODE_AND 2
51 lefcha 1.1
52     /* Action to do in case of filter matching. */
53 lefcha 1.19 #define FILTER_ACTION_DELETE 1
54     #define FILTER_ACTION_COPY 2
55     #define FILTER_ACTION_MOVE 3
56     #define FILTER_ACTION_RCOPY 4
57     #define FILTER_ACTION_RMOVE 5
58     #define FILTER_ACTION_FLAG_REPLACE 6
59     #define FILTER_ACTION_FLAG_ADD 7
60     #define FILTER_ACTION_FLAG_REMOVE 8
61     #define FILTER_ACTION_LIST 9
62    
63     /* Message flags to replace/add/remove. */
64     #define MESSAGE_FLAG_NONE 0x00
65     #define MESSAGE_FLAG_SEEN 0x01
66     #define MESSAGE_FLAG_ANSWERED 0x02
67     #define MESSAGE_FLAG_FLAGGED 0x04
68     #define MESSAGE_FLAG_DELETED 0x08
69     #define MESSAGE_FLAG_DRAFT 0x10
70 lefcha 1.1
71 lefcha 1.9 /* Type of mask. This overrides the default filter mode (AND/OR). */
72 lefcha 1.23 #define MASK_TYPE_OR 1
73     #define MASK_TYPE_AND 2
74 lefcha 1.1
75 lefcha 1.20 /* Type of mask match according to the four different regular expressions. */
76 lefcha 1.23 #define MASK_MATCH_1 1
77     #define MASK_MATCH_2 2
78     #define MASK_MATCH_3 3
79     #define MASK_MATCH_4 4
80 lefcha 1.20
81 lefcha 1.1
82     /*
83     * Find last node of linked list and append at the end of the list the
84     * supplied node.
85     */
86 lefcha 1.23 #define APPEND_LINKED_LIST(f, n, p, a) \
87     a = &f; \
88     p = f; \
89     while (p) { \
90     a = &(p->next); \
91     p = p->next; \
92     } \
93     *a = n;
94 lefcha 1.1
95     /*
96 lefcha 1.5 * Find, based on the key of the supplied node, the apropriate position for it
97 lefcha 1.9 * in the tree, and then insert it there.
98 lefcha 1.1 */
99 lefcha 1.23 #define INSERT_TREE(r, n, p, i, c) \
100     i = &r; \
101     p = r; \
102     while (p) { \
103     c = strncmp(n->key, p->key, KEY_LEN); \
104     if (c < 0) { \
105     i = &(p->left); \
106     p = p->left; \
107     } else if (c > 0) { \
108     i = &(p->right); \
109     p = p->right; \
110     } else \
111     return; \
112     } \
113     *i = n;
114 lefcha 1.1
115     /*
116     * Find, based on the supplied key, the position of a node, and return a
117     * pointer directing to that node.
118     */
119 lefcha 1.23 #define FIND_TREE(r, k, p, c) \
120     p = r; \
121     while (p) { \
122     c = strncmp(k, p->key, KEY_LEN); \
123     if (c < 0) \
124     p = p->left; \
125     else if (c > 0) \
126     p = p->right; \
127     else \
128     return p; \
129     } \
130     return NULL;
131 lefcha 1.1
132 lefcha 1.7 #define create_node(A) xmalloc(A)
133 lefcha 1.5
134 lefcha 1.1
135     /* Account. */
136 lefcha 1.14 typedef struct account {
137 lefcha 1.23 char key[KEY_LEN]; /* Alias of account. */
138     char server[SERVER_LEN];/* Hostname of mail server. */
139     unsigned short int port;/* Port to connect. */
140    
141     char username[USERNAME_LEN]; /* Username. */
142     char *password; /* Password. */
143     int passwdattr; /* Password attributes. */
144     unsigned int ssl; /* Secure Socket Layer support. */
145     struct mbox *mboxes; /* Mailboxes. */
146     struct account *next; /* Next node of linked list. */
147 lefcha 1.1 } account_t;
148    
149     /* Mailbox. */
150 lefcha 1.14 typedef struct mbox {
151 lefcha 1.23 char name[MBOX_NAME_LEN]; /* Name of mailbox. */
152     struct filter *filters[MBOX_FILTERS_MAX]; /* Filters to be
153     * applied. */
154     struct mbox *next; /* Next node of linked list. */
155 lefcha 1.1 } mbox_t;
156    
157     /* Group of mailboxes. */
158 lefcha 1.14 typedef struct mboxgrp {
159 lefcha 1.23 char key[KEY_LEN]; /* Alias of mailbox group. */
160     struct mbox *mboxes[MBOXGRP_MBOXES_MAX]; /* Mailboxes of group. */
161     struct mboxgrp *left, *right; /* Left/right nodes of tree. */
162 lefcha 1.1 } mboxgrp_t;
163    
164     /* Filter. */
165 lefcha 1.14 typedef struct filter {
166 lefcha 1.23 char key[KEY_LEN]; /* Alias of filter. */
167     unsigned int mode; /* AND/OR mode. */
168 lefcha 1.1
169 lefcha 1.23 struct { /* What to do on filter match. */
170     unsigned int type; /* Action. */
171     account_t *raccount; /* Remote account to rcopy/rmove
172     * message. */
173     char destmbox[MBOX_NAME_LEN]; /* Destination mailbox. */
174     unsigned int msgflags; /* Message flags to
175     * replace/add/remove. */
176     char args[ARGS_LEN]; /* Action's arguments. */
177     } action;
178    
179     struct mask *masks; /* Masks comprising the filter. */
180     unsigned int masknum; /* Total number of masks. */
181     unsigned int masklen; /* Total length of body of masks. */
182 lefcha 1.5
183 lefcha 1.23 struct filter *left, *right; /* Left/right node of tree. */
184 lefcha 1.1 } filter_t;
185    
186     /* Mask. */
187 lefcha 1.14 typedef struct mask {
188 lefcha 1.23 char body[MASK_BODY_LEN]; /* Body of mask. */
189     unsigned int type; /* AND/OR type. */
190     struct mask *next; /* Next node of linked list. */
191 lefcha 1.1 } mask_t;
192    
193    
194     /* data.c */
195     void init_account(account_t * node);
196     void append_account(account_t * node);
197     int set_account(char *line, regmatch_t * match);
198 lefcha 1.23
199 lefcha 1.15 #ifdef ENCRYPTED_PASSWORDS
200     char *find_password(char *user, char *serv);
201 lefcha 1.23
202 lefcha 1.15 #endif
203 lefcha 1.1
204     void init_mboxgrp(mboxgrp_t * node);
205 lefcha 1.22 void insert_mboxgrp(mboxgrp_t * node);
206 lefcha 1.1 int set_mboxgrp(char *line, regmatch_t * match);
207     void process_mboxgrp(mboxgrp_t * node, char *mboxs);
208     mboxgrp_t *find_mboxgrp(char *key);
209    
210     void init_mbox(mbox_t * node);
211     void append_mbox(mbox_t * node);
212     mbox_t *set_mbox(char *name);
213    
214     void init_filter(filter_t * node);
215 lefcha 1.22 void insert_filter(filter_t * node);
216 lefcha 1.1 int set_filter(char *line, regmatch_t * match);
217     filter_t *find_filter(char *key);
218 lefcha 1.4 int set_action(char *line, regmatch_t * match);
219 lefcha 1.1
220     void init_mask(mask_t * node);
221     void append_mask(mask_t * node);
222 lefcha 1.20 int set_mask(char *line, regmatch_t * match, int mmt);
223 lefcha 1.10 void convert_date(mask_t * node);
224 lefcha 1.1
225     int set_job(char *line, regmatch_t * match);
226 lefcha 1.4 void link_mbox_filter(filter_t * cf, mboxgrp_t * cg);
227 lefcha 1.1
228 lefcha 1.25 void destroy_all(void);
229     void destroy_unneeded(void);
230 lefcha 1.24 void destroy_mboxgrps(mboxgrp_t * node);
231     void destroy_mboxs(mbox_t * node);
232     void destroy_accounts(account_t * node);
233     void destroy_filters(filter_t * node);
234     void destroy_masks(mask_t * node);
235 lefcha 1.1
236 lefcha 1.4 void string_upper(char *str, size_t size);
237 lefcha 1.6 int string_decode(char *str);
238 lefcha 1.14
239     char *apply_namespace(char *mbox, char *prefix, char delim);
240 lefcha 1.3
241 lefcha 1.5 #endif /* DATA_H */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26