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

Annotation of /imapfilter/data.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (hide annotations)
Sat Jul 13 21:19:52 2002 UTC (21 years, 8 months ago) by lefcha
Branch: MAIN
Changes since 1.18: +18 -6 lines
File MIME type: text/plain
Added action flag.

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    
76     /*
77     * Find last node of linked list and append at the end of the list the
78     * supplied node.
79     */
80     #define APPEND_LINKED_LIST(f, n, p, a) \
81     a = &f; \
82     p = f; \
83     while (p) { \
84     a = &(p->next); \
85     p = p->next; \
86     } \
87     *a = n;
88    
89     /*
90 lefcha 1.5 * Find, based on the key of the supplied node, the apropriate position for it
91 lefcha 1.9 * in the tree, and then insert it there.
92 lefcha 1.1 */
93     #define INSERT_TREE(r, n, p, i, c) \
94     i = &r; \
95     p = r; \
96     while (p) { \
97     c = strncmp(n->key, p->key, KEY_LEN); \
98     if (c < 0) { \
99     i = &(p->left); \
100     p = p->left; \
101     } else if (c > 0) { \
102     i = &(p->right); \
103     p = p->right; \
104     } else \
105     return; \
106     } \
107     *i = n;
108    
109     /*
110     * Find, based on the supplied key, the position of a node, and return a
111     * pointer directing to that node.
112     */
113     #define FIND_TREE(r, k, p, c) \
114     p = r; \
115     while (p) { \
116     c = strncmp(k, p->key, KEY_LEN); \
117     if (c < 0) \
118     p = p->left; \
119     else if (c > 0) \
120     p = p->right; \
121     else \
122     return p; \
123     } \
124     return NULL;
125    
126 lefcha 1.7 #define create_node(A) xmalloc(A)
127 lefcha 1.5
128 lefcha 1.1
129     /* Account. */
130 lefcha 1.14 typedef struct account {
131 lefcha 1.18 char key[KEY_LEN]; /* Alias of account. */
132 lefcha 1.5 char server[SERVER_LEN]; /* Hostname of mail server. */
133     unsigned short int port; /* Port to connect. */
134    
135     char username[USERNAME_LEN];/* Username. */
136 lefcha 1.16 char *password; /* Password. */
137 lefcha 1.15 int passwdattr; /* Password attributes. */
138 lefcha 1.9 unsigned int ssl; /* Secure Socket Layer support. */
139 lefcha 1.14 struct mbox *mboxes; /* Mailboxes. */
140     struct account *next; /* Next node of linked list. */
141 lefcha 1.1 } account_t;
142    
143     /* Mailbox. */
144 lefcha 1.14 typedef struct mbox {
145 lefcha 1.5 char name[MBOX_NAME_LEN]; /* Name of mailbox. */
146 lefcha 1.14 struct filter *filters[MBOX_FILTERS_MAX]; /* Filters to be applied. */
147     struct mbox *next; /* Next node of linked list. */
148 lefcha 1.1 } mbox_t;
149    
150     /* Group of mailboxes. */
151 lefcha 1.14 typedef struct mboxgrp {
152 lefcha 1.5 char key[KEY_LEN]; /* Alias of mailbox group. */
153 lefcha 1.14 struct mbox *mboxes[MBOXGRP_MBOXES_MAX]; /* Mailboxes of group. */
154     struct mboxgrp *left, *right; /* Left/right nodes of tree. */
155 lefcha 1.1 } mboxgrp_t;
156    
157     /* Filter. */
158 lefcha 1.14 typedef struct filter {
159 lefcha 1.1 char key[KEY_LEN]; /* Alias of filter. */
160     unsigned int mode; /* AND/OR mode. */
161    
162 lefcha 1.5 struct { /* What to do on filter match. */
163     unsigned int type; /* Action. */
164 lefcha 1.18 account_t *raccount; /* Remote account to rcopy/rmove message. */
165 lefcha 1.5 char destmbox[MBOX_NAME_LEN]; /* Destination mailbox. */
166 lefcha 1.19 unsigned int msgflags; /* Message flags to replace/add/remove. */
167 lefcha 1.5 char args[ARGS_LEN]; /* Action's arguments. */
168 lefcha 1.1 } action;
169    
170 lefcha 1.14 struct mask *masks; /* Masks comprising the filter. */
171 lefcha 1.5 unsigned int masknum; /* Total number of masks. */
172 lefcha 1.18 unsigned int ormasknum; /* Total number of OR masks. */
173 lefcha 1.5 unsigned int masklen; /* Total length of body of masks. */
174    
175 lefcha 1.14 struct filter *left, *right;/* Left/right node of tree. */
176 lefcha 1.1 } filter_t;
177    
178     /* Mask. */
179 lefcha 1.14 typedef struct mask {
180 lefcha 1.1 char body[MASK_BODY_LEN]; /* Body of mask. */
181     unsigned int type; /* AND/OR type. */
182 lefcha 1.14 struct mask *next; /* Next node of linked list. */
183 lefcha 1.1 } mask_t;
184    
185    
186     /* data.c */
187     void init_account(account_t * node);
188     void append_account(account_t * node);
189     int set_account(char *line, regmatch_t * match);
190 lefcha 1.15 #ifdef ENCRYPTED_PASSWORDS
191     char *find_password(char *user, char *serv);
192     #endif
193 lefcha 1.1
194     void init_mboxgrp(mboxgrp_t * node);
195     void ins_mboxgrp(mboxgrp_t * node);
196     int set_mboxgrp(char *line, regmatch_t * match);
197     void process_mboxgrp(mboxgrp_t * node, char *mboxs);
198     mboxgrp_t *find_mboxgrp(char *key);
199    
200     void init_mbox(mbox_t * node);
201     void append_mbox(mbox_t * node);
202     mbox_t *set_mbox(char *name);
203    
204     void init_filter(filter_t * node);
205     void ins_filter(filter_t * node);
206     int set_filter(char *line, regmatch_t * match);
207     filter_t *find_filter(char *key);
208 lefcha 1.4 int set_action(char *line, regmatch_t * match);
209 lefcha 1.1
210     void init_mask(mask_t * node);
211     void append_mask(mask_t * node);
212     int set_mask(char *line, regmatch_t * match);
213 lefcha 1.10 void convert_date(mask_t * node);
214 lefcha 1.1
215     int set_job(char *line, regmatch_t * match);
216 lefcha 1.4 void link_mbox_filter(filter_t * cf, mboxgrp_t * cg);
217 lefcha 1.1
218 lefcha 1.3 void destroy_data(void);
219 lefcha 1.1 void destroy_mboxgrp(mboxgrp_t * node);
220    
221 lefcha 1.4 void string_upper(char *str, size_t size);
222 lefcha 1.6 int string_decode(char *str);
223 lefcha 1.14
224     char *apply_namespace(char *mbox, char *prefix, char delim);
225 lefcha 1.3
226 lefcha 1.5 #endif /* DATA_H */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26