49 |
#include <mailutils/registrar.h> |
#include <mailutils/registrar.h> |
50 |
#include <mailutils/stream.h> |
#include <mailutils/stream.h> |
51 |
|
|
52 |
void mutil_register_all_mbox_formats(void); |
void mutil_register_all_mbox_formats (void); |
53 |
|
|
54 |
const char *argp_program_version = "sieve (" PACKAGE_STRING ")"; |
const char *argp_program_version = "sieve (" PACKAGE_STRING ")"; |
55 |
|
|
63 |
" P - network protocols (MU_DEBUG_PROT)\n" |
" P - network protocols (MU_DEBUG_PROT)\n" |
64 |
" t - sieve trace (SV_DEBUG_TRACE)\n" |
" t - sieve trace (SV_DEBUG_TRACE)\n" |
65 |
" h - sieve header filling (SV_DEBUG_HDR_FILL)\n" |
" h - sieve header filling (SV_DEBUG_HDR_FILL)\n" |
66 |
" q - sieve message queries (SV_DEBUG_MSG_QUERY)\n" |
" q - sieve message queries (SV_DEBUG_MSG_QUERY)\n"; |
|
; |
|
67 |
|
|
68 |
#define D_DEFAULT "TPt" |
#define D_DEFAULT "TPt" |
69 |
|
|
84 |
"Ticket file for mailbox authentication", 0}, |
"Ticket file for mailbox authentication", 0}, |
85 |
|
|
86 |
{"mailer-url", 'M', "MAILER", 0, |
{"mailer-url", 'M', "MAILER", 0, |
87 |
"Mailer URL (defaults to \"sendmail:\")", 0}, |
"Mailer URL (defaults to \"sendmail:\"). Use `--mailer-url none' to disable creating the mailer (it will disable reject and redirect actions as well)", 0}, |
88 |
|
|
89 |
{"debug", 'd', "FLAGS", OPTION_ARG_OPTIONAL, |
{"debug", 'd', "FLAGS", OPTION_ARG_OPTIONAL, |
90 |
"Debug flags (defaults to \"" D_DEFAULT "\")", 0}, |
"Debug flags (defaults to \"" D_DEFAULT "\")", 0}, |
151 |
case 'T': |
case 'T': |
152 |
opts->debug_level |= MU_DEBUG_TRACE; |
opts->debug_level |= MU_DEBUG_TRACE; |
153 |
break; |
break; |
154 |
|
|
155 |
case 'P': |
case 'P': |
156 |
opts->debug_level |= MU_DEBUG_PROT; |
opts->debug_level |= MU_DEBUG_PROT; |
157 |
break; |
break; |
158 |
|
|
159 |
case 't': |
case 't': |
160 |
opts->debug_level |= SV_DEBUG_TRACE; |
opts->debug_level |= SV_DEBUG_TRACE; |
161 |
break; |
break; |
162 |
|
|
163 |
case 'h': |
case 'h': |
164 |
opts->debug_level |= SV_DEBUG_HDR_FILL; |
opts->debug_level |= SV_DEBUG_HDR_FILL; |
165 |
break; |
break; |
166 |
|
|
167 |
case 'q': |
case 'q': |
168 |
opts->debug_level |= SV_DEBUG_MSG_QUERY; |
opts->debug_level |= SV_DEBUG_MSG_QUERY; |
169 |
break; |
break; |
170 |
|
|
171 |
case 'g': |
case 'g': |
172 |
yydebug = 1; |
yydebug = 1; |
173 |
break; |
break; |
174 |
|
|
175 |
case 'a': |
case 'a': |
176 |
addrdebug = 1; |
addrdebug = 1; |
177 |
break; |
break; |
178 |
|
|
179 |
default: |
default: |
180 |
argp_error (state, "%c is not a valid debug flag", *arg); |
argp_error (state, "%c is not a valid debug flag", *arg); |
181 |
break; |
break; |
214 |
}; |
}; |
215 |
|
|
216 |
char *sieve_license_text = |
char *sieve_license_text = |
217 |
" Copyright 1999 by Carnegie Mellon University\n" |
" Copyright 1999 by Carnegie Mellon University\n" |
218 |
" Copyright 1999,2001,2002 by Free Software Foundation\n" |
" Copyright 1999,2001,2002 by Free Software Foundation\n" |
219 |
"\n" |
"\n" |
220 |
" Permission to use, copy, modify, and distribute this software and its\n" |
" Permission to use, copy, modify, and distribute this software and its\n" |
221 |
" documentation for any purpose and without fee is hereby granted,\n" |
" documentation for any purpose and without fee is hereby granted,\n" |
222 |
" provided that the above copyright notice appear in all copies and that\n" |
" provided that the above copyright notice appear in all copies and that\n" |
223 |
" both that copyright notice and this permission notice appear in\n" |
" both that copyright notice and this permission notice appear in\n" |
224 |
" supporting documentation, and that the name of Carnegie Mellon\n" |
" supporting documentation, and that the name of Carnegie Mellon\n" |
225 |
" University not be used in advertising or publicity pertaining to\n" |
" University not be used in advertising or publicity pertaining to\n" |
226 |
" distribution of the software without specific, written prior\n" |
" distribution of the software without specific, written prior\n" |
227 |
" permission.\n"; |
" permission.\n"; |
228 |
|
|
229 |
|
|
230 |
static void |
static void |
291 |
|
|
292 |
/* Override license text: */ |
/* Override license text: */ |
293 |
mu_license_text = sieve_license_text; |
mu_license_text = sieve_license_text; |
294 |
rc = mu_argp_parse(&argp, &argc, &argv, ARGP_IN_ORDER, sieve_argp_capa, |
rc = mu_argp_parse (&argp, &argc, &argv, ARGP_IN_ORDER, sieve_argp_capa, |
295 |
0, &opts); |
0, &opts); |
296 |
|
|
297 |
if (rc) { |
if (rc) |
298 |
|
{ |
299 |
fprintf (stderr, "arg parsing failed: %s\n", sv_strerror (rc)); |
fprintf (stderr, "arg parsing failed: %s\n", sv_strerror (rc)); |
300 |
return 1; |
return 1; |
301 |
} |
} |
302 |
|
|
303 |
mutil_register_all_mbox_formats (); |
mutil_register_all_mbox_formats (); |
304 |
|
|
353 |
} |
} |
354 |
if ((rc = mu_debug_set_level (debug, opts.debug_level))) |
if ((rc = mu_debug_set_level (debug, opts.debug_level))) |
355 |
{ |
{ |
356 |
fprintf (stderr, "mu_debug_set_level failed: %s\n", mu_errstring (rc)); |
fprintf (stderr, "mu_debug_set_level failed: %s\n", |
357 |
|
mu_errstring (rc)); |
358 |
goto cleanup; |
goto cleanup; |
359 |
} |
} |
360 |
if ((rc = mu_debug_set_print (debug, debug_print, interp))) |
if ((rc = mu_debug_set_print (debug, debug_print, interp))) |
361 |
{ |
{ |
362 |
fprintf (stderr, "mu_debug_set_print failed: %s\n", mu_errstring (rc)); |
fprintf (stderr, "mu_debug_set_print failed: %s\n", |
363 |
|
mu_errstring (rc)); |
364 |
goto cleanup; |
goto cleanup; |
365 |
} |
} |
366 |
} |
} |
367 |
|
|
368 |
/* Create a mailer. */ |
/* Create a mailer. */ |
369 |
if ((rc = mailer_create(&mailer, opts.mailer))) |
if (strcmp (opts.mailer, "none")) |
|
{ |
|
|
fprintf (stderr, "mailer create <%s> failed: %s\n", |
|
|
opts.mailer, mu_errstring (rc)); |
|
|
goto cleanup; |
|
|
} |
|
|
if (debug && (rc = mailer_set_debug (mailer, debug))) |
|
370 |
{ |
{ |
371 |
fprintf (stderr, "mailer_set_debug failed: %s\n", mu_errstring (rc)); |
if ((rc = mailer_create (&mailer, opts.mailer))) |
372 |
goto cleanup; |
{ |
373 |
|
fprintf (stderr, "mailer create <%s> failed: %s\n", |
374 |
|
opts.mailer, mu_errstring (rc)); |
375 |
|
goto cleanup; |
376 |
|
} |
377 |
|
if (debug && (rc = mailer_set_debug (mailer, debug))) |
378 |
|
{ |
379 |
|
fprintf (stderr, "mailer_set_debug failed: %s\n", |
380 |
|
mu_errstring (rc)); |
381 |
|
goto cleanup; |
382 |
|
} |
383 |
} |
} |
|
|
|
384 |
/* Create, give a ticket to, and open the mailbox. */ |
/* Create, give a ticket to, and open the mailbox. */ |
385 |
if ((rc = mailbox_create_default (&mbox, opts.mbox)) != 0) |
if ((rc = mailbox_create_default (&mbox, opts.mbox)) != 0) |
386 |
{ |
{ |
388 |
opts.mbox ? opts.mbox : "default", mu_errstring (rc)); |
opts.mbox ? opts.mbox : "default", mu_errstring (rc)); |
389 |
goto cleanup; |
goto cleanup; |
390 |
} |
} |
391 |
|
|
392 |
if (debug && (rc = mailbox_set_debug (mbox, debug))) |
if (debug && (rc = mailbox_set_debug (mbox, debug))) |
393 |
{ |
{ |
394 |
fprintf (stderr, "mailbox_set_debug failed: %s\n", mu_errstring (rc)); |
fprintf (stderr, "mailbox_set_debug failed: %s\n", mu_errstring (rc)); |
402 |
|
|
403 |
if ((rc = mailbox_get_folder (mbox, &folder))) |
if ((rc = mailbox_get_folder (mbox, &folder))) |
404 |
{ |
{ |
405 |
fprintf (stderr, "mailbox_get_folder failed: %s", mu_errstring (rc)); |
fprintf (stderr, "mailbox_get_folder failed: %s", |
406 |
|
mu_errstring (rc)); |
407 |
goto cleanup; |
goto cleanup; |
408 |
} |
} |
409 |
|
|
410 |
if ((rc = folder_get_authority (folder, &auth))) |
if ((rc = folder_get_authority (folder, &auth))) |
411 |
{ |
{ |
412 |
fprintf (stderr, "folder_get_authority failed: %s", mu_errstring (rc)); |
fprintf (stderr, "folder_get_authority failed: %s", |
413 |
|
mu_errstring (rc)); |
414 |
goto cleanup; |
goto cleanup; |
415 |
} |
} |
416 |
|
|
417 |
/* Authentication-less folders don't have authorities. */ |
/* Authentication-less folders don't have authorities. */ |
418 |
if (auth && (rc = authority_set_ticket (auth, ticket))) |
if (auth && (rc = authority_set_ticket (auth, ticket))) |
419 |
{ |
{ |
420 |
fprintf (stderr, "authority_set_ticket failed: %s", mu_errstring (rc)); |
fprintf (stderr, "authority_set_ticket failed: %s", |
421 |
|
mu_errstring (rc)); |
422 |
goto cleanup; |
goto cleanup; |
423 |
} |
} |
424 |
} |
} |
453 |
if ((rc = mailbox_get_message (mbox, msgno, &msg)) != 0) |
if ((rc = mailbox_get_message (mbox, msgno, &msg)) != 0) |
454 |
{ |
{ |
455 |
fprintf (stderr, "get message on %s (msg %d) failed: %s\n", |
fprintf (stderr, "get message on %s (msg %d) failed: %s\n", |
456 |
opts.mbox ? opts.mbox : "default", msgno, mu_errstring (rc)); |
opts.mbox ? opts.mbox : "default", msgno, |
457 |
|
mu_errstring (rc)); |
458 |
goto cleanup; |
goto cleanup; |
459 |
} |
} |
460 |
|
|
461 |
rc = sv_script_execute (script, msg, ticket, debug, mailer, opts.no_actions); |
rc = |
462 |
|
sv_script_execute (script, msg, ticket, debug, mailer, |
463 |
|
opts.no_actions); |
464 |
|
|
465 |
if (rc) |
if (rc) |
466 |
{ |
{ |
480 |
int e; |
int e; |
481 |
|
|
482 |
/* A message won't be marked deleted unless the script executed |
/* A message won't be marked deleted unless the script executed |
483 |
succesfully on it, so we always do an expunge, it will delete |
succesfully on it, so we always do an expunge, it will delete |
484 |
any messages that were marked DELETED even if execution failed |
any messages that were marked DELETED even if execution failed |
485 |
on a later message. */ |
on a later message. */ |
486 |
if ((e = mailbox_expunge (mbox)) != 0) |
if ((e = mailbox_expunge (mbox)) != 0) |
487 |
fprintf (stderr, "expunge on %s failed: %s\n", |
fprintf (stderr, "expunge on %s failed: %s\n", |
488 |
opts.mbox ? opts.mbox : "default", mu_errstring (e)); |
opts.mbox ? opts.mbox : "default", mu_errstring (e)); |
489 |
|
|
490 |
if(e && !rc) |
if (e && !rc) |
491 |
rc = e; |
rc = e; |
492 |
} |
} |
493 |
|
|
494 |
mailbox_close (mbox); |
mailbox_close (mbox); |
495 |
mailbox_destroy (&mbox); |
mailbox_destroy (&mbox); |
496 |
mu_debug_destroy(&debug, interp); |
mu_debug_destroy (&debug, interp); |
497 |
sv_script_free (&script); |
sv_script_free (&script); |
498 |
sv_interp_free (&interp); |
sv_interp_free (&interp); |
499 |
|
|
514 |
list_append (bookie, sendmail_record); |
list_append (bookie, sendmail_record); |
515 |
list_append (bookie, smtp_record); |
list_append (bookie, smtp_record); |
516 |
} |
} |
|
|
|