From f461b22e119f6756619544ad8779cbf1f93a9c95 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Thu, 20 Nov 2008 00:54:14 +0100 Subject: [PATCH] Fixed error handling of actions that send mail. --- src/lib-sieve/cmd-redirect.c | 14 +++++++++++--- src/lib-sieve/ext-reject.c | 18 +++++++++++++----- src/lib-sieve/plugins/vacation/cmd-vacation.c | 17 +++++++++-------- src/plugins/lda-sieve/lda-sieve-plugin.c | 2 +- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/lib-sieve/cmd-redirect.c b/src/lib-sieve/cmd-redirect.c index ddd500d53..b5dc36cf1 100644 --- a/src/lib-sieve/cmd-redirect.c +++ b/src/lib-sieve/cmd-redirect.c @@ -280,12 +280,12 @@ static bool act_redirect_send /* Just to be sure */ if ( senv->smtp_open == NULL || senv->smtp_close == NULL ) { - sieve_result_error(aenv, "redirect action has no means to send mail."); + sieve_result_warning(aenv, "redirect action has no means to send mail."); return FALSE; } if (mail_get_stream(msgdata->mail, NULL, NULL, &input) < 0) - return -1; + return FALSE; /* Open SMTP transport */ smtp_handle = senv->smtp_open(ctx->to_address, msgdata->return_path, &f); @@ -304,7 +304,15 @@ static bool act_redirect_send i_stream_unref(&input); /* Close SMTP transport */ - return senv->smtp_close(smtp_handle); + if ( !senv->smtp_close(smtp_handle) ) { + sieve_result_error(aenv, + "failed to redirect message to <%s> " + "(refer to server log for more information)", + str_sanitize(ctx->to_address, 80)); + return FALSE; + } + + return TRUE; } static bool act_redirect_commit diff --git a/src/lib-sieve/ext-reject.c b/src/lib-sieve/ext-reject.c index 70b2c0361..89ea05126 100644 --- a/src/lib-sieve/ext-reject.c +++ b/src/lib-sieve/ext-reject.c @@ -318,8 +318,8 @@ static bool act_reject_send /* Just to be sure */ if ( senv->smtp_open == NULL || senv->smtp_close == NULL ) { - sieve_result_error(aenv, "reject action has no means to send mail."); - return FALSE; + sieve_result_warning(aenv, "reject action has no means to send mail."); + return TRUE; } smtp_handle = senv->smtp_open(msgdata->return_path, NULL, &f); @@ -395,7 +395,15 @@ static bool act_reject_send fprintf(f, "\r\n\r\n--%s--\r\n", boundary); - return senv->smtp_close(smtp_handle); + if ( !senv->smtp_close(smtp_handle) ) { + sieve_result_error(aenv, + "failed to send rejection message to <%s> " + "(refer to server log for more information)", + str_sanitize(msgdata->return_path, 80)); + return FALSE; + } + + return TRUE; } static bool act_reject_commit @@ -411,14 +419,14 @@ static bool act_reject_commit *keep = FALSE; return TRUE; } - + if ( act_reject_send(aenv, ctx) ) { sieve_result_log(aenv, "rejected"); *keep = FALSE; return TRUE; } - + return FALSE; } diff --git a/src/lib-sieve/plugins/vacation/cmd-vacation.c b/src/lib-sieve/plugins/vacation/cmd-vacation.c index 57c3343ce..12daacd56 100644 --- a/src/lib-sieve/plugins/vacation/cmd-vacation.c +++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c @@ -800,8 +800,8 @@ static bool act_vacation_send /* Check smpt functions just to be sure */ if ( senv->smtp_open == NULL || senv->smtp_close == NULL ) { - sieve_result_error(aenv, "vacation action has no means to send mail."); - return FALSE; + sieve_result_warning(aenv, "vacation action has no means to send mail."); + return TRUE; } /* Open smtp session */ @@ -842,10 +842,15 @@ static bool act_vacation_send fprintf(f, "%s\r\n", ctx->reason); /* Close smtp session */ - if ( senv->smtp_close(smtp_handle) ) + if ( !senv->smtp_close(smtp_handle) ) { + sieve_result_error(aenv, + "failed to send vacation response to <%s> " + "(refer to server log for more information)", + str_sanitize(msgdata->return_path, 128)); return TRUE; + } - return FALSE; + return TRUE; } static void act_vacation_hash @@ -1011,10 +1016,6 @@ static bool act_vacation_commit return TRUE; } - /* Failure message; should be preceded by a more informative error */ - sieve_result_error(aenv, "failed to send vacation response to <%s>", - str_sanitize(msgdata->return_path, 128)); - return FALSE; } diff --git a/src/plugins/lda-sieve/lda-sieve-plugin.c b/src/plugins/lda-sieve/lda-sieve-plugin.c index 34f1f98a0..b04d48b3f 100644 --- a/src/plugins/lda-sieve/lda-sieve-plugin.c +++ b/src/plugins/lda-sieve/lda-sieve-plugin.c @@ -41,7 +41,7 @@ static bool lda_sieve_smtp_close(void *handle) { struct smtp_client *smtp_client = (struct smtp_client *) handle; - return ( smtp_client_close(smtp_client) >= 0 ); + return ( smtp_client_close(smtp_client) == 0 ); } /* -- GitLab