Line 0
Link Here
|
|
|
1 |
#include <stdio.h> |
2 |
#include <stdlib.h> |
3 |
#include <string.h> |
4 |
|
5 |
#ifdef HAVE_UNISTD_H |
6 |
#include <unistd.h> |
7 |
#endif |
8 |
|
9 |
#include <errno.h> |
10 |
#include <sys/types.h> |
11 |
#include <sys/stat.h> |
12 |
#include <sys/uio.h> |
13 |
#include <fcntl.h> |
14 |
#include <ctype.h> |
15 |
#include <time.h> |
16 |
#include <syslog.h> |
17 |
#include <com_err.h> |
18 |
#include <config.h> |
19 |
|
20 |
#include "global.h" |
21 |
#include "util.h" |
22 |
#include "mailbox.h" |
23 |
#include "imap_err.h" |
24 |
#include "sieve_interface.h" |
25 |
#include "script.h" |
26 |
|
27 |
#define TIMSIEVE_FAIL -1 |
28 |
#define TIMSIEVE_OK 0 |
29 |
#define MAX_FILENAME 1024 |
30 |
|
31 |
static int get_script_name(char *sievename, size_t buflen, const char *filename); |
32 |
static int get_script_dir(char *sieve_script_dir, size_t buflen, char *userid, const char *sieve_dir); |
33 |
int autoadd_sieve(char *userid, const char *source_script); |
34 |
|
35 |
static void fatal(const char *s, int code); |
36 |
static void foo(void); |
37 |
static int sieve_notify(void *ac __attribute__((unused)), |
38 |
void *interp_context __attribute__((unused)), |
39 |
void *script_context __attribute__((unused)), |
40 |
void *message_context __attribute__((unused)), |
41 |
const char **errmsg __attribute__((unused))); |
42 |
static int mysieve_error(int lineno, const char *msg, |
43 |
void *i __attribute__((unused)), void *s); |
44 |
static int is_script_parsable(FILE *stream, char **errstr, sieve_script_t **ret); |
45 |
|
46 |
|
47 |
sieve_vacation_t vacation2 = { |
48 |
0, /* min response */ |
49 |
0, /* max response */ |
50 |
(sieve_callback *) &foo, /* autorespond() */ |
51 |
(sieve_callback *) &foo /* send_response() */ |
52 |
}; |
53 |
|
54 |
|
55 |
/* |
56 |
* Find the name of the sieve script |
57 |
* given the source script and compiled script names |
58 |
*/ |
59 |
static int get_script_name(char *sievename, size_t buflen, const char *filename) |
60 |
{ |
61 |
char *p; |
62 |
int r; |
63 |
|
64 |
p = strrchr(filename, '/'); |
65 |
if (p == NULL) |
66 |
p = (char *) filename; |
67 |
else |
68 |
p++; |
69 |
|
70 |
r = strlcpy(sievename, p, buflen) - buflen; |
71 |
return (r >= 0 || r == -buflen ? 1 : 0); |
72 |
} |
73 |
|
74 |
|
75 |
/* |
76 |
* Find the directory where the sieve scripts of the user |
77 |
* reside |
78 |
*/ |
79 |
static int get_script_dir(char *sieve_script_dir, size_t buflen, char *userid, const char *sieve_dir) |
80 |
{ |
81 |
char *user = NULL, *domain = NULL; |
82 |
|
83 |
/* Setup the user and the domain */ |
84 |
if(config_virtdomains && (domain = strchr(userid, '@'))) { |
85 |
user = (char *) xmalloc((domain - userid +1) * sizeof(char)); |
86 |
strlcpy(user, userid, domain - userid + 1); |
87 |
domain++; |
88 |
} else |
89 |
user = userid; |
90 |
|
91 |
/* Find the dir path where the sieve scripts of the user will reside */ |
92 |
if (config_virtdomains && domain) { |
93 |
if(snprintf(sieve_script_dir, buflen, "%s%s%c/%s/%c/%s/", |
94 |
sieve_dir, FNAME_DOMAINDIR, dir_hash_c(domain), domain, dir_hash_c(user), user) >= buflen) { |
95 |
free(user); |
96 |
return 1; |
97 |
} |
98 |
} else { |
99 |
if(snprintf(sieve_script_dir, buflen, "%s/%c/%s/", |
100 |
sieve_dir, dir_hash_c(user), user) >= buflen) |
101 |
return 1; |
102 |
} |
103 |
|
104 |
/* Free the xmalloced user memory, reserved above */ |
105 |
if(user != userid) |
106 |
free(user); |
107 |
|
108 |
return 0; |
109 |
} |
110 |
|
111 |
int autoadd_sieve(char *userid, const char *source_script) |
112 |
{ |
113 |
sieve_script_t *s = NULL; |
114 |
bytecode_info_t *bc = NULL; |
115 |
char *err = NULL; |
116 |
FILE *in_stream, *out_fp; |
117 |
int out_fd, in_fd, r, k; |
118 |
int do_compile = 0; |
119 |
const char *sieve_dir = NULL; |
120 |
const char *compiled_source_script = NULL; |
121 |
char sievename[MAX_FILENAME]; |
122 |
char sieve_script_name[MAX_FILENAME]; |
123 |
char sieve_script_dir[MAX_FILENAME]; |
124 |
char sieve_bcscript_name[MAX_FILENAME]; |
125 |
char sieve_default[MAX_FILENAME]; |
126 |
char sieve_tmpname[MAX_FILENAME]; |
127 |
char sieve_bctmpname[MAX_FILENAME]; |
128 |
char sieve_bclink_name[MAX_FILENAME]; |
129 |
char buf[4096]; |
130 |
mode_t oldmask; |
131 |
struct stat statbuf; |
132 |
|
133 |
/* We don't support using the homedirectory, like timsieved */ |
134 |
if (config_getswitch(IMAPOPT_SIEVEUSEHOMEDIR)) { |
135 |
syslog(LOG_WARNING,"autocreate_sieve: autocreate_sieve does not work with sieveusehomedir option in imapd.conf"); |
136 |
return 1; |
137 |
} |
138 |
|
139 |
/* Check if sievedir is defined in imapd.conf */ |
140 |
if(!(sieve_dir = config_getstring(IMAPOPT_SIEVEDIR))) { |
141 |
syslog(LOG_WARNING, "autocreate_sieve: sievedir option is not defined. Check imapd.conf"); |
142 |
return 1; |
143 |
} |
144 |
|
145 |
/* Check if autocreate_sieve_compiledscript is defined in imapd.conf */ |
146 |
if(!(compiled_source_script = config_getstring(IMAPOPT_AUTOCREATE_SIEVE_COMPILEDSCRIPT))) { |
147 |
syslog(LOG_WARNING, "autocreate_sieve: autocreate_sieve_compiledscript option is not defined. Compiling it"); |
148 |
do_compile = 1; |
149 |
} |
150 |
|
151 |
if(get_script_dir(sieve_script_dir, sizeof(sieve_script_dir), userid, sieve_dir)) { |
152 |
syslog(LOG_WARNING, "autocreate_sieve: Cannot find sieve scripts directory"); |
153 |
return 1; |
154 |
} |
155 |
|
156 |
if (get_script_name(sievename, sizeof(sievename), source_script)) { |
157 |
syslog(LOG_WARNING, "autocreate_sieve: Invalid sieve script %s", source_script); |
158 |
return 1; |
159 |
} |
160 |
|
161 |
if(snprintf(sieve_tmpname, sizeof(sieve_tmpname), "%s%s.script.NEW",sieve_script_dir, sievename) >= sizeof(sieve_tmpname)) { |
162 |
syslog(LOG_WARNING, "autocreate_sieve: Invalid sieve path %s, %s, %s", sieve_dir, sievename, userid); |
163 |
return 1; |
164 |
} |
165 |
if(snprintf(sieve_bctmpname, sizeof(sieve_bctmpname), "%s%s.bc.NEW",sieve_script_dir, sievename) >= sizeof(sieve_bctmpname)) { |
166 |
syslog(LOG_WARNING, "autocreate_sieve: Invalid sieve path %s, %s, %s", sieve_dir, sievename, userid); |
167 |
return 1; |
168 |
} |
169 |
if(snprintf(sieve_script_name, sizeof(sieve_script_name), "%s%s.script",sieve_script_dir, sievename) >= sizeof(sieve_script_name)) { |
170 |
syslog(LOG_WARNING, "autocreate_sieve: Invalid sieve path %s, %s, %s", sieve_dir, sievename, userid); |
171 |
return 1; |
172 |
} |
173 |
if(snprintf(sieve_bcscript_name, sizeof(sieve_bcscript_name), "%s%s.bc",sieve_script_dir, sievename) >= sizeof(sieve_bcscript_name)) { |
174 |
syslog(LOG_WARNING, "autocreate_sieve: Invalid sieve path %s, %s, %s", sieve_dir, sievename, userid); |
175 |
return 1; |
176 |
} |
177 |
if(snprintf(sieve_default, sizeof(sieve_default), "%s%s",sieve_script_dir,"defaultbc") >= sizeof(sieve_default)) { |
178 |
syslog(LOG_WARNING, "autocreate_sieve: Invalid sieve path %s, %s, %s", sieve_dir, sievename, userid); |
179 |
return 1; |
180 |
} |
181 |
if(snprintf(sieve_bclink_name, sizeof(sieve_bclink_name), "%s.bc", sievename) >= sizeof(sieve_bclink_name)) { |
182 |
syslog(LOG_WARNING, "autocreate_sieve: Invalid sieve path %s, %s, %s", sieve_dir, sievename, userid); |
183 |
return 1; |
184 |
} |
185 |
|
186 |
/* Check if a default sieve filter alrady exists */ |
187 |
if(!stat(sieve_default,&statbuf)) { |
188 |
syslog(LOG_WARNING,"autocreate_sieve: Default sieve script already exists"); |
189 |
fclose(in_stream); |
190 |
return 1; |
191 |
} |
192 |
|
193 |
/* Open the source script. if there is a problem with that exit */ |
194 |
in_stream = fopen(source_script, "r"); |
195 |
if(!in_stream) { |
196 |
syslog(LOG_WARNING,"autocreate_sieve: Unable to open sieve script %s. Check permissions",source_script); |
197 |
return 1; |
198 |
} |
199 |
|
200 |
|
201 |
/* |
202 |
* At this point we start the modifications of the filesystem |
203 |
*/ |
204 |
|
205 |
/* Create the directory where the sieve scripts will reside */ |
206 |
r = cyrus_mkdir(sieve_script_dir, 0755); |
207 |
if(r == -1) { |
208 |
/* If this fails we just leave */ |
209 |
syslog(LOG_WARNING,"autocreate_sieve: Unable to create directory %s. Check permissions",sieve_script_name); |
210 |
return 1; |
211 |
} |
212 |
|
213 |
/* |
214 |
* We open the file that will be used as the bc file. If this file exists, overwrite it |
215 |
* since something bad has happened. We open the file here so that this error checking is |
216 |
* done before we try to open the rest of the files to start copying etc. |
217 |
*/ |
218 |
out_fd = open(sieve_bctmpname, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); |
219 |
if(out_fd < 0) { |
220 |
if(errno == EEXIST) { |
221 |
syslog(LOG_WARNING,"autocreate_sieve: File %s already exists. Probaly left over. Ignoring",sieve_bctmpname); |
222 |
} else if (errno == EACCES) { |
223 |
syslog(LOG_WARNING,"autocreate_sieve: No access to create file %s. Check permissions",sieve_bctmpname); |
224 |
fclose(in_stream); |
225 |
return 1; |
226 |
} else { |
227 |
syslog(LOG_WARNING,"autocreate_sieve: Unable to create %s. Unknown error",sieve_bctmpname); |
228 |
fclose(in_stream); |
229 |
return 1; |
230 |
} |
231 |
} |
232 |
|
233 |
if(!do_compile && compiled_source_script && (in_fd = open(compiled_source_script, O_RDONLY)) != -1) { |
234 |
while((r = read(in_fd, buf, sizeof(buf))) > 0) { |
235 |
if((k=write(out_fd, buf,r)) < 0) { |
236 |
syslog(LOG_WARNING, "autocreate_sieve: Error writing to file: %s, error: %d", sieve_bctmpname, errno); |
237 |
close(out_fd); |
238 |
close(in_fd); |
239 |
fclose(in_stream); |
240 |
unlink(sieve_bctmpname); |
241 |
return 1; |
242 |
} |
243 |
} |
244 |
|
245 |
if(r == 0) { /* EOF */ |
246 |
close(out_fd); |
247 |
close(in_fd); |
248 |
} else if (r < 0) { |
249 |
syslog(LOG_WARNING, "autocreate_sieve: Error reading compiled script file: %s. Will try to compile it", |
250 |
compiled_source_script); |
251 |
close(in_fd); |
252 |
do_compile = 1; |
253 |
if(lseek(out_fd, 0, SEEK_SET)) { |
254 |
syslog(LOG_WARNING, "autocreate_sieve: Major IO problem. Aborting"); |
255 |
return 1; |
256 |
} |
257 |
} |
258 |
close(in_fd); |
259 |
} else { |
260 |
if(compiled_source_script) |
261 |
syslog(LOG_WARNING,"autocreate_sieve: Problem opening compiled script file: %s. Compiling it", compiled_source_script); |
262 |
do_compile = 1; |
263 |
} |
264 |
|
265 |
|
266 |
/* Because we failed to open a precompiled bc sieve script, we compile one */ |
267 |
if(do_compile) { |
268 |
if(is_script_parsable(in_stream,&err, &s) == TIMSIEVE_FAIL) { |
269 |
if(err && *err) { |
270 |
syslog(LOG_WARNING,"autocreate_sieve: Error while parsing script %s.",err); |
271 |
free(err); |
272 |
} else |
273 |
syslog(LOG_WARNING,"autocreate_sieve: Error while parsing script"); |
274 |
|
275 |
unlink(sieve_bctmpname); |
276 |
fclose(in_stream); |
277 |
close(out_fd); |
278 |
return 1; |
279 |
} |
280 |
|
281 |
/* generate the bytecode */ |
282 |
if(sieve_generate_bytecode(&bc, s) == TIMSIEVE_FAIL) { |
283 |
syslog(LOG_WARNING,"autocreate_sieve: problem compiling sieve script"); |
284 |
/* removing the copied script and cleaning up memory */ |
285 |
unlink(sieve_bctmpname); |
286 |
sieve_script_free(&s); |
287 |
fclose(in_stream); |
288 |
close(out_fd); |
289 |
return 1; |
290 |
} |
291 |
|
292 |
if(sieve_emit_bytecode(out_fd, bc) == TIMSIEVE_FAIL) { |
293 |
syslog(LOG_WARNING,"autocreate_sieve: problem emiting sieve script"); |
294 |
/* removing the copied script and cleaning up memory */ |
295 |
unlink(sieve_bctmpname); |
296 |
sieve_free_bytecode(&bc); |
297 |
sieve_script_free(&s); |
298 |
fclose(in_stream); |
299 |
close(out_fd); |
300 |
return 1; |
301 |
} |
302 |
|
303 |
/* clean up the memory */ |
304 |
sieve_free_bytecode(&bc); |
305 |
sieve_script_free(&s); |
306 |
} |
307 |
|
308 |
close(out_fd); |
309 |
rewind(in_stream); |
310 |
|
311 |
/* Copy the initial script */ |
312 |
oldmask = umask(077); |
313 |
if((out_fp = fopen(sieve_tmpname, "w")) == NULL) { |
314 |
syslog(LOG_WARNING,"autocreate_sieve: Unable to open %s destination sieve script", sieve_tmpname); |
315 |
unlink(sieve_bctmpname); |
316 |
umask(oldmask); |
317 |
fclose(in_stream); |
318 |
return 1; |
319 |
} |
320 |
umask(oldmask); |
321 |
|
322 |
while((r = fread(buf,sizeof(char), sizeof(buf), in_stream))) { |
323 |
if( fwrite(buf,sizeof(char), r, out_fp) != r) { |
324 |
syslog(LOG_WARNING,"autocreate_sieve: Problem writing to sieve script file: %s",sieve_tmpname); |
325 |
fclose(out_fp); |
326 |
unlink(sieve_tmpname); |
327 |
unlink(sieve_bctmpname); |
328 |
fclose(in_stream); |
329 |
return 1; |
330 |
} |
331 |
} |
332 |
|
333 |
if(feof(in_stream)) { |
334 |
fclose(out_fp); |
335 |
} else { /* ferror */ |
336 |
fclose(out_fp); |
337 |
unlink(sieve_tmpname); |
338 |
unlink(sieve_bctmpname); |
339 |
fclose(in_stream); |
340 |
return 1; |
341 |
} |
342 |
|
343 |
/* Renaming the necessary stuff */ |
344 |
if(rename(sieve_tmpname, sieve_script_name)) { |
345 |
unlink(sieve_tmpname); |
346 |
unlink(sieve_bctmpname); |
347 |
return 1; |
348 |
} |
349 |
|
350 |
if(rename(sieve_bctmpname, sieve_bcscript_name)) { |
351 |
unlink(sieve_bctmpname); |
352 |
unlink(sieve_bcscript_name); |
353 |
return 1; |
354 |
} |
355 |
|
356 |
/* end now with the symlink */ |
357 |
if(symlink(sieve_bclink_name, sieve_default)) { |
358 |
if(errno != EEXIST) { |
359 |
syslog(LOG_WARNING, "autocreate_sieve: problem making the default link."); |
360 |
/* Lets delete the files */ |
361 |
unlink(sieve_script_name); |
362 |
unlink(sieve_bcscript_name); |
363 |
} |
364 |
} |
365 |
|
366 |
/* |
367 |
* If everything has succeeded AND we have compiled the script AND we have requested |
368 |
* to generate the global script so that it is not compiled each time then we create it. |
369 |
*/ |
370 |
if(do_compile && |
371 |
config_getswitch(IMAPOPT_GENERATE_COMPILED_SIEVE_SCRIPT)) { |
372 |
|
373 |
if(!compiled_source_script) { |
374 |
syslog(LOG_WARNING, "autocreate_sieve: To save a compiled sieve script, autocreate_sieve_compiledscript must have been defined in imapd.conf"); |
375 |
return 0; |
376 |
} |
377 |
|
378 |
if(snprintf(sieve_tmpname, sizeof(sieve_tmpname), "%s.NEW", compiled_source_script) >= sizeof(sieve_tmpname)) |
379 |
return 0; |
380 |
|
381 |
/* |
382 |
* Copy everything from the newly created bc sieve sieve script. |
383 |
*/ |
384 |
if((in_fd = open(sieve_bcscript_name, O_RDONLY))<0) { |
385 |
return 0; |
386 |
} |
387 |
|
388 |
if((out_fd = open(sieve_tmpname, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) { |
389 |
if(errno == EEXIST) { |
390 |
/* Someone is already doing this so just bail out. */ |
391 |
syslog(LOG_WARNING, "autocreate_sieve: %s already exists. Some other instance processing it, or it is left over", sieve_tmpname); |
392 |
close(in_fd); |
393 |
return 0; |
394 |
} else if (errno == EACCES) { |
395 |
syslog(LOG_WARNING,"autocreate_sieve: No access to create file %s. Check permissions",sieve_tmpname); |
396 |
close(in_fd); |
397 |
return 0; |
398 |
} else { |
399 |
syslog(LOG_WARNING,"autocreate_sieve: Unable to create %s",sieve_tmpname); |
400 |
close(in_fd); |
401 |
return 0; |
402 |
} |
403 |
} |
404 |
|
405 |
while((r = read(in_fd, buf, sizeof(buf))) > 0) { |
406 |
if((k = write(out_fd,buf,r)) < 0) { |
407 |
syslog(LOG_WARNING, "autocreate_sieve: Error writing to file: %s, error: %d", sieve_tmpname, errno); |
408 |
close(out_fd); |
409 |
close(in_fd); |
410 |
unlink(sieve_tmpname); |
411 |
return 0; |
412 |
} |
413 |
} |
414 |
|
415 |
if(r == 0 ) { /*EOF */ |
416 |
close(out_fd); |
417 |
close(in_fd); |
418 |
} else if (r < 0) { |
419 |
syslog(LOG_WARNING, "autocreate_sieve: Error writing to file: %s, error: %d", sieve_tmpname, errno); |
420 |
close(out_fd); |
421 |
close(in_fd); |
422 |
unlink(sieve_tmpname); |
423 |
return 0; |
424 |
} |
425 |
|
426 |
/* Rename the temporary created sieve script to its final name. */ |
427 |
if(rename(sieve_tmpname, compiled_source_script)) { |
428 |
if(errno != EEXIST) { |
429 |
unlink(sieve_tmpname); |
430 |
unlink(compiled_source_script); |
431 |
} |
432 |
return 0; |
433 |
} |
434 |
|
435 |
syslog(LOG_NOTICE, "autocreate_sieve: Compiled sieve script was successfully saved in %s", compiled_source_script); |
436 |
} |
437 |
|
438 |
return 0; |
439 |
} |
440 |
|
441 |
static void fatal(const char *s, int code) |
442 |
{ |
443 |
printf("Fatal error: %s (%d)\r\n", s, code); |
444 |
exit(1); |
445 |
} |
446 |
|
447 |
/* to make larry's stupid functions happy :) */ |
448 |
static void foo(void) |
449 |
{ |
450 |
fatal("stub function called", 0); |
451 |
} |
452 |
|
453 |
static int sieve_notify(void *ac __attribute__((unused)), |
454 |
void *interp_context __attribute__((unused)), |
455 |
void *script_context __attribute__((unused)), |
456 |
void *message_context __attribute__((unused)), |
457 |
const char **errmsg __attribute__((unused))) |
458 |
{ |
459 |
fatal("stub function called", 0); |
460 |
return SIEVE_FAIL; |
461 |
} |
462 |
|
463 |
static int mysieve_error(int lineno, const char *msg, |
464 |
void *i __attribute__((unused)), void *s) |
465 |
{ |
466 |
char buf[1024]; |
467 |
char **errstr = (char **) s; |
468 |
|
469 |
snprintf(buf, 80, "line %d: %s\r\n", lineno, msg); |
470 |
*errstr = (char *) xrealloc(*errstr, strlen(*errstr) + strlen(buf) + 30); |
471 |
syslog(LOG_DEBUG, "%s", buf); |
472 |
strcat(*errstr, buf); |
473 |
|
474 |
return SIEVE_OK; |
475 |
} |
476 |
|
477 |
/* end the boilerplate */ |
478 |
|
479 |
/* returns TRUE or FALSE */ |
480 |
int is_script_parsable(FILE *stream, char **errstr, sieve_script_t **ret) |
481 |
{ |
482 |
sieve_interp_t *i; |
483 |
sieve_script_t *s; |
484 |
int res; |
485 |
|
486 |
res = sieve_interp_alloc(&i, NULL); |
487 |
if (res != SIEVE_OK) { |
488 |
syslog(LOG_WARNING, "sieve_interp_alloc() returns %d\n", res); |
489 |
return TIMSIEVE_FAIL; |
490 |
} |
491 |
|
492 |
res = sieve_register_redirect(i, (sieve_callback *) &foo); |
493 |
if (res != SIEVE_OK) { |
494 |
syslog(LOG_WARNING, "sieve_register_redirect() returns %d\n", res); |
495 |
return TIMSIEVE_FAIL; |
496 |
} |
497 |
res = sieve_register_discard(i, (sieve_callback *) &foo); |
498 |
if (res != SIEVE_OK) { |
499 |
syslog(LOG_WARNING, "sieve_register_discard() returns %d\n", res); |
500 |
return TIMSIEVE_FAIL; |
501 |
} |
502 |
res = sieve_register_reject(i, (sieve_callback *) &foo); |
503 |
if (res != SIEVE_OK) { |
504 |
syslog(LOG_WARNING, "sieve_register_reject() returns %d\n", res); |
505 |
return TIMSIEVE_FAIL; |
506 |
} |
507 |
res = sieve_register_fileinto(i, (sieve_callback *) &foo); |
508 |
if (res != SIEVE_OK) { |
509 |
syslog(LOG_WARNING, "sieve_register_fileinto() returns %d\n", res); |
510 |
return TIMSIEVE_FAIL; |
511 |
} |
512 |
res = sieve_register_keep(i, (sieve_callback *) &foo); |
513 |
if (res != SIEVE_OK) { |
514 |
syslog(LOG_WARNING, "sieve_register_keep() returns %d\n", res); |
515 |
return TIMSIEVE_FAIL; |
516 |
} |
517 |
|
518 |
res = sieve_register_imapflags(i, NULL); |
519 |
if (res != SIEVE_OK) { |
520 |
syslog(LOG_WARNING, "sieve_register_imapflags() returns %d\n", res); |
521 |
return TIMSIEVE_FAIL; |
522 |
} |
523 |
|
524 |
res = sieve_register_size(i, (sieve_get_size *) &foo); |
525 |
if (res != SIEVE_OK) { |
526 |
syslog(LOG_WARNING, "sieve_register_size() returns %d\n", res); |
527 |
return TIMSIEVE_FAIL; |
528 |
} |
529 |
|
530 |
res = sieve_register_header(i, (sieve_get_header *) &foo); |
531 |
if (res != SIEVE_OK) { |
532 |
syslog(LOG_WARNING, "sieve_register_header() returns %d\n", res); |
533 |
return TIMSIEVE_FAIL; |
534 |
} |
535 |
|
536 |
res = sieve_register_envelope(i, (sieve_get_envelope *) &foo); |
537 |
if (res != SIEVE_OK) { |
538 |
syslog(LOG_WARNING, "sieve_register_envelope() returns %d\n", res); |
539 |
return TIMSIEVE_FAIL; |
540 |
} |
541 |
|
542 |
res = sieve_register_vacation(i, &vacation2); |
543 |
if (res != SIEVE_OK) { |
544 |
syslog(LOG_WARNING, "sieve_register_vacation() returns %d\n", res); |
545 |
return TIMSIEVE_FAIL; |
546 |
} |
547 |
|
548 |
res = sieve_register_notify(i, &sieve_notify); |
549 |
if (res != SIEVE_OK) { |
550 |
syslog(LOG_WARNING, "sieve_register_notify() returns %d\n", res); |
551 |
return TIMSIEVE_FAIL; |
552 |
} |
553 |
|
554 |
res = sieve_register_parse_error(i, &mysieve_error); |
555 |
if (res != SIEVE_OK) { |
556 |
syslog(LOG_WARNING, "sieve_register_parse_error() returns %d\n", res); |
557 |
return TIMSIEVE_FAIL; |
558 |
} |
559 |
|
560 |
rewind(stream); |
561 |
|
562 |
*errstr = (char *) xmalloc(20 * sizeof(char)); |
563 |
strcpy(*errstr, "script errors:\r\n"); |
564 |
|
565 |
res = sieve_script_parse(i, stream, errstr, &s); |
566 |
|
567 |
if (res == SIEVE_OK) { |
568 |
if(ret) { |
569 |
*ret = s; |
570 |
} else { |
571 |
sieve_script_free(&s); |
572 |
} |
573 |
free(*errstr); |
574 |
*errstr = NULL; |
575 |
} |
576 |
|
577 |
/* free interpreter */ |
578 |
sieve_interp_free(&i); |
579 |
|
580 |
return (res == SIEVE_OK) ? TIMSIEVE_OK : TIMSIEVE_FAIL; |
581 |
} |
582 |
|
583 |
/* |
584 |
* Btw the initial date of this patch is Sep, 02 2004 which is the birthday of |
585 |
* Pavlos. Author of cyrusmaster. So consider this patch as his birthday present |
586 |
*/ |
587 |
|