diff --git a/TODO b/TODO index 19512eb6746d7d03989cb4bdfb9f5d458e6b6817..b5fab8e7283b8a1f2525315c12723b2b427ac858 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,7 @@ Current activities: -- +* Build a sieve tool to filter an entire existing mailbox through a Sieve + script. Parallel plugin-based efforts: @@ -14,13 +15,6 @@ Parallel plugin-based efforts: Next (mostly in order of descending priority/precedence): * Implement index extension -* Build a sieve tool to filter an entire existing mailbox through a Sieve - script. - > Needs to have single mail transaction for each destination folder for - all moved messages. Otherwise, partial failure cannot be prevented. - - Implement ability to group Sieve execution results of all processed messages - into one big `Sieve transaction' object, which (among other things) keeps - track of opened mailboxes and transactions. Is probably also more efficient. * Update include extension to latest draft (v10 currently): - Implement :optional tag. - Implement required ManageSieve behavior diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am index 3868734b7f840dd121fffcc22ceeeb9738f3529a..1e4091c66d7e4143508b489c16885ae5d05c58fa 100644 --- a/doc/man/Makefile.am +++ b/doc/man/Makefile.am @@ -1,10 +1,5 @@ pkgsysconfdir = $(sysconfdir)/dovecot rundir = ${prefix}/var/run/dovecot -unfinished = sieve-filter.1 - -if BUILD_UNFINISHED -unfinished_mans = $(unfinished) -endif dist_man1_MANS = \ sieved.1 @@ -13,7 +8,7 @@ nodist_man1_MANS = \ sievec.1 \ sieve-dump.1 \ sieve-test.1 \ - $(unfinished_mans) + sieve-filter.1 nodist_man7_MANS = \ pigeonhole.7 @@ -27,8 +22,8 @@ EXTRA_DIST = \ sieve-test.1.in \ sieve-filter.1.in \ pigeonhole.7.in \ - sed.sh \ - $(man_includefiles) + sed.sh \ + $(man_includefiles) CLEANFILES = $(nodist_man1_MANS) $(nodist_man7_MANS) diff --git a/doc/man/sieve-filter.1.in b/doc/man/sieve-filter.1.in index 0418c9adf6813f6708b57d25762fd9e850b0dbd4..bb3421ee967272382b35b71050d2e382b6ccb708 100644 --- a/doc/man/sieve-filter.1.in +++ b/doc/man/sieve-filter.1.in @@ -4,17 +4,17 @@ sieve\-filter \- Pigeonhole\(aqs Sieve mailbox filter tool .PP -\fBWARNING: \fRThis tool is not finished and should \fB*NOT*\fR be used, unless -you feel like testing newly developed features! The behavior described in this -manual page represents the design and not necessarily what the tool currently -implements. +\fBWARNING: \fRThis tool is still experimental. Read this manual carefully, and +backup any important mail before using this tool. Also note that some of the +features documented here are not actually implemented yet; this is clearly +indicated where applicable. .\"------------------------------------------------------------------------ .SH SYNOPSIS .B sieve\-filter .RI [ options ] .I script\-file .I source\-mailbox -.RI [ source\-action ] +.RI [ discard\-action ] .SH DESCRIPTION .PP The \fBsieve\-filter\fP command is part of the Pigeonhole Project @@ -25,29 +25,37 @@ The Sieve language was originally meant for filtering messages upon delivery. However, there are occasions when it is desirable to filter messages that are already stored in a mailbox, for instance when a bug in a Sieve script caused many messages to be delivered incorrectly. Using the sieve\-filter tool it is -possible to apply a Sieve script on all messages in a particular mailbox, making -it possible to delete messages, to store them in a different mailbox and to -change the assigned IMAP flags and keywords. Attempts to send messages to the -outside world are ignored by default for obvious reasons, but, using the proper -command line options, it is possible to capture outgoing mail as well. +possible to apply a Sieve script on all messages in a particular +\fIsource\-mailbox\fP, making it possible to delete messages, to store them in a +different mailbox and to change the assigned IMAP flags and keywords. Attempts +to send messages to the outside world are ignored by default for obvious +reasons, but, using the proper command line options, it is possible to capture +and handle outgoing mail as well. .PP If no options are specified, the sieve\-filter command runs in a simulation mode in which it only prints what would be performed, without actually doing anything. Use the \fB\-e\fP option to activate true script execution. Also, the -source mailbox is opened read\-only by default, so that the source mailbox -remains unchanged. Use the \fB\-W\fP option to allow changes in the source mailbox. -And even with the \fB\-W\fP option enabled, messages in the source mailbox are -only potentially modified and not (re)moved, unless a \fIsource\-action\fP -argument other than \fBkeep\fP is specified. +\fIsource\-mailbox\fP is opened read\-only by default, meaning that it normally +always remains unchanged. Use the \fB\-W\fP option to allow changes in the +\fIsource\-mailbox\fP. +.PP +Even with the \fB\-W\fP option enabled, messages in the \fIsource\-mailbox\fP +are only potentially modified or moved to a different folder. Messages are never +lost unless a \fIdiscard\-action\fP argument other than \fBkeep\fP (the default) +is specified. If the Sieve filter decides to store the message in the +\fIsource\-mailbox\fP, where it obviously already exists, it is never duplicated +there. However, in that case, the IMAP flags of the original message can be +modified by the Sieve interpreter, provided that \fB\-W\fP is specified. + .SS CAUTION Although this is a very useful tool, it can also be very destructive when used improperly. A small bug in your Sieve script in combination with the wrong command line options could cause it to discard the wrong e\-mails. And, even if -the source mailbox is opened in read\-only mode to prevent such mishaps, it can -still litter other mailboxes with spurious copies of your e\-mails if your Sieve -script decides to do so. Therefore, users are advised to read this manual -carefully and to use the simulation mode first to check what the script will do. -And, of course: +the \fIsource\-mailbox\fP is opened in read\-only mode to prevent such mishaps, +it can still litter other mailboxes with spurious copies of your e\-mails if +your Sieve script decides to do so. Therefore, users are advised to read this +manual carefully and to use the simulation mode first to check what the script +will do. And, of course: .PP \fBMAKING A BACKUP IS IMPERATIVE FOR ANY IMPORTANT MAIL!\fP @@ -72,32 +80,24 @@ Enable Sieve debugging. Turns on execution mode. By default, the sieve\-filter command runs in simulation mode in which it changes nothing, meaning that no mailbox is altered in any way and no actions are performed. It only prints what would be done. -Using this option the sieve\-filter command becomes active and performs the +Using this option, the sieve\-filter command becomes active and performs the requested actions. .TP .BI \-m\ default\-mailbox -The mailbox where the (implicit) \fBkeep\fP Sieve action stores messages. This is -equal to the source mailbox by default. -.TP -.B \-M -Enable move mode. This will cause all messages that were succesfully stored -somewhere else to be expunged from the source mailbox, regardless of what the -\fIsource\-action\fP is (refer to Arguments section below). However, if the -Sieve filter decides to keep the message in the source mailbox, it is left -there and not affected by this option. -.IP -Note that some Sieve actions, such as \fBredirect\fP, don't store the message -anywhere and are thus \- with respect to the fate of the message in the source -mailbox \- treated as if a \fBdiscard\fP action were executed. +The mailbox where the (implicit) \fBkeep\fP Sieve action stores messages. This +is equal to the \fIsource\-mailbox\fP by default. Specifying a different folder +will have the effect of moving (or copying if \fB\-W\fP is omitted) all kept +messages to the indicated folder, instead of just leaving them in the +\fIsource\-mailbox\fP. .TP -.BI \-q\ output\-mailbox\ \fR[not\ implemented\ yet]\fP +.BI \-q\ output\-mailbox\ \fB[not\ implemented\ yet]\fP Store outgoing e\-mail into the indicated \fIoutput\-mailbox\fP. By default, the sieve\-filter command ignores Sieve actions such as redirect, reject, vacation and notify, but using this option outgoing messages can be appended to the indicated mailbox. This option has no effect in simulation mode. Flags of redirected messages are not preserved. .TP -.BI \-Q\ mail\-command\ \fR[not\ implemented\ yet]\fP +.BI \-Q\ mail\-command\ \fB[not\ implemented\ yet]\fP Send outgoing e\-mail (e.g. as produced by redirect, reject and vacation) through the specified program. By default, the sieve\-filter command ignores Sieve actions such as redirect, reject, vacation and notify, but using this @@ -105,7 +105,7 @@ option outgoing messages can be fed to the \fBstdin\fP of an external shell command. This option has no effect in simulation mode. Unless you really know what you are doing, \fBDO NOT USE THIS TO FEED MAIL TO SENDMAIL!\fP. .TP -.BI \-s\ script\-file\ \fR[not\ implemented\ yet]\fP +.BI \-s\ script\-file\ \fB[not\ implemented\ yet]\fP Specify additional scripts to be executed before the main script. Multiple \fB\-s\fP arguments are allowed and the specified scripts are executed sequentially in the order specified at the command @@ -114,9 +114,13 @@ line. .BI \-u\ user Run the Sieve script for the given \fIuser\fP. .TP +.B \-v\ +Produce verbose output during filtering. +.TP .B \-W -Enables write access to the source mailbox. This allows deleting the messages -from the source mailbox and changing the assigned IMAP flags and keywords. +Enables write access to the \fIsource\-mailbox\fP. This allows (re)moving the +messages from the \fIsource\-mailbox\fP and changing the assigned IMAP flags and +keywords. .TP .BI \-x\ extensions Set the available extensions. The parameter is a space\-separated list of the @@ -136,7 +140,7 @@ except for the enotify extension. .SH ARGUMENTS .TP .I script\-file -Specifies the script to (compile and) execute. +Specifies the Sieve script to (compile and) execute. Note that this tool looks for a pre\-compiled binary file with a \fI.svbin\fP extension and with basename and path identical to the specified script. Use the @@ -144,44 +148,40 @@ extension and with basename and path identical to the specified script. Use the into a new binary. .TP .I source\-mailbox -The name of the source mailbox. +The name of the source mailbox containing the messages that the Sieve filter +will act upon. This mailbox is not modified unless the \fB\-W\fP option is +specified. .TP -.I source\-action -Specifies what is done with messages in the source mailbox once processed by the -Sieve script. The \fIsource\-action\fP parameter accepts one of the following values: +.I discard\-action +Specifies what is done with messages in the \fIsource\-mailbox\fP that where not +kept or otherwise stored by the Sieve script; i.e. those messages that would +normally be discarded if the Sieve script were executed at delivery. +The \fIdiscard\-action\fP parameter accepts one of the following values: .RS 7 .TP .BR keep\ (default) -Keep processed messages in source mailbox. When the filter decides to store the message -in the source mailbox, it is never duplicated there. However, in that case, the -IMAP flags of the original message can be modified by the Sieve interpreter. +Keep discarded messages in source mailbox. .TP .BI move\ mailbox -Move processed messages to the indicated \fImailbox\fP. This is for instance useful -to move messages to a Trash mailbox. +Move discarded messages to the indicated \fImailbox\fP. This is for instance +useful to move messages to a Trash mailbox. .TP .B delete -Flag processed messages as \\DELETED. +Flag discarded messages as \\DELETED. .TP .B expunge -Expunge processed messages, meaning that these are removed irreversibly when the +Expunge discarded messages, meaning that these are removed irreversibly when the tool finishes filtering. .RE .IP -The \fBsource\-action\fP is normally applied to all messages in the source mailbox, -but there are a few exceptions: -.RS 7 -.IP \(bu -When the \fB\-W\fP option is not specified, the source mailbox is immutable and -the specified \fIsource\-action\fP has no effect. -.IP \(bu -When the \fB\-M\fR option (move mode) is active, all messages that were -successfully moved to another mailbox are expunged irrespective of the specified -\fIsource\-action\fP. -.IP \(bu -If the filter decides to keep the message in the source mailbox, it is left there -and not affected by the \fIsource\-action\fP. -.RE +When the \fB\-W\fP option is not specified, the \fIsource\-mailbox\fP is +immutable and the specified \fIdiscard\-action\fP has no effect. This means that +messages are at most \fIcopied\fP to a new location. In contrast, when the +\fB\-W\fP is specified, messages that are successfully stored somewhere else by +the Sieve script are \fBalways\fP expunged from the \fIsource\-mailbox\fP, with +the effect that these are thus \fImoved\fP to the new location. This happens +irrespective of the specified \fIdiscard\-action\fP. Remember: only discarded +messages are affected by the specified \fIdiscard\-action\fP. .\"------------------------------------------------------------------------ diff --git a/src/sieve-tools/Makefile.am b/src/sieve-tools/Makefile.am index bcb754c009fc7682ffff5d7a22912a789f5fdeab..33b1bad26a2790622c6f6442cad72144527cbc48 100644 --- a/src/sieve-tools/Makefile.am +++ b/src/sieve-tools/Makefile.am @@ -1,8 +1,4 @@ -bin_PROGRAMS = sievec sieve-dump sieve-test - -if BUILD_UNFINISHED -bin_PROGRAMS += sieve-filter -endif +bin_PROGRAMS = sievec sieve-dump sieve-test sieve-filter AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib-sieve \ diff --git a/src/sieve-tools/sieve-filter.c b/src/sieve-tools/sieve-filter.c index fbe8180e489eb21d8384883c70dee3eb889d06f9..2face61671222cc56581fdf8ed8cb7b19fc6ac27 100644 --- a/src/sieve-tools/sieve-filter.c +++ b/src/sieve-tools/sieve-filter.c @@ -36,20 +36,20 @@ static void print_help(void) printf( "Usage: sieve-filter [-c <config-file>] [-C] [-D] [-e] [-m <default-mailbox>]\n" " [-P <plugin>] [-q <output-mailbox>] [-Q <mail-command>]\n" -" [-s <script-file>] [-u <user>] [-W] [-x <extensions>]\n" -" <script-file> <source-mailbox> <source-action>\n" +" [-s <script-file>] [-u <user>] [-v] [-W] [-x <extensions>]\n" +" <script-file> <source-mailbox> [<discard-action>]\n" ); } -enum sieve_filter_source_action { - SIEVE_FILTER_SACT_KEEP, /* Always keep messages in source folder */ - SIEVE_FILTER_SACT_MOVE, /* Move discarded messages to Trash folder */ - SIEVE_FILTER_SACT_DELETE, /* Flag discarded messages as \DELETED */ - SIEVE_FILTER_SACT_EXPUNGE /* Expunge discarded messages */ +enum sieve_filter_discard_action { + SIEVE_FILTER_DACT_KEEP, /* Keep discarded messages in source folder */ + SIEVE_FILTER_DACT_MOVE, /* Move discarded messages to Trash folder */ + SIEVE_FILTER_DACT_DELETE, /* Flag discarded messages as \DELETED */ + SIEVE_FILTER_DACT_EXPUNGE /* Expunge discarded messages */ }; struct sieve_filter_data { - enum sieve_filter_source_action source_action; + enum sieve_filter_discard_action discard_action; struct mailbox *move_mailbox; struct sieve_script_env *senv; @@ -58,7 +58,6 @@ struct sieve_filter_data { unsigned int execute:1; unsigned int source_write:1; - unsigned int move_mode:1; }; struct sieve_filter_context { @@ -77,10 +76,11 @@ static int filter_message struct sieve_exec_status estatus; struct sieve_binary *sbin; struct sieve_message_data msgdata; - const char *recipient, *sender; + const char *recipient = NULL, *sender = NULL; bool execute = sfctx->data->execute; bool source_write = sfctx->data->source_write; - bool move_mode = sfctx->data->move_mode; + const char *subject, *date; + uoff_t size = 0; int ret; sieve_tool_get_envelope_data(mail, &recipient, &sender); @@ -97,14 +97,41 @@ static int filter_message msgdata.final_envelope_to = recipient; msgdata.auth_user = senv->username; (void)mail_get_first_header(mail, "Message-ID", &msgdata.id); + + if ( mail_get_virtual_size(mail, &size) < 0 ) { + if ( mail->expunged ) + return 1; + + sieve_error(ehandler, NULL, "failed to obtain message size; " + "skipping this message (id=%s)", + ( msgdata.id == NULL ? "none" : msgdata.id )); + return 0; + } + + if ( mail_get_first_header(mail, "date", &date) <= 0 ) + date = ""; + if ( mail_get_first_header(mail, "subject", &subject) <= 0 ) + subject = ""; /* Single script */ sbin = sfctx->data->main_sbin; /* Execute script */ if ( execute ) { + sieve_info(ehandler, NULL, + "filtering: [%s; %"PRIuUOFF_T" bytes] `%s'", date, size, + str_sanitize(subject, 40)); + ret = sieve_execute(sbin, &msgdata, senv, ehandler, NULL); } else { + (void)o_stream_send_str(sfctx->teststream, + t_strdup_printf(">> Filtering message:\n\n" + " ID: %s\n" + " Date: %s\n" + " Size: %"PRIuUOFF_T" bytes\n" + " Subject: %s\n", ( msgdata.id == NULL ? "none" : msgdata.id ), + date, size, str_sanitize(subject, 40))); + ret = sieve_test (sbin, &msgdata, senv, ehandler, sfctx->teststream, NULL); } @@ -112,16 +139,17 @@ static int filter_message /* Handle message in source folder */ if ( ret > 0 ) { struct mailbox *move_box = sfctx->data->move_mailbox; - enum sieve_filter_source_action source_action = - sfctx->data->source_action; + enum sieve_filter_discard_action discard_action = + sfctx->data->discard_action; if ( !source_write ) { - /* Do nothing */ + /* READ-ONLY; Do nothing */ } else if ( estatus.keep_original ) { + /* Explicitly `stored' in source box; just keep it there */ sieve_info(ehandler, NULL, "message kept in source mailbox"); - } else if ( move_mode && estatus.message_saved ) { + } else if ( estatus.message_saved ) { sieve_info(ehandler, NULL, "message expunged from source mailbox upon successful move"); @@ -129,13 +157,14 @@ static int filter_message mail_expunge(mail); } else { - switch ( source_action ) { + + switch ( discard_action ) { /* Leave it there */ - case SIEVE_FILTER_SACT_KEEP: + case SIEVE_FILTER_DACT_KEEP: sieve_info(ehandler, NULL, "message left in source mailbox"); break; /* Move message to indicated folder */ - case SIEVE_FILTER_SACT_MOVE: + case SIEVE_FILTER_DACT_MOVE: sieve_info(ehandler, NULL, "message in source mailbox moved to mailbox '%s'", mailbox_get_name(move_box)); @@ -144,7 +173,7 @@ static int filter_message struct mailbox_transaction_context *t = sfctx->move_trans; struct mail_save_context *save_ctx; - save_ctx = mailbox_save_alloc(t); + save_ctx = mailbox_save_alloc(t); if ( mailbox_copy(&save_ctx, mail) < 0 ) { enum mail_error error; @@ -163,13 +192,13 @@ static int filter_message } break; /* Flag message as \DELETED */ - case SIEVE_FILTER_SACT_DELETE: + case SIEVE_FILTER_DACT_DELETE: sieve_info(ehandler, NULL, "message flagged as deleted in source mailbox"); if ( execute ) mail_update_flags(mail, MODIFY_ADD, MAIL_DELETED); break; /* Expunge the message immediately */ - case SIEVE_FILTER_SACT_EXPUNGE: + case SIEVE_FILTER_DACT_EXPUNGE: sieve_info(ehandler, NULL, "message expunged from source mailbox"); if ( execute ) mail_expunge(mail); @@ -182,7 +211,25 @@ static int filter_message } } - return ret; + switch ( ret ) { + case SIEVE_EXEC_OK: + break; + case SIEVE_EXEC_BIN_CORRUPT: + sieve_error(ehandler, NULL, "sieve script binary is corrupt"); + return -1; + case SIEVE_EXEC_FAILURE: + case SIEVE_EXEC_KEEP_FAILED: + sieve_error(ehandler, NULL, + "sieve script execution failed for this message; " + "message left in source mailbox"); + return 0; + default: + sieve_error(ehandler, NULL, + "sieve execution result: unrecognized return value?!"); + return -1; + } + + return 1; } /* FIXME: introduce this into Dovecot */ @@ -194,7 +241,7 @@ static void mail_search_build_add_flags arg = p_new(args->pool, struct mail_search_arg, 1); arg->type = SEARCH_FLAGS; arg->value.flags = flags; - arg->not = not; + arg->match_not = not; arg->next = args->args; args->args = arg; @@ -241,38 +288,14 @@ static int filter_mailbox mail_search_build_add_flags(search_args, MAIL_DELETED, TRUE); t = mailbox_transaction_begin(src_box, 0); - search_ctx = mailbox_search_init(t, search_args, NULL); + search_ctx = mailbox_search_init(t, search_args, NULL, 0, NULL); mail_search_args_unref(&search_args); /* Iterate through all requested messages */ - mail = mail_alloc(t, 0, NULL); - while ( ret > 0 && mailbox_search_next(search_ctx, mail) > 0 ) { - const char *subject, *date; - uoff_t size = 0; - - /* Request message size */ - - if ( mail_get_virtual_size(mail, &size) < 0 ) { - if ( mail->expunged ) - continue; - - sieve_error(ehandler, NULL, "failed to obtain message size"); - continue; - } - - if ( mail_get_first_header(mail, "date", &date) <= 0 ) - date = ""; - if ( mail_get_first_header(mail, "subject", &subject) <= 0 ) - subject = ""; - - sieve_info(ehandler, NULL, - "filtering: [%s; %"PRIuUOFF_T" bytes] %s", date, size, - str_sanitize(subject, 40)); - + while ( ret >= 0 && mailbox_search_next(search_ctx, &mail) > 0 ) { ret = filter_message(&sfctx, mail); } - mail_free(&mail); /* Cleanup */ @@ -281,21 +304,13 @@ static int filter_mailbox } if ( sfctx.move_trans != NULL ) { - if ( ret < 0 ) { - mailbox_transaction_rollback(&sfctx.move_trans); - } else { - if ( mailbox_transaction_commit(&sfctx.move_trans) < 0 ) { - ret = -1; - } + if ( mailbox_transaction_commit(&sfctx.move_trans) < 0 ) { + ret = -1; } } - if ( ret < 0 ) { - mailbox_transaction_rollback(&t); - } else { - if ( mailbox_transaction_commit(&t) < 0 ) { - ret = -1; - } + if ( mailbox_transaction_commit(&t) < 0 ) { + ret = -1; } if ( sfctx.teststream != NULL ) @@ -335,28 +350,27 @@ int main(int argc, char **argv) ARRAY_TYPE (const_string) scriptfiles; const char *scriptfile, *src_mailbox, *dst_mailbox, *move_mailbox; struct sieve_filter_data sfdata; - enum sieve_filter_source_action source_action = SIEVE_FILTER_SACT_KEEP; + enum sieve_filter_discard_action discard_action = SIEVE_FILTER_DACT_KEEP; struct mail_user *mail_user; struct sieve_binary *main_sbin; struct sieve_script_env scriptenv; struct sieve_error_handler *ehandler; - bool force_compile, execute, source_write, move_mode; + bool force_compile, execute, source_write, verbose; struct mail_namespace *ns; struct mailbox *src_box = NULL, *move_box = NULL; - enum mailbox_flags open_flags = - MAILBOX_FLAG_KEEP_RECENT | MAILBOX_FLAG_IGNORE_ACLS; + enum mailbox_flags open_flags = MAILBOX_FLAG_IGNORE_ACLS; enum mail_error error; int c; sieve_tool = sieve_tool_init("sieve-filter", &argc, &argv, - "m:s:x:P:u:q:Q:DCeWM", FALSE); + "m:s:x:P:u:q:Q:DCevW", FALSE); t_array_init(&scriptfiles, 16); /* Parse arguments */ scriptfile = NULL; src_mailbox = dst_mailbox = move_mailbox = NULL; - force_compile = execute = source_write = move_mode = FALSE; + force_compile = execute = source_write = verbose = FALSE; while ((c = sieve_tool_getopt(sieve_tool)) > 0) { switch (c) { case 'm': @@ -392,14 +406,14 @@ int main(int argc, char **argv) /* force script compile */ force_compile = TRUE; break; - case 'M': - /* move mode */ - move_mode = TRUE; - break; case 'W': /* enable source mailbox write */ source_write = TRUE; break; + case 'v': + /* enable verbose output */ + verbose = TRUE; + break; default: /* unrecognized option */ print_help(); @@ -429,24 +443,24 @@ int main(int argc, char **argv) const char *srcact = argv[optind++]; if ( strcmp(srcact, "keep") == 0 ) { - source_action = SIEVE_FILTER_SACT_KEEP; + discard_action = SIEVE_FILTER_DACT_KEEP; } else if ( strcmp(srcact, "move") == 0 ) { - source_action = SIEVE_FILTER_SACT_MOVE; + discard_action = SIEVE_FILTER_DACT_MOVE; if ( optind < argc ) { move_mailbox = t_strdup(argv[optind++]); } else { print_help(); i_fatal_status(EX_USAGE, - "Invalid <source-action> argument: " + "Invalid <discard-action> argument: " "the `move' action requires mailbox argument"); } - } else if ( strcmp(srcact, "flag") == 0 ) { - source_action = SIEVE_FILTER_SACT_DELETE; + } else if ( strcmp(srcact, "delete") == 0 ) { + discard_action = SIEVE_FILTER_DACT_DELETE; } else if ( strcmp(srcact, "expunge") == 0 ) { - source_action = SIEVE_FILTER_SACT_EXPUNGE; + discard_action = SIEVE_FILTER_DACT_EXPUNGE; } else { print_help(); - i_fatal_status(EX_USAGE, "Invalid <source-action> argument"); + i_fatal_status(EX_USAGE, "Invalid <discard-action> argument"); } } @@ -462,13 +476,13 @@ int main(int argc, char **argv) /* Finish tool initialization */ svinst = sieve_tool_init_finish(sieve_tool, TRUE); - /* Enable debug extension */ - sieve_enable_debug_extension(svinst); + /* Enable debug extension */ + sieve_enable_debug_extension(svinst); /* Create error handler */ ehandler = sieve_stderr_ehandler_create(svinst, 0); sieve_system_ehandler_set(ehandler); - sieve_error_handler_accept_infolog(ehandler, TRUE); + sieve_error_handler_accept_infolog(ehandler, verbose); /* Compile main sieve script */ if ( force_compile ) { @@ -485,7 +499,7 @@ int main(int argc, char **argv) /* Open the source mailbox */ src_mailbox = mailbox_name_to_mutf7(src_mailbox); - ns = mail_namespace_find(mail_user->namespaces, &src_mailbox); + ns = mail_namespace_find(mail_user->namespaces, src_mailbox); if ( ns == NULL ) i_fatal("Unknown namespace for source mailbox '%s'", src_mailbox); @@ -500,10 +514,10 @@ int main(int argc, char **argv) /* Open move box if necessary */ - if ( execute && source_action == SIEVE_FILTER_SACT_MOVE && + if ( execute && discard_action == SIEVE_FILTER_DACT_MOVE && move_mailbox != NULL ) { move_mailbox = mailbox_name_to_mutf7(move_mailbox); - ns = mail_namespace_find(mail_user->namespaces, &move_mailbox); + ns = mail_namespace_find(mail_user->namespaces, move_mailbox); if ( ns == NULL ) i_fatal("Unknown namespace for mailbox '%s'", move_mailbox); @@ -532,13 +546,12 @@ int main(int argc, char **argv) /* Compose filter context */ memset(&sfdata, 0, sizeof(sfdata)); sfdata.senv = &scriptenv; - sfdata.source_action = source_action; + sfdata.discard_action = discard_action; sfdata.move_mailbox = move_box; sfdata.main_sbin = main_sbin; sfdata.ehandler = ehandler; sfdata.execute = execute; sfdata.source_write = source_write; - sfdata.move_mode = move_mode; /* Apply Sieve filter to all messages found */ (void) filter_mailbox(&sfdata, src_box);