From 1e5d2c6ae8b41d0be78249d6639c58268f69bd4f Mon Sep 17 00:00:00 2001 From: Timo Sirainen <timo.sirainen@dovecot.fi> Date: Tue, 1 Nov 2016 01:09:42 +0200 Subject: [PATCH] Adjust to var_expand*() API changes. --- src/lib-sieve/sieve-error.c | 11 ++++++++++- src/managesieve/main.c | 10 ++++++++-- src/managesieve/managesieve-client.c | 6 +++++- src/plugins/lda-sieve/lda-sieve-log.c | 6 +++++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/lib-sieve/sieve-error.c b/src/lib-sieve/sieve-error.c index bc7aa443c..a3c23f1e1 100644 --- a/src/lib-sieve/sieve-error.c +++ b/src/lib-sieve/sieve-error.c @@ -1300,13 +1300,22 @@ static const char *ATTR_FORMAT(3, 0) _expand_message struct var_expand_table *table = array_get_modifiable(&ehandler->table, &count); string_t *str = t_str_new(256); + const char *error; + static bool expand_error_logged = FALSE; /* Fill in substitution items */ table[0].value = t_strdup_vprintf(fmt, args); table[1].value = location; /* Expand variables */ - var_expand(str, ehandler->format, table); + if (var_expand(str, ehandler->format, table, &error) <= 0 && + !expand_error_logged) { + /* Log the error only once. This also prevents recursively + looping back here. */ + expand_error_logged = TRUE; + sieve_sys_error(_ehandler->svinst, + "Failed to expand error message: %s", error); + } return str_c(str); } diff --git a/src/managesieve/main.c b/src/managesieve/main.c index c2ae6c113..6bf5e3006 100644 --- a/src/managesieve/main.c +++ b/src/managesieve/main.c @@ -129,6 +129,7 @@ client_create_from_input(const struct mail_storage_service_input *input, struct mail_user *mail_user; struct client *client; struct managesieve_settings *set; + const char *error; if (mail_storage_service_lookup_next(storage_service, input, &user, &mail_user, error_r) <= 0) @@ -139,8 +140,13 @@ client_create_from_input(const struct mail_storage_service_input *input, if (set->verbose_proctitle) verbose_proctitle = TRUE; - settings_var_expand(&managesieve_setting_parser_info, set, mail_user->pool, - mail_user_var_expand_table(mail_user)); + if (settings_var_expand(&managesieve_setting_parser_info, set, mail_user->pool, + mail_user_var_expand_table(mail_user), &error) <= 0) { + i_error("Failed to expand settings: %s", error); + mail_storage_service_user_free(&user); + mail_user_unref(&mail_user); + return -1; + } client = client_create (fd_in, fd_out, input->session_id, mail_user, user, set); diff --git a/src/managesieve/managesieve-client.c b/src/managesieve/managesieve-client.c index cad6ef4bb..48a33aaf6 100644 --- a/src/managesieve/managesieve-client.c +++ b/src/managesieve/managesieve-client.c @@ -206,6 +206,7 @@ static const char *client_stats(struct client *client) }; struct var_expand_table *tab; string_t *str; + const char *error; tab = t_malloc_no0(sizeof(static_tab)); memcpy(tab, static_tab, sizeof(static_tab)); @@ -223,7 +224,10 @@ static const char *client_stats(struct client *client) tab[10].value = client->session_id; str = t_str_new(128); - var_expand(str, client->set->managesieve_logout_format, tab); + if (var_expand(str, client->set->managesieve_logout_format, tab, &error) <= 0) { + i_error("Failed to expand managesieve_logout_format=%s: %s", + client->set->managesieve_logout_format, error); + } return str_c(str); } diff --git a/src/plugins/lda-sieve/lda-sieve-log.c b/src/plugins/lda-sieve/lda-sieve-log.c index f2b0d0911..2c1ae4c4e 100644 --- a/src/plugins/lda-sieve/lda-sieve-log.c +++ b/src/plugins/lda-sieve/lda-sieve-log.c @@ -26,12 +26,16 @@ static const char *ATTR_FORMAT(2, 0) lda_sieve_log_expand_message struct mail_deliver_context *mdctx = ehandler->mdctx; const struct var_expand_table *table; string_t *str; + const char *error; table = mail_deliver_ctx_get_log_var_expand_table (mdctx, t_strdup_vprintf(fmt, args)); str = t_str_new(256); - var_expand(str, mdctx->set->deliver_log_format, table); + if (var_expand(str, mdctx->set->deliver_log_format, table, &error) <= 0) { + i_error("Failed to expand deliver_log_format=%s: %s", + mdctx->set->deliver_log_format, error); + } return str_c(str); } -- GitLab