From 36e5af33499ef4dcc8740a3f445446c71b0020c5 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Thu, 3 Apr 2008 17:10:58 +0200
Subject: [PATCH] Added -c option to sieve-test to force compile.

---
 README                     |  3 ++-
 src/sieve-bin/sieve-test.c | 14 +++++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/README b/README
index f0ffe6f3e..b057a9823 100644
--- a/README
+++ b/README
@@ -41,7 +41,7 @@ Otherwise, the dump is printed to stdout.
 -- 
 
 sieve-test [-r <recipient address>][-s <envelope sender>]
-           [-m <mailbox>][-d <dump filename>] <scriptfile> <mailfile>
+           [-m <mailbox>][-d <dump filename>][-c] <scriptfile> <mailfile>
 
 Reads mail message from the specified mailfile and executes the specified sieve 
 script to produce a verdict. This prints an execution dump with the instructions 
@@ -54,6 +54,7 @@ Options:
 	-m	the mailbox where the keep action should store
 	-d	causes a dump of the generated code to be written to the specified
 		file. Using - as filename causes the dump to be written to stdout
+	-c  force compilation (ignore any existing binary)
 
 --
 
diff --git a/src/sieve-bin/sieve-test.c b/src/sieve-bin/sieve-test.c
index c30ff636d..1f75a3a6f 100644
--- a/src/sieve-bin/sieve-test.c
+++ b/src/sieve-bin/sieve-test.c
@@ -22,7 +22,7 @@ static void print_help(void)
 {
 	printf(
 "Usage: sieve-test [-r <recipient address>][-s <envelope sender>]\n"
-"                  [-m <mailbox>][-d <dump filename>] <scriptfile> <mailfile>\n"
+"                  [-m <mailbox>][-d <dump filename>][-c] <scriptfile> <mailfile>\n"
 	);
 }
 
@@ -37,6 +37,7 @@ int main(int argc, char **argv)
 	struct sieve_message_data msgdata;
 	struct sieve_script_env scriptenv;
 	struct sieve_error_handler *ehandler;
+	bool force_compile = FALSE;
 
 	bin_init();
 
@@ -67,6 +68,9 @@ int main(int argc, char **argv)
 			if (i == argc)
 				i_fatal("Missing -d argument");
 			dumpfile = argv[i];
+		} else if (strcmp(argv[i], "-c") == 0) {
+            /* force compile */
+			force_compile = TRUE;
 		} else if ( scriptfile == NULL ) {
 			scriptfile = argv[i];
 		} else if ( mailfile == NULL ) {
@@ -91,8 +95,12 @@ int main(int argc, char **argv)
 	mfd = bin_open_mail_file(mailfile);
 	
 	/* Compile sieve script */
-	sbin = bin_open_sieve_script(scriptfile);
-	
+	if ( force_compile ) {
+		sbin = bin_compile_sieve_script(scriptfile);
+	} else {
+		sbin = bin_open_sieve_script(scriptfile);
+	}
+
 	/* Dump script */
 	bin_dump_sieve_binary_to(sbin, dumpfile);
 	
-- 
GitLab