diff --git a/src/lib-sieve/sieve.c b/src/lib-sieve/sieve.c index c6fe9948573bde2cbf34f38e261d457b06e5289d..58584cecda43d0a5b90c21f8b644bf6bb46f99fa 100644 --- a/src/lib-sieve/sieve.c +++ b/src/lib-sieve/sieve.c @@ -799,6 +799,43 @@ size_t sieve_max_script_size(struct sieve_instance *svinst) return svinst->max_script_size; } +/* + * User log + */ + +const char *sieve_user_get_log_path +(struct sieve_instance *svinst, + struct sieve_script *user_script) +{ + const char *log_path = NULL; + + /* Determine user log file path */ + if ( (log_path=sieve_setting_get + (svinst, "sieve_user_log")) == NULL ) { + const char *path; + + if ( user_script == NULL || + (path=sieve_file_script_get_path(user_script)) == NULL ) { + /* Default */ + if ( svinst->home_dir != NULL ) { + log_path = t_strconcat + (svinst->home_dir, "/.dovecot.sieve.log", NULL); + } + } else { + /* Use script file as a base (legacy behavior) */ + log_path = t_strconcat(path, ".log", NULL); + } + } else if ( svinst->home_dir != NULL ) { + /* Expand home dir if necessary */ + if ( log_path[0] == '~' ) { + log_path = home_expand_tilde(log_path, svinst->home_dir); + } else if ( log_path[0] != '/' ) { + log_path = t_strconcat(svinst->home_dir, "/", log_path, NULL); + } + } + return log_path; +} + /* * Script trace log */ diff --git a/src/lib-sieve/sieve.h b/src/lib-sieve/sieve.h index 3e108e02aab253be99008c3175b5bc6013879da8..23d5fe153a1356ace1a297dc93388d75656637b2 100644 --- a/src/lib-sieve/sieve.h +++ b/src/lib-sieve/sieve.h @@ -213,6 +213,15 @@ unsigned int sieve_max_redirects(struct sieve_instance *svinst); unsigned int sieve_max_actions(struct sieve_instance *svinst); size_t sieve_max_script_size(struct sieve_instance *svinst); +/* + * User log + */ + +const char *sieve_user_get_log_path + (struct sieve_instance *svinst, + struct sieve_script *user_script) + ATTR_NULL(2); + /* * Script trace log */ diff --git a/src/plugins/imapsieve/imap-sieve.c b/src/plugins/imapsieve/imap-sieve.c index 5904aab903e19b94dc646cb0afc25927ce5a0671..063c4273ff8abe5f83edf5392a71e2dc30cd58b4 100644 --- a/src/plugins/imapsieve/imap-sieve.c +++ b/src/plugins/imapsieve/imap-sieve.c @@ -246,44 +246,14 @@ struct imap_sieve_run { }; static void -imap_sieve_run_init_user_log( - struct imap_sieve_run *isrun) +imap_sieve_run_init_user_log(struct imap_sieve_run *isrun) { struct imap_sieve *isieve = isrun->isieve; struct sieve_instance *svinst = isieve->svinst; const char *log_path; - /* Determine user log file path */ // FIXME: code shared with LDA - if ( (log_path=mail_user_plugin_getenv - (isieve->user, "sieve_user_log")) == NULL ) { - const char *path; - - if ( isrun->user_script == NULL || - (path=sieve_file_script_get_path - (isrun->user_script)) == NULL ) { - /* Default */ - if ( isieve->home_dir != NULL ) { - log_path = t_strconcat - (isieve->home_dir, "/.dovecot.sieve.log", NULL); - } - } else { - /* Use script file as a basis (legacy behavior) */ - log_path = t_strconcat(path, ".log", NULL); - } - } else { - if ( isieve->home_dir != NULL ) { - /* Expand home dir if necessary */ - if ( log_path[0] == '~' ) { - log_path = home_expand_tilde - (log_path, isieve->home_dir); - } else if ( log_path[0] != '/' ) { - log_path = t_strconcat - (isieve->home_dir, "/", log_path, NULL); - } - } - } - - /* Initialize user error handler */ + log_path = sieve_user_get_log_path + (svinst, isrun->user_script); if ( log_path != NULL ) { isrun->userlog = p_strdup(isrun->pool, log_path); isrun->user_ehandler = sieve_logfile_ehandler_create diff --git a/src/plugins/lda-sieve/lda-sieve-plugin.c b/src/plugins/lda-sieve/lda-sieve-plugin.c index 6a7728e44d3e22f35a432961abb788592c5fcaa1..4e11b673d619bf4819136a7ef101d1924f2d0c9c 100644 --- a/src/plugins/lda-sieve/lda-sieve-plugin.c +++ b/src/plugins/lda-sieve/lda-sieve-plugin.c @@ -793,32 +793,9 @@ static int lda_sieve_execute /* Initialize user error handler */ if ( srctx->user_script != NULL ) { - const char *log_path = NULL; - - /* Determine user log file path */ - if ( (log_path=mail_user_plugin_getenv - (mdctx->dest_user, "sieve_user_log")) == NULL ) { - const char *path; - - if ( (path=sieve_file_script_get_path(srctx->user_script)) == NULL ) { - /* Default */ - if ( srctx->home_dir != NULL ) { - log_path = t_strconcat - (srctx->home_dir, "/.dovecot.sieve.log", NULL); - } - } else { - /* Use script file as a basic (legacy behavior) */ - log_path = t_strconcat(path, ".log", NULL); - } - } else if ( srctx->home_dir != NULL ) { - /* Expand home dir if necessary */ - if ( log_path[0] == '~' ) { - log_path = home_expand_tilde(log_path, srctx->home_dir); - } else if ( log_path[0] != '/' ) { - log_path = t_strconcat(srctx->home_dir, "/", log_path, NULL); - } - } - + const char *log_path = + sieve_user_get_log_path(svinst, srctx->user_script); + if ( log_path != NULL ) { srctx->userlog = log_path; srctx->user_ehandler = sieve_logfile_ehandler_create