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

Annotation of /imapfilter/data.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (hide annotations)
Thu Jul 25 21:24:39 2002 UTC (21 years, 8 months ago) by lefcha
Branch: MAIN
Changes since 1.19: +7 -1 lines
File MIME type: text/plain
Run correctly when compiled with libc5 and clean up of set_mask().

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.7 #define SERVER_LEN (635 + 1) /* Section 2.5 RFC 1123. */
9 lefcha 1.12 #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     #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 lefcha 1.9 /* 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 lefcha 1.1 /* String length of keys (aliases). */
28 lefcha 1.7 #define KEY_LEN 32
29 lefcha 1.1
30     /* String length of action's arguments. */
31 lefcha 1.7 #define ARGS_LEN 256
32 lefcha 1.1
33     /* String length of mailbox's name. */
34 lefcha 1.7 #define MBOX_NAME_LEN 128
35 lefcha 1.1
36     /* String length of mask's body. */
37 lefcha 1.7 #define MASK_BODY_LEN 256
38 lefcha 1.1
39     /* Maximum filters assigned to a mailbox. */
40 lefcha 1.12 #define MBOX_FILTERS_MAX 64
41 lefcha 1.1
42     /* Maximum mailboxes contained in a mailbox-group. */
43 lefcha 1.7 #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.7 #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.7 #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     #define MASK_MATCH_1 1
77     #define MASK_MATCH_2 2
78     #define MASK_MATCH_3 3
79     #define MASK_MATCH_4 4
80    
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     #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    
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     #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    
115     /*
116     * Find, based on the supplied key, the position of a node, and return a
117     * pointer directing to that node.
118     */
119     #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    
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.18 char key[KEY_LEN]; /* Alias of account. */
138 lefcha 1.5 char server[SERVER_LEN]; /* Hostname of mail server. */
139     unsigned short int port; /* Port to connect. */
140    
141     char username[USERNAME_LEN];/* Username. */
142 lefcha 1.16 char *password; /* Password. */
143 lefcha 1.15 int passwdattr; /* Password attributes. */
144 lefcha 1.9 unsigned int ssl; /* Secure Socket Layer support. */
145 lefcha 1.14 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.5 char name[MBOX_NAME_LEN]; /* Name of mailbox. */
152 lefcha 1.14 struct filter *filters[MBOX_FILTERS_MAX]; /* Filters to be applied. */
153     struct mbox *next; /* Next node of linked list. */
154 lefcha 1.1 } mbox_t;
155    
156     /* Group of mailboxes. */
157 lefcha 1.14 typedef struct mboxgrp {
158 lefcha 1.5 char key[KEY_LEN]; /* Alias of mailbox group. */
159 lefcha 1.14 struct mbox *mboxes[MBOXGRP_MBOXES_MAX]; /* Mailboxes of group. */
160     struct mboxgrp *left, *right; /* Left/right nodes of tree. */
161 lefcha 1.1 } mboxgrp_t;
162    
163     /* Filter. */
164 lefcha 1.14 typedef struct filter {
165 lefcha 1.1 char key[KEY_LEN]; /* Alias of filter. */
166     unsigned int mode; /* AND/OR mode. */
167    
168 lefcha 1.5 struct { /* What to do on filter match. */
169     unsigned int type; /* Action. */
170 lefcha 1.18 account_t *raccount; /* Remote account to rcopy/rmove message. */
171 lefcha 1.5 char destmbox[MBOX_NAME_LEN]; /* Destination mailbox. */
172 lefcha 1.19 unsigned int msgflags; /* Message flags to replace/add/remove. */
173 lefcha 1.5 char args[ARGS_LEN]; /* Action's arguments. */
174 lefcha 1.1 } action;
175    
176 lefcha 1.14 struct mask *masks; /* Masks comprising the filter. */
177 lefcha 1.5 unsigned int masknum; /* Total number of masks. */
178 lefcha 1.18 unsigned int ormasknum; /* Total number of OR masks. */
179 lefcha 1.5 unsigned int masklen; /* Total length of body of masks. */
180    
181 lefcha 1.14 struct filter *left, *right;/* Left/right node of tree. */
182 lefcha 1.1 } filter_t;
183    
184     /* Mask. */
185 lefcha 1.14 typedef struct mask {
186 lefcha 1.1 char body[MASK_BODY_LEN]; /* Body of mask. */
187     unsigned int type; /* AND/OR type. */
188 lefcha 1.14 struct mask *next; /* Next node of linked list. */
189 lefcha 1.1 } mask_t;
190    
191    
192     /* data.c */
193     void init_account(account_t * node);
194     void append_account(account_t * node);
195     int set_account(char *line, regmatch_t * match);
196 lefcha 1.15 #ifdef ENCRYPTED_PASSWORDS
197     char *find_password(char *user, char *serv);
198     #endif
199 lefcha 1.1
200     void init_mboxgrp(mboxgrp_t * node);
201     void ins_mboxgrp(mboxgrp_t * node);
202     int set_mboxgrp(char *line, regmatch_t * match);
203     void process_mboxgrp(mboxgrp_t * node, char *mboxs);
204     mboxgrp_t *find_mboxgrp(char *key);
205    
206     void init_mbox(mbox_t * node);
207     void append_mbox(mbox_t * node);
208     mbox_t *set_mbox(char *name);
209    
210     void init_filter(filter_t * node);
211     void ins_filter(filter_t * node);
212     int set_filter(char *line, regmatch_t * match);
213     filter_t *find_filter(char *key);
214 lefcha 1.4 int set_action(char *line, regmatch_t * match);
215 lefcha 1.1
216     void init_mask(mask_t * node);
217     void append_mask(mask_t * node);
218 lefcha 1.20 int set_mask(char *line, regmatch_t * match, int mmt);
219 lefcha 1.10 void convert_date(mask_t * node);
220 lefcha 1.1
221     int set_job(char *line, regmatch_t * match);
222 lefcha 1.4 void link_mbox_filter(filter_t * cf, mboxgrp_t * cg);
223 lefcha 1.1
224 lefcha 1.3 void destroy_data(void);
225 lefcha 1.1 void destroy_mboxgrp(mboxgrp_t * node);
226    
227 lefcha 1.4 void string_upper(char *str, size_t size);
228 lefcha 1.6 int string_decode(char *str);
229 lefcha 1.14
230     char *apply_namespace(char *mbox, char *prefix, char delim);
231 lefcha 1.3
232 lefcha 1.5 #endif /* DATA_H */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26