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

Annotation of /imapfilter/data.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Mon Sep 10 23:43:29 2001 UTC (22 years, 7 months ago) by lefcha
Branch: MAIN
File MIME type: text/plain
New imapfilter.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26