Skip to content
Snippets Groups Projects
Commit 76f0f1f4 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Vacation extension: from address of reply is now by default equal to whatever...

Vacation extension: from address of reply is now by default equal to whatever known recipient alias matched the headers of the message.
parent 0b1d5db1
No related branches found
No related tags found
No related merge requests found
...@@ -868,7 +868,7 @@ static bool _contains_8bit(const char *text) ...@@ -868,7 +868,7 @@ static bool _contains_8bit(const char *text)
static bool act_vacation_send static bool act_vacation_send
(const struct sieve_action_exec_env *aenv, struct act_vacation_context *ctx, (const struct sieve_action_exec_env *aenv, struct act_vacation_context *ctx,
const char *sender, const char *recipient) const char *reply_to, const char *reply_from)
{ {
const struct sieve_message_data *msgdata = aenv->msgdata; const struct sieve_message_data *msgdata = aenv->msgdata;
const struct sieve_script_env *senv = aenv->scriptenv; const struct sieve_script_env *senv = aenv->scriptenv;
...@@ -903,7 +903,7 @@ static bool act_vacation_send ...@@ -903,7 +903,7 @@ static bool act_vacation_send
/* Open smtp session */ /* Open smtp session */
smtp_handle = sieve_smtp_open(senv, sender, NULL, &f); smtp_handle = sieve_smtp_open(senv, reply_to, NULL, &f);
outmsgid = sieve_message_get_new_id(senv); outmsgid = sieve_message_get_new_id(senv);
/* Produce a proper reply */ /* Produce a proper reply */
...@@ -914,15 +914,15 @@ static bool act_vacation_send ...@@ -914,15 +914,15 @@ static bool act_vacation_send
if ( ctx->from != NULL && *(ctx->from) != '\0' ) if ( ctx->from != NULL && *(ctx->from) != '\0' )
rfc2822_header_field_utf8_printf(f, "From", "%s", ctx->from); rfc2822_header_field_utf8_printf(f, "From", "%s", ctx->from);
else if ( recipient != NULL ) else if ( reply_from != NULL )
rfc2822_header_field_printf(f, "From", "<%s>", recipient); rfc2822_header_field_printf(f, "From", "<%s>", reply_from);
else else
rfc2822_header_field_printf(f, "From", "Postmaster <%s>", senv->postmaster_address); rfc2822_header_field_printf(f, "From", "Postmaster <%s>", senv->postmaster_address);
/* FIXME: If From header of message has same address, we should use that in /* FIXME: If From header of message has same address, we should use that in
* stead properly include the phrase part. * stead properly include the phrase part.
*/ */
rfc2822_header_field_printf(f, "To", "<%s>", sender); rfc2822_header_field_printf(f, "To", "<%s>", reply_to);
if ( _contains_8bit(subject) ) if ( _contains_8bit(subject) )
rfc2822_header_field_utf8_printf(f, "Subject", "%s", subject); rfc2822_header_field_utf8_printf(f, "Subject", "%s", subject);
...@@ -964,7 +964,7 @@ static bool act_vacation_send ...@@ -964,7 +964,7 @@ static bool act_vacation_send
sieve_result_error(aenv, sieve_result_error(aenv,
"failed to send vacation response to <%s> " "failed to send vacation response to <%s> "
"(refer to server log for more information)", "(refer to server log for more information)",
str_sanitize(sender, 128)); str_sanitize(reply_to, 128));
return TRUE; return TRUE;
} }
...@@ -998,6 +998,7 @@ static bool act_vacation_commit ...@@ -998,6 +998,7 @@ static bool act_vacation_commit
const char *const *headers; const char *const *headers;
const char *sender = sieve_message_get_sender(aenv->msgctx); const char *sender = sieve_message_get_sender(aenv->msgctx);
const char *recipient = sieve_message_get_recipient(aenv->msgctx); const char *recipient = sieve_message_get_recipient(aenv->msgctx);
const char *reply_from = NULL;
/* Is the recipient unset? /* Is the recipient unset?
*/ */
...@@ -1097,8 +1098,10 @@ static bool act_vacation_commit ...@@ -1097,8 +1098,10 @@ static bool act_vacation_commit
if ( mail_get_headers_utf8 if ( mail_get_headers_utf8
(msgdata->mail, *hdsp, &headers) >= 0 && headers[0] != NULL ) { (msgdata->mail, *hdsp, &headers) >= 0 && headers[0] != NULL ) {
if ( _contains_my_address(headers, recipient) ) if ( _contains_my_address(headers, recipient) ) {
reply_from = recipient;
break; break;
}
if ( ctx->addresses != NULL ) { if ( ctx->addresses != NULL ) {
bool found = FALSE; bool found = FALSE;
...@@ -1106,6 +1109,7 @@ static bool act_vacation_commit ...@@ -1106,6 +1109,7 @@ static bool act_vacation_commit
while ( !found && *my_address != NULL ) { while ( !found && *my_address != NULL ) {
found = _contains_my_address(headers, *my_address); found = _contains_my_address(headers, *my_address);
reply_from = *my_address;
my_address++; my_address++;
} }
...@@ -1125,7 +1129,7 @@ static bool act_vacation_commit ...@@ -1125,7 +1129,7 @@ static bool act_vacation_commit
/* Send the message */ /* Send the message */
if ( act_vacation_send(aenv, ctx, sender, recipient) ) { if ( act_vacation_send(aenv, ctx, sender, reply_from) ) {
sieve_result_log(aenv, "sent vacation response to <%s>", sieve_result_log(aenv, "sent vacation response to <%s>",
str_sanitize(sender, 128)); str_sanitize(sender, 128));
......
...@@ -15,21 +15,21 @@ test_set "envelope.from" "sirius@rename-it.nl"; ...@@ -15,21 +15,21 @@ test_set "envelope.from" "sirius@rename-it.nl";
test_set "envelope.to" "timo@iki.fi"; test_set "envelope.to" "timo@iki.fi";
test "Basic" { test "Basic" {
vacation :addresses "tss@iki.fi" :from "Timo Sirainen <tss@iki.fi>" "I am gone"; vacation :addresses "tss@iki.fi" :from "Timo Sirainen <sirainen@iki.fi>" "I am gone";
if not test_result_execute { if not test_result_execute {
test_fail "failed to execute vacation"; test_fail "failed to execute vacation";
} }
test_message :smtp 0; test_message :smtp 0;
if not address :is "to" "sirius@rename-it.nl" { if not address :is "to" "sirius@rename-it.nl" {
test_fail "to address incorrect"; test_fail "to address incorrect";
} }
if not address :is "from" "tss@iki.fi" { if not address :is "from" "sirainen@iki.fi" {
test_fail "from address incorrect"; test_fail "from address incorrect";
} }
if not envelope :is "to" "sirius@rename-it.nl" { if not envelope :is "to" "sirius@rename-it.nl" {
test_fail "envelope recipient incorrect"; test_fail "envelope recipient incorrect";
...@@ -54,3 +54,69 @@ test "Null Sender" { ...@@ -54,3 +54,69 @@ test "Null Sender" {
test_fail "reject sent message to NULL sender"; test_fail "reject sent message to NULL sender";
} }
} }
test_result_reset;
test_set "message" text:
From: stephan@rename-it.nl
To: timo@iki.fi
Cc: stephan@drunksnipers.com
Subject: Frop!
Frop!
.
;
test_set "envelope.from" "sirius@rename-it.nl";
test_set "envelope.to" "timo@iki.fi";
test "Envelope.to == To" {
vacation "I am gone";
if not test_result_execute {
test_fail "failed to execute vacation";
}
test_message :smtp 0;
if not address :is "from" "timo@iki.fi" {
test_fail "from address incorrect";
}
if not envelope :is "from" "" {
test_fail "envelope sender not null";
}
}
test_result_reset;
test_set "message" text:
From: stephan@rename-it.nl
To: tss@iki.fi
Cc: stephan@drunksnipers.com
Subject: Frop!
Frop!
.
;
test_set "envelope.from" "sirius@rename-it.nl";
test_set "envelope.to" "timo@iki.fi";
test "Envelope.to != To" {
vacation :addresses "tss@iki.fi" "I am gone";
if not test_result_execute {
test_fail "failed to execute vacation";
}
test_message :smtp 0;
if not address :is "from" "tss@iki.fi" {
test_fail "from address incorrect";
}
if not envelope :is "from" "" {
test_fail "envelope sender not null";
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.