dovecot-2.0-pigeonhole: Sieve-Tools: fully use Dovecot service a...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Sat Jul 3 23:44:57 EEST 2010
details: http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/a3f9c77e220a
changeset: 1312:a3f9c77e220a
user: Stephan Bosch <stephan at rename-it.nl>
date: Sat Jul 03 22:44:49 2010 +0200
description:
Sieve-Tools: fully use Dovecot service and settings API.
diffstat:
src/lib-sieve-tool/sieve-tool.c | 80 ++++++++------------------
src/lib-sieve-tool/sieve-tool.h | 4 +-
src/lib-sieve/sieve-script.c | 7 +-
src/sieve-tools/sieve-test.c | 89 +++++++++++++++--------------
src/sieve-tools/sievec.c | 105 +++++++++++++++++++++++-----------
src/sieve-tools/sieved.c | 103 +++++++++++++++++++++++-----------
src/testsuite/testsuite.c | 4 +-
7 files changed, 219 insertions(+), 173 deletions(-)
diffs (truncated from 692 to 300 lines):
diff -r 9b9f2cd44aca -r a3f9c77e220a src/lib-sieve-tool/sieve-tool.c
--- a/src/lib-sieve-tool/sieve-tool.c Sat Jul 03 19:07:52 2010 +0200
+++ b/src/lib-sieve-tool/sieve-tool.c Sat Jul 03 22:44:49 2010 +0200
@@ -9,6 +9,7 @@
#include "hostpid.h"
#include "dict.h"
#include "mail-storage.h"
+#include "mail-user.h"
#include "sieve.h"
#include "sieve-plugins.h"
@@ -25,8 +26,6 @@
* Global state
*/
-static struct ioloop *ioloop;
-
/* Sieve instance */
struct sieve_instance *sieve_instance;
@@ -36,15 +35,29 @@
*/
const char *sieve_tool_get_setting
-(void *context ATTR_UNUSED, const char *identifier)
+(void *context, const char *identifier)
{
- return getenv(t_str_ucase(identifier));
+ struct mail_user *mail_user = (struct mail_user *) context;
+
+ if ( mail_user == NULL )
+ return NULL;
+
+ return mail_user_plugin_getenv(mail_user, identifier);
}
const char *sieve_tool_get_homedir
-(void *context ATTR_UNUSED)
+(void *context)
{
- return getenv("HOME");
+ struct mail_user *mail_user = (struct mail_user *) context;
+ const char *home = NULL;
+
+ if ( mail_user == NULL )
+ return NULL;
+
+ if ( mail_user_get_home(mail_user, &home) <= 0 )
+ return NULL;
+
+ return home;
}
const struct sieve_environment sieve_tool_sieve_env = {
@@ -53,53 +66,15 @@
};
/*
- * Signal handlers
- */
-
-static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED)
-{
- /* warn about being killed because of some signal, except SIGINT (^C)
- * which is too common at least while testing :)
- */
- if (si->si_signo != SIGINT) {
- /* FIXME: strange error for a command line tool */
- i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)",
- si->si_signo, dec2str(si->si_pid),
- dec2str(si->si_uid),
- lib_signal_code_to_str(si->si_signo, si->si_code));
- }
- io_loop_stop(current_ioloop);
-}
-
-/*
* Initialization
*/
-/* HACK */
-static bool _init_lib = FALSE;
-
-void sieve_tool_init(bool init_lib)
-{
- _init_lib = init_lib;
-
- if ( _init_lib ) {
- lib_init();
-
- ioloop = io_loop_create();
-
- lib_signals_init();
- lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
- lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
- lib_signals_ignore(SIGPIPE, TRUE);
- lib_signals_ignore(SIGALRM, FALSE);
- }
-}
-
-void sieve_tool_sieve_init(const struct sieve_environment *env, bool debug)
+void sieve_tool_init
+(const struct sieve_environment *env, void *context, bool debug)
{
if ( env == NULL ) env = &sieve_tool_sieve_env;
- if ( (sieve_instance=sieve_init(env, NULL, debug)) == NULL )
+ if ( (sieve_instance=sieve_init(env, context, debug)) == NULL )
i_fatal("failed to initialize sieve implementation\n");
}
@@ -107,13 +82,6 @@
{
sieve_deinit(&sieve_instance);
- if ( _init_lib ) {
- lib_signals_deinit();
-
- io_loop_destroy(&ioloop);
-
- lib_deinit();
- }
}
@@ -201,7 +169,7 @@
sieve_error_handler_accept_infolog(ehandler, TRUE);
if ( (sbin = sieve_compile(sieve_instance, filename, name, ehandler)) == NULL )
- i_error("failed to compile sieve script '%s'\n", filename);
+ i_error("failed to compile sieve script '%s'", filename);
sieve_error_handler_unref(&ehandler);
@@ -218,7 +186,7 @@
if ( (sbin = sieve_open(sieve_instance, filename, NULL, ehandler, NULL)) == NULL ) {
sieve_error_handler_unref(&ehandler);
- i_fatal("Failed to compile sieve script\n");
+ i_fatal("Failed to compile sieve script");
}
sieve_error_handler_unref(&ehandler);
diff -r 9b9f2cd44aca -r a3f9c77e220a src/lib-sieve-tool/sieve-tool.h
--- a/src/lib-sieve-tool/sieve-tool.h Sat Jul 03 19:07:52 2010 +0200
+++ b/src/lib-sieve-tool/sieve-tool.h Sat Jul 03 22:44:49 2010 +0200
@@ -23,8 +23,8 @@
* Initialization
*/
-void sieve_tool_init(bool init_lib);
-void sieve_tool_sieve_init(const struct sieve_environment *env, bool debug);
+void sieve_tool_init
+ (const struct sieve_environment *env, void *context, bool debug);
void sieve_tool_deinit(void);
/*
diff -r 9b9f2cd44aca -r a3f9c77e220a src/lib-sieve/sieve-script.c
--- a/src/lib-sieve/sieve-script.c Sat Jul 03 19:07:52 2010 +0200
+++ b/src/lib-sieve/sieve-script.c Sat Jul 03 22:44:49 2010 +0200
@@ -5,6 +5,7 @@
#include "compat.h"
#include "unichar.h"
#include "array.h"
+#include "abspath.h"
#include "istream.h"
#include "eacces-error.h"
@@ -163,9 +164,11 @@
if ( (ret=lstat(path, &st)) < 0 ) {
switch ( errno ) {
case ENOENT:
- if ( exists_r == NULL )
+ if ( exists_r == NULL ) {
sieve_error(ehandler, basename, "sieve script does not exist");
- else
+ if ( svinst->debug )
+ sieve_sys_debug("script file %s not found", t_abspath(path));
+ } else
*exists_r = FALSE;
break;
case EACCES:
diff -r 9b9f2cd44aca -r a3f9c77e220a src/sieve-tools/sieve-test.c
--- a/src/sieve-tools/sieve-test.c Sat Jul 03 19:07:52 2010 +0200
+++ b/src/sieve-tools/sieve-test.c Sat Jul 03 22:44:49 2010 +0200
@@ -103,7 +103,12 @@
int main(int argc, char **argv)
{
- enum mail_storage_service_flags service_flags = 0;
+ enum master_service_flags service_flags =
+ MASTER_SERVICE_FLAG_STANDALONE |
+ MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN;
+ enum mail_storage_service_flags storage_service_flags =
+ MAIL_STORAGE_SERVICE_FLAG_NO_CHDIR |
+ MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT;
struct mail_storage_service_ctx *storage_service;
struct mail_storage_service_user *service_user;
struct mail_storage_service_input service_input;
@@ -111,8 +116,8 @@
ARRAY_TYPE (const_string) scriptfiles;
ARRAY_TYPE (const_string) plugins;
const char *scriptfile, *recipient, *sender, *mailbox, *dumpfile, *mailfile,
- *mailloc, *extensions;
- const char *user, *home, *errstr;
+ *mailloc, *extensions, *username;
+ const char *errstr;
struct mail_raw *mailr;
struct mail_namespace_settings ns_set;
struct mail_namespace *ns = NULL;
@@ -128,18 +133,15 @@
int ret, c;
master_service = master_service_init("sieve-test",
- MASTER_SERVICE_FLAG_STANDALONE, &argc, &argv, "r:f:m:d:l:x:s:P:eCtD");
-
- sieve_tool_init(FALSE);
+ service_flags, &argc, &argv, "r:f:m:d:l:x:s:P:eCtD");
t_array_init(&scriptfiles, 16);
t_array_init(&plugins, 4);
-
- user = getenv("USER");
/* Parse arguments */
scriptfile = recipient = sender = mailbox = dumpfile = mailfile = mailloc =
extensions = NULL;
+ username = getenv("USER");
while ((c = master_getopt(master_service)) > 0) {
switch (c) {
case 'r':
@@ -166,6 +168,11 @@
/* extensions */
extensions = optarg;
break;
+ case 'u':
+ storage_service_flags |=
+ MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
+ username = optarg;
+ break;
case 's':
/* scriptfile executed before main script */
{
@@ -204,14 +211,14 @@
}
if ( optind < argc ) {
- scriptfile = t_strdup(argv[optind++]);
+ scriptfile = argv[optind++];
} else {
print_help();
i_fatal_status(EX_USAGE, "Missing <script-file> argument");
}
if ( optind < argc ) {
- mailfile = t_strdup(argv[optind++]);
+ mailfile = argv[optind++];
} else {
print_help();
i_fatal_status(EX_USAGE, "Missing <mail-file> argument");
@@ -222,7 +229,22 @@
i_fatal_status(EX_USAGE, "Unknown argument: %s", argv[optind]);
}
- sieve_tool_sieve_init(NULL, debug);
+ master_service_init_finish(master_service);
+
+ memset(&service_input, 0, sizeof(service_input));
+ service_input.module = "sieve-test";
+ service_input.service = "sieve-test";
+ service_input.username = username;
+
+ storage_service = mail_storage_service_init
+ (master_service, NULL, storage_service_flags);
+ if (mail_storage_service_lookup_next(storage_service, &service_input,
+ &service_user, &mail_user_dovecot, &errstr) <= 0)
+ i_fatal("%s", errstr);
+
+ /* Initialize Sieve */
+
+ sieve_tool_init(NULL, (void *) mail_user_dovecot, debug);
if ( array_count(&plugins) > 0 ) {
sieve_tool_load_plugins(&plugins);
@@ -234,27 +256,6 @@
/* Register tool-specific extensions */
(void) sieve_extension_register(sieve_instance, &debug_extension, TRUE);
-
- user = sieve_tool_get_user();
- home = getenv("HOME");
-
- /* Initialize mail storages */
- //env_remove("HOME");
- env_put("DOVECONF_ENV=1");
- env_put(t_strdup_printf("MAIL=maildir:/tmp/dovecot-test-%s", user));
-
- master_service_init_finish(master_service);
-
- memset(&service_input, 0, sizeof(service_input));
More information about the dovecot-cvs
mailing list