From 7f6f92084d2451c8a5eaa74621317aaeb2566391 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Sat, 13 Dec 2008 18:41:20 +0100 Subject: [PATCH] Enotify: implemented construction and printing of action object. --- src/lib-sieve/plugins/enotify/cmd-notify.c | 17 +++---- src/lib-sieve/plugins/enotify/ntfy-mailto.c | 44 +++++++++++++++++-- .../plugins/enotify/sieve-ext-enotify.h | 7 ++- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/lib-sieve/plugins/enotify/cmd-notify.c b/src/lib-sieve/plugins/enotify/cmd-notify.c index 4106f54ed..7f5a64713 100644 --- a/src/lib-sieve/plugins/enotify/cmd-notify.c +++ b/src/lib-sieve/plugins/enotify/cmd-notify.c @@ -507,17 +507,14 @@ static void act_notify_print const struct sieve_result_print_env *rpenv, void *context, bool *keep ATTR_UNUSED) { - struct sieve_enotify_context *ctx = (struct sieve_enotify_context *) context; - - sieve_result_action_printf( rpenv, "send notification with method %s:", - ctx->method); - sieve_result_printf(rpenv, " => importance : %d\n", ctx->importance); - if ( ctx->message != NULL ) - sieve_result_printf(rpenv, " => message: \n%s\n", ctx->message); - if ( ctx->from != NULL ) - sieve_result_printf(rpenv, " => from : %s\n", ctx->from); + const struct sieve_enotify_context *nctx = + (const struct sieve_enotify_context *) context; + + sieve_result_action_printf + ( rpenv, "send notification with method '%s:':", nctx->method->identifier); - /* FIXME: list options */ + if ( nctx->method->action_print != NULL ) + nctx->method->action_print(rpenv, nctx); } /* Result execution */ diff --git a/src/lib-sieve/plugins/enotify/ntfy-mailto.c b/src/lib-sieve/plugins/enotify/ntfy-mailto.c index 4c58079c6..33edca9f3 100644 --- a/src/lib-sieve/plugins/enotify/ntfy-mailto.c +++ b/src/lib-sieve/plugins/enotify/ntfy-mailto.c @@ -50,7 +50,10 @@ static bool ntfy_mailto_runtime_check_operands (const struct sieve_runtime_env *renv, unsigned int source_line, const char *uri, const char *uri_body, const char *message, const char *from, void **context); -static bool ntfy_mailto_execute +static void ntfy_mailto_action_print + (const struct sieve_result_print_env *rpenv, + const struct sieve_enotify_context *nctx); +static bool ntfy_mailto_action_execute (const struct sieve_action_exec_env *aenv, const struct sieve_enotify_context *nctx); @@ -58,7 +61,8 @@ const struct sieve_enotify_method mailto_notify = { "mailto", ntfy_mailto_validate_uri, ntfy_mailto_runtime_check_operands, - ntfy_mailto_execute + ntfy_mailto_action_print, + ntfy_mailto_action_execute }; /* @@ -365,6 +369,40 @@ static bool ntfy_mailto_runtime_check_operands return TRUE; } +/* + * Action printing + */ + +static void ntfy_mailto_action_print +(const struct sieve_result_print_env *rpenv, + const struct sieve_enotify_context *nctx) +{ + unsigned int count, i; + const char *const *recipients; + const struct ntfy_mailto_header_field *headers; + struct ntfy_mailto_context *mtctx = + (struct ntfy_mailto_context *) nctx->method_context; + + sieve_result_printf(rpenv, " => importance : %d\n", nctx->importance); + if ( nctx->message != NULL ) + sieve_result_printf(rpenv, " => message : \n%s\n", nctx->message); + if ( nctx->from != NULL ) + sieve_result_printf(rpenv, " => from : %s\n", nctx->from); + + sieve_result_printf(rpenv, " => recipients :\n" ); + recipients = array_get(&mtctx->recipients, &count); + for ( i = 0; i < count; i++ ) { + sieve_result_printf(rpenv, " + %s\n", recipients[i]); + } + + sieve_result_printf(rpenv, " => headers :\n" ); + headers = array_get(&mtctx->headers, &count); + for ( i = 0; i < count; i++ ) { + sieve_result_printf(rpenv, " + %s: %s\n", + headers[i].name, headers[i].body); + } +} + /* * Action execution */ @@ -381,7 +419,7 @@ static bool _contains_8bit(const char *msg) return FALSE; } -static bool ntfy_mailto_execute +static bool ntfy_mailto_action_execute (const struct sieve_action_exec_env *aenv, const struct sieve_enotify_context *nctx) { diff --git a/src/lib-sieve/plugins/enotify/sieve-ext-enotify.h b/src/lib-sieve/plugins/enotify/sieve-ext-enotify.h index 5f66f5440..5dbed7d7f 100644 --- a/src/lib-sieve/plugins/enotify/sieve-ext-enotify.h +++ b/src/lib-sieve/plugins/enotify/sieve-ext-enotify.h @@ -32,8 +32,13 @@ struct sieve_enotify_method { const char *uri, const char *uri_body, const char *message, const char *from, void **context); + /* Action print */ + void (*action_print) + (const struct sieve_result_print_env *rpenv, + const struct sieve_enotify_context *nctx); + /* Action execution */ - bool (*execute) + bool (*action_execute) (const struct sieve_action_exec_env *aenv, const struct sieve_enotify_context *nctx); }; -- GitLab