diff --git a/src/lib-sieve/sieve.c b/src/lib-sieve/sieve.c index 8ce37650d3b7116c6abee3f626814f9da585d242..e174b405d5db9acef6e0ea04151e3299b76a8499 100644 --- a/src/lib-sieve/sieve.c +++ b/src/lib-sieve/sieve.c @@ -259,9 +259,22 @@ struct sieve_binary *sieve_open } bool sieve_save - (struct sieve_binary *sbin, const char *path) +(struct sieve_binary *sbin, const char *bin_path) { - return sieve_binary_save(sbin, path); + return sieve_binary_save(sbin, bin_path); +} + +struct sieve_binary *sieve_load +(const char *bin_path) +{ + struct sieve_binary *sbin = sieve_binary_open(bin_path, NULL); + + if ( sbin != NULL && !sieve_binary_load(sbin) ) { + sieve_binary_unref(&sbin); + sbin = NULL; + } + + return sbin; } void sieve_close(struct sieve_binary **sbin) diff --git a/src/lib-sieve/sieve.h b/src/lib-sieve/sieve.h index a8d09ed3fc909866102ae567cdba60b7c5490f35..5aa953d260455d472e4a0910568053a9c3285433 100644 --- a/src/lib-sieve/sieve.h +++ b/src/lib-sieve/sieve.h @@ -72,10 +72,20 @@ struct sieve_binary *sieve_open struct sieve_error_handler *ehandler, bool *exists_r); /* sieve_save: - * Saves the binary as the file indicated by the path parameter. + * + * Saves the binary as the file indicated by the path parameter. If + * path is NULL, it chooses the default path relative to the original + * script. */ bool sieve_save - (struct sieve_binary *sbin, const char *path); + (struct sieve_binary *sbin, const char *bin_path); + +/* sieve_load: + * + * Loads the sieve binary indicated by the provided path. + */ +struct sieve_binary *sieve_load + (const char *bin_path); /* sieve_close: * diff --git a/src/sieve-tools/sieved.c b/src/sieve-tools/sieved.c index 6bb01788ea7adae5ac6ad71ca6c3df22493c4a84..f687a9cddd38a626d91a80c1b6b4332d4235d297 100644 --- a/src/sieve-tools/sieved.c +++ b/src/sieve-tools/sieved.c @@ -5,7 +5,6 @@ #include "sieve.h" #include "sieve-extensions.h" -#include "sieve-binary.h" #include "sieve-tool.h" #include "sieve-ext-debug.h" @@ -72,17 +71,12 @@ int main(int argc, char **argv) { /* Register tool-specific extensions */ (void) sieve_extension_register(&debug_extension, TRUE); - sbin = sieve_binary_open(binfile, NULL); - - if ( sbin != NULL && !sieve_binary_load(sbin) ) { - sieve_binary_unref(&sbin); - sbin = NULL; - } + sbin = sieve_load(binfile); if ( sbin != NULL ) { sieve_tool_dump_binary_to(sbin, outfile == NULL ? "-" : outfile); - sieve_binary_unref(&sbin); + sieve_close(&sbin); } else i_error("failed to load binary: %s", binfile);