dovecot-2.0-pigeonhole: Sieve-filter: fixed tool compilation and...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Fri Oct 1 20:05:02 EEST 2010
details: http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/a50464354f5a
changeset: 1440:a50464354f5a
user: Stephan Bosch <stephan at rename-it.nl>
date: Fri Oct 01 19:04:32 2010 +0200
description:
Sieve-filter: fixed tool compilation and further developed tool design.
diffstat:
TODO | 9 +-
doc/man/sieve-filter.1.in | 116 ++++++++++++++++-------------
src/sieve-tools/sieve-filter.c | 145 +++++++++++++++++++++---------------
3 files changed, 154 insertions(+), 116 deletions(-)
diffs (truncated from 488 to 300 lines):
diff -r e0c8354f8b21 -r a50464354f5a TODO
--- a/TODO Fri Oct 01 19:03:08 2010 +0200
+++ b/TODO Fri Oct 01 19:04:32 2010 +0200
@@ -1,3 +1,8 @@
+Current activities:
+
+* Build a sieve tool to filter an entire existing mailbox through a Sieve
+ script.
+
Next (in order of descending priority/precedence):
* Finish the ereject extension
@@ -16,10 +21,6 @@
* Cleanup the test suite
- Restructure test scripts
- Add more comment on purpose of tests
-* Build a sieve tool to filter an entire existing mailbox through a Sieve
- script:
- - Add commandline options to fully customize execution
- - Write manual page
* Implement index extension
* Update include extension to latest draft (v05 currently):
- Implement required ManageSieve behavior (pending IETF discussion)
diff -r e0c8354f8b21 -r a50464354f5a doc/man/sieve-filter.1.in
--- a/doc/man/sieve-filter.1.in Fri Oct 01 19:03:08 2010 +0200
+++ b/doc/man/sieve-filter.1.in Fri Oct 01 19:04:32 2010 +0200
@@ -38,47 +38,31 @@
.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. Therefore,
-users are advised to read this manual carefully and to use the simulation mode
-first to check what the script will do.
+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:
.PP
\fBMAKING A BACKUP IS IMPERATIVE FOR ANY IMPORTANT MAIL!\fP
-.PP
-By default, it will open the source mailbox in a read\-only mode, such that it
-will not delete any of your e\-mails. However, it can still litter other
-mailboxes with spurious copies of your e\-mails if your Sieve script decides to
-do so.
+
.\"------------------------------------------------------------------------
.SH OPTIONS
.TP
.BI \-c\ config\-file
Alternative Dovecot configuration file path.
-.TP
-.BI \-D\ source\-action
-By default, the sieve\-filter command does not delete the messages from the
-source mailbox. This means that a copy operation is executed by default and the
-source mailbox is not altered. The \fIsource\-action\fP parameter of the
-\fB\-D\fP option can take four different values:
-.RS 7
-.TP
-\fBkeep\fP (default)
-Keep messages in source folder. If \fB\-W\fR is specified and the source mailbox
-is the destination of a keep or fileinto action, flags can be changed by the
-Sieve script. Messages are never duplicated in the source mailbox.
-.TP
-\fBflag\fP
-Flag messages as \\DELETED.
-.TP
-\fBmove\fP [\fIfolder\fP]
-Move messages to the indicated \fIfolder\fP.
-.TP
-\fBexpunge\fP
-Expunge messages, meaning that these are removed irreversibly when the tool
-finishes filtering.
-.PP
-Note that values other than `keep' have no effect, unless the \fB\-W\fP option
-is specified as well.
-.RE
+.TP
+.B \-C
+Force compilation. By default, the compiled binary is stored on disk. When this
+binary is found during the next execution of \fBsieve\-filter\fP and its
+modification time is more recent than the script file, it is used and the script
+is not compiled again. This option forces the script to be compiled, thus
+ignoring any present binary. Refer to \fBsievec\fP(1) for more information about
+Sieve compilation.
+.TP
+.B \-D
+Enable Sieve debugging.
.TP
.B \-e
Turns on execution mode. By default, the sieve\-filter command runs in
@@ -87,33 +71,61 @@
Using this option the sieve\-filter command becomes active and performs the
requested actions.
.TP
-.BI \-f\ envelope\-sender
-The envelope sender or return path. This is what Sieve\(aqs envelope test will
-compare to when the \(dqfrom\(dq envelope part is requested. Also, this is
-where response messages are sent to.
-.TP
.BI \-m\ default\-mailbox
-The mailbox where the keep action stores the message. This is \(dqINBOX\(dq
+The mailbox where the keep action stores messages. This is \(dqINBOX\(dq
by default.
.TP
+.BI \-q\ output\-mailbox
+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.
+.TP
.BI \-Q\ mail\-command
-Send outgoing e\-mail through the specified program. By default,
-the sieve\-filter command ignores Sieve actions such as redirect, reject,
-vacation and notify, but using this 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!\f.
-.TP
-.BI \-r\ recipient\-address
-The envelope recipient address. This is what Sieve\(aqs envelope test will
-compare to when the \(dqto\(dq envelope part is requested. Some tests and
-actions will also use this as the owner\(aqs e\-mail address.
+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
+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 \-R\ source\-action
+Specifies what needs to be done with messages in the source mailbox once
+processed by the Sieve script. By default, the sieve\-filter command does not
+remove the messages from the source mailbox. In particular this means that the
+keep and fileinto actions will cause the messages to be copied. To alter this
+behavior, the \fIsource\-action\fP parameter of the \fB\-R\fP option accepts
+one of the following values:
+.RS 7
+.TP
+\fBkeep\fP (default)
+Keep processed messages in source folder. If \fB\-W\fR is specified and the
+source mailbox is the destination of a keep or fileinto action, flags may be
+changed by the Sieve script, but messages are never duplicated there.
+.TP
+\fBflag\fP
+Flag processed messages as \\DELETED.
+.TP
+\fBmove\fP [\fIfolder\fP]
+Move processed messages to the indicated \fIfolder\fP.
+.TP
+\fBexpunge\fP
+Expunge processed messages, meaning that these are removed irreversibly when the
+tool finishes filtering.
+.PP
+Note that the chosen \fIsource\-action\fP only has an effect on the source
+mailbox when the \fB\-W\fP option is specified as well.
+.RE
.TP
.BI \-s\ script\-file
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
-line..TP
+line.
+.TP
+.BI \-u\ user
+Run the Sieve script for the given \fIuser\fP.
+.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.
diff -r e0c8354f8b21 -r a50464354f5a src/sieve-tools/sieve-filter.c
--- a/src/sieve-tools/sieve-filter.c Fri Oct 01 19:03:08 2010 +0200
+++ b/src/sieve-tools/sieve-filter.c Fri Oct 01 19:04:32 2010 +0200
@@ -11,6 +11,7 @@
#include "mail-namespace.h"
#include "mail-storage.h"
#include "mail-search-build.h"
+#include "imap-utf7.h"
#include "sieve.h"
#include "sieve-extensions.h"
@@ -36,25 +37,30 @@
printf(
"Usage: sieve-filter [-m <mailbox>] [-x <extensions>] [-s <script-file>] [-c]\n"
" <script-file> <src-mail-store> [<dest-mail-store>]\n"
+"Usage: sieve-filter [-c <config-file>] [-C] [-D] [-e]\n"
+" [-m <default-mailbox>] [-P <plugin>]\n"
+" [-r <recipient-address>] [-s <script-file>]\n"
+" [-t <trace-file>] [-T <trace-option>] [-x <extensions>]\n"
+" <script-file> <mail-file>\n"
);
}
-enum discard_action_type {
- DISCARD_ACTION_KEEP, /* Always keep messages in source folder */
- DISCARD_ACTION_DELETE, /* Flag discarded messages as \DELETED */
- DISCARD_ACTION_TRASH_FOLDER, /* Move discarded messages to Trash folder */
- DISCARD_ACTION_EXPUNGE /* Expunge discarded messages */
+enum source_action_type {
+ SOURCE_ACTION_KEEP, /* Always keep messages in source folder */
+ SOURCE_ACTION_DELETE, /* Flag discarded messages as \DELETED */
+ SOURCE_ACTION_TRASH_FOLDER, /* Move discarded messages to Trash folder */
+ SOURCE_ACTION_EXPUNGE /* Expunge discarded messages */
};
-struct discard_action {
- enum discard_action_type type;
+struct source_action {
+ enum source_action_type type;
const char *trash_folder;
};
static int filter_message
(struct mail *mail, struct sieve_binary *main_sbin,
struct sieve_script_env *senv, struct sieve_error_handler *ehandler,
- struct discard_action discard_action)
+ struct source_action source_action)
{
struct sieve_exec_status estatus;
struct sieve_binary *sbin;
@@ -72,7 +78,8 @@
memset(&msgdata, 0, sizeof(msgdata));
msgdata.mail = mail;
msgdata.return_path = sender;
- msgdata.to_address = recipient;
+ msgdata.orig_envelope_to = recipient;
+ msgdata.final_envelope_to = recipient;
msgdata.auth_user = senv->username;
(void)mail_get_first_header(mail, "Message-ID", &msgdata.id);
@@ -85,24 +92,24 @@
/* Handle message in source folder */
if ( ret > 0 && !estatus.keep_original ) {
- switch ( discard_action.type ) {
+ switch ( source_action.type ) {
/* Leave it there */
- case DISCARD_ACTION_KEEP:
- sieve_info(ehandler, NULL, "message left in source folder");
+ case SOURCE_ACTION_KEEP:
+ sieve_info(ehandler, NULL, "message left in source mailbox");
break;
/* Flag message as \DELETED */
- case DISCARD_ACTION_DELETE:
- sieve_info(ehandler, NULL, "message flagged as deleted in source folder");
+ case SOURCE_ACTION_DELETE:
+ sieve_info(ehandler, NULL, "message flagged as deleted in source mailbox");
mail_update_flags(mail, MODIFY_ADD, MAIL_DELETED);
break;
/* Move message to Trash folder */
- case DISCARD_ACTION_TRASH_FOLDER:
+ case SOURCE_ACTION_TRASH_FOLDER:
sieve_info(ehandler, NULL,
"message in source folder moved to folder '%s'",
- discard_action.trash_folder);
+ source_action.trash_folder);
break;
/* Expunge the message immediately */
- case DISCARD_ACTION_EXPUNGE:
+ case SOURCE_ACTION_EXPUNGE:
sieve_info(ehandler, NULL, "message removed from source folder");
mail_expunge(mail);
break;
@@ -132,9 +139,9 @@
}
static int filter_mailbox
-(struct mailbox *box, struct sieve_binary *main_sbin,
+(struct mailbox *src_box, struct sieve_binary *main_sbin,
struct sieve_script_env *senv, struct sieve_error_handler *ehandler,
- struct discard_action discard_action)
+ struct source_action source_action)
{
struct mail_search_args *search_args;
struct mailbox_transaction_context *t;
@@ -144,7 +151,7 @@
/* Sync mailbox */
- if ( mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0 ) {
+ if ( mailbox_sync(src_box, MAILBOX_SYNC_FLAG_FULL_READ) < 0 ) {
return -1;
}
@@ -155,7 +162,7 @@
/* Iterate through all requested messages */
- t = mailbox_transaction_begin(box, 0);
+ t = mailbox_transaction_begin(src_box, 0);
search_ctx = mailbox_search_init(t, search_args, NULL);
mail_search_args_unref(&search_args);
@@ -182,7 +189,7 @@
sieve_info(ehandler, NULL,
"filtering: [%s; %"PRIuUOFF_T" bytes] %s", date, size, subject);
- ret = filter_message(mail, main_sbin, senv, ehandler, discard_action);
More information about the dovecot-cvs
mailing list