First draft to set `property' on the mailbox, setting a property
will permit to change the behaviour of the mailbox. For example POP3 and IMAP4 streams are RFC822 meaning they end with "\r\n", Now I'm doing ugly hack to convert it and maintain the offset, that does not work well. Rather lets put the trouble on the client ;-) but by setting property_set ("RFC822_FORMAT"); the conversion "\r\n" can still be done. But it will be up to the client to do the offset calculation.
Showing
8 changed files
with
373 additions
and
4 deletions
1 | 2001-02-22 Alain Magloire | 1 | 2001-02-22 Alain Magloire |
2 | 2 | ||
3 | * mailbox/property.c : New file. | ||
4 | * include/mailutils/property.h : New file. | ||
5 | * mailbox/mailbox.c (mailbox_get_property) : New function, | ||
6 | a first draft to let set "property" on a mailbox that can | ||
7 | change its behaviour. | ||
8 | * mailbox/include/mailbox0.h : New field in struct _mailbox, property. | ||
9 | |||
10 | * sieve/lex-sieve.lex : Add LGPL banner. | ||
11 | * sieve/gram-sieve.y : Add LGPL banner. | ||
12 | |||
13 | 2001-02-22 Alain Magloire | ||
14 | |||
3 | * sieve : New Directory. | 15 | * sieve : New Directory. |
4 | * sieve/lex-sieve.lex : RFC3028 tokenizer. | 16 | * sieve/lex-sieve.lex : RFC3028 tokenizer. |
5 | * sieve/gram-sieve.y : RFC3028 grammar. | 17 | * sieve/gram-sieve.y : RFC3028 grammar. | ... | ... |
... | @@ -27,6 +27,7 @@ typedef struct _mailbox *mailbox_t; | ... | @@ -27,6 +27,7 @@ typedef struct _mailbox *mailbox_t; |
27 | #include <mailutils/url.h> | 27 | #include <mailutils/url.h> |
28 | #include <mailutils/observer.h> | 28 | #include <mailutils/observer.h> |
29 | #include <mailutils/debug.h> | 29 | #include <mailutils/debug.h> |
30 | #include <mailutils/property.h> | ||
30 | #include <mailutils/message.h> | 31 | #include <mailutils/message.h> |
31 | #include <mailutils/auth.h> | 32 | #include <mailutils/auth.h> |
32 | #include <mailutils/locker.h> | 33 | #include <mailutils/locker.h> |
... | @@ -83,6 +84,9 @@ extern int mailbox_set_authority __P ((mailbox_t, authority_t)); | ... | @@ -83,6 +84,9 @@ extern int mailbox_set_authority __P ((mailbox_t, authority_t)); |
83 | extern int mailbox_get_ticket __P ((mailbox_t, ticket_t *)); | 84 | extern int mailbox_get_ticket __P ((mailbox_t, ticket_t *)); |
84 | extern int mailbox_set_ticket __P ((mailbox_t, ticket_t)); | 85 | extern int mailbox_set_ticket __P ((mailbox_t, ticket_t)); |
85 | 86 | ||
87 | /* Property. */ | ||
88 | extern int mailbox_get_property __P ((mailbox_t, property_t *)); | ||
89 | |||
86 | /* URL. */ | 90 | /* URL. */ |
87 | extern int mailbox_get_url __P ((mailbox_t, url_t *)); | 91 | extern int mailbox_get_url __P ((mailbox_t, url_t *)); |
88 | 92 | ... | ... |
include/mailutils/property.h
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Library Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifndef _MAILUTILS_PROPERTY_H | ||
19 | #define _MAILUTILS_PROPERTY_H | ||
20 | |||
21 | #include <sys/types.h> | ||
22 | |||
23 | #ifndef __P | ||
24 | # ifdef __STDC__ | ||
25 | # define __P(args) args | ||
26 | # else | ||
27 | # define __P(args) () | ||
28 | # endif | ||
29 | #endif /*__P */ | ||
30 | |||
31 | #ifdef _cplusplus | ||
32 | extern "C" { | ||
33 | #endif | ||
34 | |||
35 | struct _property; | ||
36 | typedef struct _property *property_t; | ||
37 | enum property_type { TYPE_POINTER, TYPE_LONG }; | ||
38 | |||
39 | extern int property_create __P ((property_t *)); | ||
40 | extern void property_destroy __P ((property_t *)); | ||
41 | |||
42 | extern int property_set_value __P ((property_t, const char *k, const void *v, | ||
43 | enum property_type)); | ||
44 | extern int property_get_value __P ((property_t, const char *k, void **, | ||
45 | enum property_type *)); | ||
46 | |||
47 | extern int property_set __P ((property_t, const char *k)); | ||
48 | extern int property_unset __P ((property_t, const char *k)); | ||
49 | extern int property_is_set __P ((property_t, const char *k)); | ||
50 | |||
51 | extern int property_set_int __P ((property_t, const char *, int)); | ||
52 | extern int property_get_int __P ((property_t, const char *)); | ||
53 | |||
54 | extern int property_set_long __P ((property_t, const char *, long)); | ||
55 | extern long property_get_long __P ((property_t, const char *)); | ||
56 | |||
57 | extern int property_set_pointer __P ((property_t, const char *, void *)); | ||
58 | extern void *property_get_pointer __P ((property_t, const char *)); | ||
59 | |||
60 | #ifdef _cplusplus | ||
61 | } | ||
62 | #endif | ||
63 | |||
64 | #endif /* _MAILUTILS_PROPERTY_H */ |
... | @@ -48,6 +48,7 @@ struct _mailbox | ... | @@ -48,6 +48,7 @@ struct _mailbox |
48 | debug_t debug; | 48 | debug_t debug; |
49 | ticket_t ticket; | 49 | ticket_t ticket; |
50 | authority_t authority; | 50 | authority_t authority; |
51 | property_t property; | ||
51 | locker_t locker; | 52 | locker_t locker; |
52 | stream_t stream; | 53 | stream_t stream; |
53 | url_t url; | 54 | url_t url; | ... | ... |
... | @@ -392,6 +392,16 @@ mailbox_get_observable (mailbox_t mbox, observable_t *pobservable) | ... | @@ -392,6 +392,16 @@ mailbox_get_observable (mailbox_t mbox, observable_t *pobservable) |
392 | } | 392 | } |
393 | 393 | ||
394 | int | 394 | int |
395 | mailbox_get_property (mailbox_t mbox, property_t *pproperty) | ||
396 | { | ||
397 | if (mbox == NULL || pproperty == NULL) | ||
398 | return EINVAL; | ||
399 | *pproperty = mbox->property; | ||
400 | return 0; | ||
401 | } | ||
402 | |||
403 | |||
404 | int | ||
395 | mailbox_set_debug (mailbox_t mbox, debug_t debug) | 405 | mailbox_set_debug (mailbox_t mbox, debug_t debug) |
396 | { | 406 | { |
397 | if (mbox == NULL) | 407 | if (mbox == NULL) | ... | ... |
mailbox/property.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Library Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | #include <config.h> | ||
20 | #endif | ||
21 | |||
22 | #include <errno.h> | ||
23 | #include <stdlib.h> | ||
24 | |||
25 | #include <mailutils/property.h> | ||
26 | #include <mailutils/list.h> | ||
27 | #include <mailutils/iterator.h> | ||
28 | |||
29 | struct property_data | ||
30 | { | ||
31 | size_t hash; | ||
32 | enum property_type type; | ||
33 | union | ||
34 | { | ||
35 | long l; | ||
36 | void *v; | ||
37 | } value; | ||
38 | }; | ||
39 | |||
40 | struct _property | ||
41 | { | ||
42 | list_t list; | ||
43 | }; | ||
44 | |||
45 | static int property_find __P ((list_t, const char *, struct property_data **)); | ||
46 | static size_t hash __P ((const char *)); | ||
47 | |||
48 | int | ||
49 | property_create (property_t *pp) | ||
50 | { | ||
51 | property_t prop; | ||
52 | int status; | ||
53 | if (pp == NULL) | ||
54 | return EINVAL; | ||
55 | prop = calloc (1, sizeof (*prop)); | ||
56 | if (prop == NULL) | ||
57 | return ENOMEM; | ||
58 | status = list_create (&(prop->list)); | ||
59 | if (status != 0) | ||
60 | { | ||
61 | free (prop); | ||
62 | return status; | ||
63 | } | ||
64 | *pp = prop; | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | void | ||
69 | property_destroy (property_t *pp) | ||
70 | { | ||
71 | if (pp && *pp) | ||
72 | { | ||
73 | property_t prop = *pp; | ||
74 | list_destroy (&(prop->list)); | ||
75 | free (prop); | ||
76 | *pp = NULL; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | |||
81 | int | ||
82 | property_set_value (property_t prop, const char *key, const void *value, | ||
83 | enum property_type type) | ||
84 | { | ||
85 | struct property_data *pd; | ||
86 | int status; | ||
87 | |||
88 | if (prop == NULL) | ||
89 | return EINVAL; | ||
90 | |||
91 | status = property_find (prop->list, key, &pd); | ||
92 | if (status != 0) | ||
93 | return status; | ||
94 | |||
95 | if (pd == NULL) | ||
96 | { | ||
97 | pd = calloc (1, sizeof (*pd)); | ||
98 | if (pd == NULL) | ||
99 | return ENOMEM; | ||
100 | pd->hash = hash (key); | ||
101 | pd->type = type; | ||
102 | switch (type) | ||
103 | { | ||
104 | case TYPE_POINTER: | ||
105 | pd->value.v = (void *)value; | ||
106 | break; | ||
107 | |||
108 | case TYPE_LONG: | ||
109 | pd->value.l = (long)value; | ||
110 | break; | ||
111 | } | ||
112 | list_append (prop->list, (void *)pd); | ||
113 | } | ||
114 | else | ||
115 | pd->value.v = (void *)value; | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | int | ||
120 | property_get_value (property_t prop, const char *key, void **pvalue, | ||
121 | enum property_type *ptype) | ||
122 | { | ||
123 | struct property_data *pd; | ||
124 | int status; | ||
125 | |||
126 | if (prop == NULL) | ||
127 | return EINVAL; | ||
128 | |||
129 | status = property_find (prop->list, key, &pd); | ||
130 | if (status != 0) | ||
131 | return status; | ||
132 | |||
133 | if (pd == NULL) | ||
134 | return ENOENT; | ||
135 | |||
136 | if (ptype) | ||
137 | *ptype = pd->type; | ||
138 | if (pvalue) | ||
139 | *pvalue = pd->value.v; | ||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | int | ||
144 | property_set (property_t prop, const char *k) | ||
145 | { | ||
146 | return property_set_int (prop, k, 1); | ||
147 | } | ||
148 | |||
149 | int | ||
150 | property_unset (property_t prop, const char *k) | ||
151 | { | ||
152 | return property_set_int (prop, k, 0); | ||
153 | } | ||
154 | |||
155 | int | ||
156 | property_is_set (property_t prop, const char *k) | ||
157 | { | ||
158 | return property_get_int (prop, k); | ||
159 | } | ||
160 | |||
161 | int | ||
162 | property_set_int (property_t prop, const char *k, int i) | ||
163 | { | ||
164 | return property_set_value (prop, k, (void *)i, TYPE_LONG); | ||
165 | } | ||
166 | |||
167 | int | ||
168 | property_get_int (property_t prop, const char *k) | ||
169 | { | ||
170 | int value = 0; | ||
171 | property_get_value (prop, k, (void **)&value, NULL); | ||
172 | return value; | ||
173 | } | ||
174 | |||
175 | int | ||
176 | property_set_long (property_t prop, const char *k, long l) | ||
177 | { | ||
178 | return property_set_value (prop, k, (const void *)l, TYPE_LONG); | ||
179 | } | ||
180 | |||
181 | long | ||
182 | property_get_long (property_t prop, const char *k) | ||
183 | { | ||
184 | long value = 0; | ||
185 | property_get_value (prop, k, (void **)&value, NULL); | ||
186 | return value; | ||
187 | } | ||
188 | |||
189 | int | ||
190 | property_set_pointer (property_t prop, const char *k, void *p) | ||
191 | { | ||
192 | return property_set_value (prop, k, p, TYPE_POINTER); | ||
193 | } | ||
194 | |||
195 | void * | ||
196 | property_get_pointer (property_t prop, const char *k) | ||
197 | { | ||
198 | void *value = NULL; | ||
199 | property_get_value (prop, k, &value, NULL); | ||
200 | return value; | ||
201 | } | ||
202 | |||
203 | static size_t | ||
204 | hash (const char *s) | ||
205 | { | ||
206 | size_t hashval; | ||
207 | for (hashval = 0; *s != '\0' ; s++) | ||
208 | { | ||
209 | hashval += (unsigned)*s ; | ||
210 | hashval += (hashval <<10); | ||
211 | hashval ^= (hashval >>6) ; | ||
212 | } | ||
213 | hashval += (hashval <<3); | ||
214 | hashval ^= (hashval >>11); | ||
215 | hashval += (hashval <<15); | ||
216 | return hashval; | ||
217 | } | ||
218 | |||
219 | static int | ||
220 | property_find (list_t list, const char *key, struct property_data **p) | ||
221 | { | ||
222 | int status; | ||
223 | size_t h; | ||
224 | struct property_data *pd = NULL; | ||
225 | iterator_t iterator; | ||
226 | |||
227 | status = iterator_create (&iterator, list); | ||
228 | if (status != 0) | ||
229 | return status; | ||
230 | |||
231 | h = hash (key); | ||
232 | for (iterator_first (iterator); !iterator_is_done (iterator); | ||
233 | iterator_next (iterator)) | ||
234 | { | ||
235 | iterator_current (iterator, (void **)&pd); | ||
236 | if (pd && pd->hash == h) | ||
237 | { | ||
238 | break; | ||
239 | } | ||
240 | pd = NULL; | ||
241 | } | ||
242 | iterator_destroy (&iterator); | ||
243 | *p = pd; | ||
244 | return 0; | ||
245 | } |
1 | %{ | 1 | %{ |
2 | /* GNU mailutils - a suite of utilities for electronic mail | ||
3 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Library Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU Library General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Library General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
18 | |||
2 | %} | 19 | %} |
3 | 20 | ||
4 | %token SIEVE_ADDRESS SIEVE_ALL SIEVE_ALLOF SIEVE_ANYOF SIEVE_COMPARATOR | 21 | %token SIEVE_ADDRESS SIEVE_ALL SIEVE_ALLOF SIEVE_ANYOF SIEVE_COMPARATOR | ... | ... |
1 | /* Scanner for Sieve | ||
2 | created : Alain Magloire | ||
3 | ref: RFC 3028 */ | ||
4 | |||
5 | %{ | 1 | %{ |
2 | /* GNU mailutils - a suite of utilities for electronic mail | ||
3 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Library Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU Library General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Library General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
18 | |||
6 | #include <stdio.h> | 19 | #include <stdio.h> |
7 | #include "y.tab.h" | 20 | #include "y.tab.h" |
21 | /* Scanner for Sieve | ||
22 | created : Alain Magloire | ||
23 | ref: RFC 3028 */ | ||
8 | 24 | ||
9 | void count (); | 25 | void count (); |
10 | %} | 26 | %} | ... | ... |
-
Please register or sign in to post a comment