1 |
/* GNU mailutils - a suite of utilities for electronic mail |
/* GNU Mailutils -- a suite of utilities for electronic mail |
2 |
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. |
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
GNU Mailutils 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 |
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) |
the Free Software Foundation; either version 2, or (at your option) |
7 |
any later version. |
any later version. |
8 |
|
|
9 |
This program is distributed in the hope that it will be useful, |
GNU Mailutils is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU Library General Public License for more details. |
GNU Library General Public License for more details. |
13 |
|
|
14 |
You should have received a copy of the GNU Library General Public License |
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 |
along with GNU Mailutils; if not, write to the Free Software |
16 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
17 |
|
|
18 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
41 |
#include <mailutils/mutil.h> |
#include <mailutils/mutil.h> |
42 |
#include <mailutils/registrar.h> |
#include <mailutils/registrar.h> |
43 |
#include <mailutils/stream.h> |
#include <mailutils/stream.h> |
44 |
|
#include <mailutils/nls.h> |
45 |
|
|
46 |
void mutil_register_all_mbox_formats (void); |
void mutil_register_all_mbox_formats (void); |
47 |
|
|
48 |
const char *argp_program_version = "sieve (" PACKAGE_STRING ")"; |
const char *argp_program_version = "sieve (" PACKAGE_STRING ")"; |
49 |
|
|
50 |
static char doc[] = |
static char doc[] = |
51 |
"GNU sieve -- a mail filtering tool\n" |
N_("GNU sieve -- a mail filtering tool\n" |
52 |
"\v" |
"\v" |
53 |
"Debug flags:\n" |
"Debug flags:\n" |
54 |
" g - main parser traces\n" |
" g - main parser traces\n" |
55 |
" T - mailutil traces (MU_DEBUG_TRACE)\n" |
" T - mailutil traces (MU_DEBUG_TRACE)\n" |
56 |
" P - network protocols (MU_DEBUG_PROT)\n" |
" P - network protocols (MU_DEBUG_PROT)\n" |
57 |
" t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n" |
" t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n" |
58 |
" i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n"; |
" i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n"); |
59 |
|
|
60 |
#define D_DEFAULT "TPt" |
#define D_DEFAULT "TPt" |
61 |
|
|
62 |
static struct argp_option options[] = |
static struct argp_option options[] = |
63 |
{ |
{ |
64 |
{"no-actions", 'n', 0, 0, |
{"no-actions", 'n', 0, 0, |
65 |
"No actions executed, just print what would be done", 0}, |
N_("No actions executed, just print what would be done"), 0}, |
66 |
|
|
67 |
{"keep-going", 'k', 0, 0, |
{"keep-going", 'k', 0, 0, |
68 |
"Keep on going if execution fails on a message", 0}, |
N_("Keep on going if execution fails on a message"), 0}, |
69 |
|
|
70 |
{"compile-only", 'c', 0, 0, |
{"compile-only", 'c', 0, 0, |
71 |
"Compile script and exit", 0}, |
N_("Compile script and exit"), 0}, |
72 |
|
|
73 |
{"dump", 'D', 0, 0, |
{"dump", 'D', 0, 0, |
74 |
"Compile script, dump disassembled sieve code to terminal and exit", 0 }, |
N_("Compile script, dump disassembled sieve code to terminal and exit"), 0 }, |
75 |
|
|
76 |
{"mbox-url", 'f', "MBOX", 0, |
{"mbox-url", 'f', "MBOX", 0, |
77 |
"Mailbox to sieve (defaults to user's mail spool)", 0}, |
N_("Mailbox to sieve (defaults to user's mail spool)"), 0}, |
78 |
|
|
79 |
{"ticket", 't', "TICKET", 0, |
{"ticket", 't', "TICKET", 0, |
80 |
"Ticket file for mailbox authentication", 0}, |
N_("Ticket file for mailbox authentication"), 0}, |
81 |
|
|
82 |
{"debug", 'd', "FLAGS", OPTION_ARG_OPTIONAL, |
{"debug", 'd', "FLAGS", OPTION_ARG_OPTIONAL, |
83 |
"Debug flags (defaults to \"" D_DEFAULT "\")", 0}, |
N_("Debug flags (defaults to \"" D_DEFAULT "\")"), 0}, |
84 |
|
|
85 |
{"verbose", 'v', NULL, 0, |
{"verbose", 'v', NULL, 0, |
86 |
"Log all actions", 0}, |
N_("Log all actions"), 0}, |
87 |
|
|
88 |
{"email", 'e', "ADDRESS", 0, |
{"email", 'e', "ADDRESS", 0, |
89 |
"Override user email address", 0}, |
N_("Override user email address"), 0}, |
90 |
|
|
91 |
{0} |
{0} |
92 |
}; |
}; |
121 |
case 'e': |
case 'e': |
122 |
rc = mu_set_user_email (arg); |
rc = mu_set_user_email (arg); |
123 |
if (rc) |
if (rc) |
124 |
argp_error (state, "invalid email: %s", mu_errstring (rc)); |
argp_error (state, _("invalid email: %s"), mu_errstring (rc)); |
125 |
break; |
break; |
126 |
|
|
127 |
case 'n': |
case 'n': |
142 |
|
|
143 |
case 'f': |
case 'f': |
144 |
if (opts->mbox) |
if (opts->mbox) |
145 |
argp_error (state, "only one MBOX can be specified"); |
argp_error (state, _("only one MBOX can be specified")); |
146 |
opts->mbox = strdup (arg); |
opts->mbox = strdup (arg); |
147 |
break; |
break; |
148 |
|
|
179 |
break; |
break; |
180 |
|
|
181 |
default: |
default: |
182 |
argp_error (state, "%c is not a valid debug flag", *arg); |
argp_error (state, _("%c is not a valid debug flag"), *arg); |
183 |
break; |
break; |
184 |
} |
} |
185 |
} |
} |
191 |
|
|
192 |
case ARGP_KEY_ARG: |
case ARGP_KEY_ARG: |
193 |
if (opts->script) |
if (opts->script) |
194 |
argp_error (state, "only one SCRIPT can be specified"); |
argp_error (state, _("only one SCRIPT can be specified")); |
195 |
opts->script = mu_tilde_expansion (arg, "/", NULL); |
opts->script = mu_tilde_expansion (arg, "/", NULL); |
196 |
break; |
break; |
197 |
|
|
198 |
case ARGP_KEY_NO_ARGS: |
case ARGP_KEY_NO_ARGS: |
199 |
argp_error (state, "SCRIPT must be specified"); |
argp_error (state, _("SCRIPT must be specified")); |
200 |
|
|
201 |
default: |
default: |
202 |
return ARGP_ERR_UNKNOWN; |
return ARGP_ERR_UNKNOWN; |
263 |
|
|
264 |
message_get_uid (msg, &uid); |
message_get_uid (msg, &uid); |
265 |
|
|
266 |
fprintf (stdout, "%s on msg uid %lu", action, (unsigned long) uid); |
fprintf (stdout, _("%s on msg uid %lu"), action, (unsigned long) uid); |
267 |
if (fmt && strlen (fmt)) |
if (fmt && strlen (fmt)) |
268 |
{ |
{ |
269 |
fprintf (stdout, ": "); |
fprintf (stdout, ": "); |
282 |
|
|
283 |
message_get_uid (msg, &uid); |
message_get_uid (msg, &uid); |
284 |
|
|
285 |
asprintf (&text, "%s on msg uid %d", action, uid); |
asprintf (&text, _("%s on msg uid %d"), action, uid); |
286 |
if (fmt && strlen (fmt)) |
if (fmt && strlen (fmt)) |
287 |
{ |
{ |
288 |
char *diag = NULL; |
char *diag = NULL; |
306 |
int rc; |
int rc; |
307 |
struct options opts = {0}; |
struct options opts = {0}; |
308 |
int (*debugfp) __P ((mu_debug_t, size_t level, const char *, va_list)); |
int (*debugfp) __P ((mu_debug_t, size_t level, const char *, va_list)); |
309 |
|
|
310 |
|
/* Native Language Support */ |
311 |
|
/* mu_init_nls (); */ |
312 |
|
|
313 |
sieve_argp_init (); |
sieve_argp_init (); |
314 |
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, |
315 |
0, &opts); |
0, &opts); |
323 |
rc = sieve_machine_init (&mach, NULL); |
rc = sieve_machine_init (&mach, NULL); |
324 |
if (rc) |
if (rc) |
325 |
{ |
{ |
326 |
mu_error ("can't initialize sieve machine: %s", mu_errstring (rc)); |
mu_error (_("can't initialize sieve machine: %s"), mu_errstring (rc)); |
327 |
return 1; |
return 1; |
328 |
} |
} |
329 |
|
|
361 |
{ |
{ |
362 |
if ((rc = wicket_create (&wicket, opts.tickets)) != 0) |
if ((rc = wicket_create (&wicket, opts.tickets)) != 0) |
363 |
{ |
{ |
364 |
mu_error ("wicket create <%s> failed: %s\n", |
mu_error (_("wicket create <%s> failed: %s\n"), |
365 |
opts.tickets, mu_errstring (rc)); |
opts.tickets, mu_errstring (rc)); |
366 |
goto cleanup; |
goto cleanup; |
367 |
} |
} |
368 |
if ((rc = wicket_get_ticket (wicket, &ticket, 0, 0)) != 0) |
if ((rc = wicket_get_ticket (wicket, &ticket, 0, 0)) != 0) |
369 |
{ |
{ |
370 |
mu_error ("ticket get failed: %s\n", mu_errstring (rc)); |
mu_error (_("ticket get failed: %s\n"), mu_errstring (rc)); |
371 |
goto cleanup; |
goto cleanup; |
372 |
} |
} |
373 |
sieve_set_ticket (mach, ticket); |
sieve_set_ticket (mach, ticket); |
378 |
{ |
{ |
379 |
if ((rc = mu_debug_create (&debug, mach))) |
if ((rc = mu_debug_create (&debug, mach))) |
380 |
{ |
{ |
381 |
mu_error ("mu_debug_create failed: %s\n", mu_errstring (rc)); |
mu_error (_("mu_debug_create failed: %s\n"), mu_errstring (rc)); |
382 |
goto cleanup; |
goto cleanup; |
383 |
} |
} |
384 |
if ((rc = mu_debug_set_level (debug, opts.debug_level))) |
if ((rc = mu_debug_set_level (debug, opts.debug_level))) |
385 |
{ |
{ |
386 |
mu_error ("mu_debug_set_level failed: %s\n", |
mu_error (_("mu_debug_set_level failed: %s\n"), |
387 |
mu_errstring (rc)); |
mu_errstring (rc)); |
388 |
goto cleanup; |
goto cleanup; |
389 |
} |
} |
390 |
if ((rc = mu_debug_set_print (debug, debugfp, mach))) |
if ((rc = mu_debug_set_print (debug, debugfp, mach))) |
391 |
{ |
{ |
392 |
mu_error ("mu_debug_set_print failed: %s\n", |
mu_error (_("mu_debug_set_print failed: %s\n"), |
393 |
mu_errstring (rc)); |
mu_errstring (rc)); |
394 |
goto cleanup; |
goto cleanup; |
395 |
} |
} |
400 |
/* Create, give a ticket to, and open the mailbox. */ |
/* Create, give a ticket to, and open the mailbox. */ |
401 |
if ((rc = mailbox_create_default (&mbox, opts.mbox)) != 0) |
if ((rc = mailbox_create_default (&mbox, opts.mbox)) != 0) |
402 |
{ |
{ |
403 |
mu_error ("mailbox create <%s> failed: %s\n", |
mu_error (_("mailbox create <%s> failed: %s\n"), |
404 |
opts.mbox ? opts.mbox : "default", mu_errstring (rc)); |
opts.mbox ? opts.mbox : _("default"), mu_errstring (rc)); |
405 |
goto cleanup; |
goto cleanup; |
406 |
} |
} |
407 |
|
|
408 |
if (debug && (rc = mailbox_set_debug (mbox, debug))) |
if (debug && (rc = mailbox_set_debug (mbox, debug))) |
409 |
{ |
{ |
410 |
mu_error ("mailbox_set_debug failed: %s\n", mu_errstring (rc)); |
mu_error (_("mailbox_set_debug failed: %s\n"), mu_errstring (rc)); |
411 |
goto cleanup; |
goto cleanup; |
412 |
} |
} |
413 |
|
|
418 |
|
|
419 |
if ((rc = mailbox_get_folder (mbox, &folder))) |
if ((rc = mailbox_get_folder (mbox, &folder))) |
420 |
{ |
{ |
421 |
mu_error ("mailbox_get_folder failed: %s", |
mu_error (_("mailbox_get_folder failed: %s"), |
422 |
mu_errstring (rc)); |
mu_errstring (rc)); |
423 |
goto cleanup; |
goto cleanup; |
424 |
} |
} |
425 |
|
|
426 |
if ((rc = folder_get_authority (folder, &auth))) |
if ((rc = folder_get_authority (folder, &auth))) |
427 |
{ |
{ |
428 |
mu_error ("folder_get_authority failed: %s", |
mu_error (_("folder_get_authority failed: %s"), |
429 |
mu_errstring (rc)); |
mu_errstring (rc)); |
430 |
goto cleanup; |
goto cleanup; |
431 |
} |
} |
433 |
/* Authentication-less folders don't have authorities. */ |
/* Authentication-less folders don't have authorities. */ |
434 |
if (auth && (rc = authority_set_ticket (auth, ticket))) |
if (auth && (rc = authority_set_ticket (auth, ticket))) |
435 |
{ |
{ |
436 |
mu_error ("authority_set_ticket failed: %s", |
mu_error (_("authority_set_ticket failed: %s"), |
437 |
mu_errstring (rc)); |
mu_errstring (rc)); |
438 |
goto cleanup; |
goto cleanup; |
439 |
} |
} |
447 |
|
|
448 |
if (rc != 0) |
if (rc != 0) |
449 |
{ |
{ |
450 |
mu_error ("open on %s failed: %s\n", |
mu_error (_("open on %s failed: %s\n"), |
451 |
opts.mbox ? opts.mbox : "default", mu_errstring (rc)); |
opts.mbox ? opts.mbox : _("default"), mu_errstring (rc)); |
452 |
goto cleanup; |
goto cleanup; |
453 |
} |
} |
454 |
|
|
465 |
any messages that were marked DELETED even if execution failed |
any messages that were marked DELETED even if execution failed |
466 |
on a later message. */ |
on a later message. */ |
467 |
if ((e = mailbox_expunge (mbox)) != 0) |
if ((e = mailbox_expunge (mbox)) != 0) |
468 |
mu_error ("expunge on %s failed: %s\n", |
mu_error (_("expunge on %s failed: %s\n"), |
469 |
opts.mbox ? opts.mbox : "default", mu_errstring (e)); |
opts.mbox ? opts.mbox : _("default"), mu_errstring (e)); |
470 |
|
|
471 |
if (e && !rc) |
if (e && !rc) |
472 |
rc = e; |
rc = e; |