Skip to content

Commit

Permalink
lib-sieve: redirect action: Always set X-Sieve-Redirected-From header…
Browse files Browse the repository at this point in the history
… to sieve_user_email if configured.

Set it to the final recipient only when there is an envelope and sieve_user_email is unconfigured.
  • Loading branch information
stephanbosch committed Oct 3, 2017
1 parent 862b85e commit 0828d80
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/lib-sieve/cmd-redirect.c
Expand Up @@ -362,7 +362,8 @@ static int act_redirect_send
/* Prepend sieve headers (should not affect signatures) */
rfc2822_header_append(hdr,
"X-Sieve", SIEVE_IMPLEMENTATION, FALSE, NULL);
if ( (aenv->flags & SIEVE_EXECUTE_FLAG_NO_ENVELOPE) == 0 )
if ( svinst->user_email == NULL &&
(aenv->flags & SIEVE_EXECUTE_FLAG_NO_ENVELOPE) == 0 )
user_email = sieve_message_get_final_recipient(msgctx);
else
user_email = sieve_get_user_email(aenv->svinst);
Expand Down
46 changes: 45 additions & 1 deletion tests/execute/smtp.svtest
Expand Up @@ -36,6 +36,11 @@ test "Redirect" {
if not envelope :is "from" "sirius@example.org" {
test_fail "envelope sender incorrect";
}

if not header :contains "x-sieve-redirected-from"
"timo@example.net" {
test_fail "x-sieve-redirected-from header is incorrect";
}
}

test_result_reset;
Expand Down Expand Up @@ -66,6 +71,11 @@ test "Redirect from <>" {
if not envelope :is "from" "" {
test_fail "envelope sender incorrect";
}

if not header :contains "x-sieve-redirected-from"
"timo@example.net" {
test_fail "x-sieve-redirected-from header is incorrect";
}
}

test_result_reset;
Expand Down Expand Up @@ -99,6 +109,11 @@ test "Redirect from [recipient]" {
if not envelope :is "from" "timo@example.net" {
test_fail "envelope sender incorrect";
}

if not header :contains "x-sieve-redirected-from"
"timo@example.net" {
test_fail "x-sieve-redirected-from header is incorrect";
}
}

test_result_reset;
Expand Down Expand Up @@ -133,8 +148,12 @@ test "Redirect from [original recipient]" {
if not envelope :is "from" "tss@example.net" {
test_fail "envelope sender incorrect";
}
}

if not header :contains "x-sieve-redirected-from"
"timo@example.net" {
test_fail "x-sieve-redirected-from header is incorrect";
}
}

test_result_reset;
test_set "message" text:
Expand Down Expand Up @@ -168,6 +187,11 @@ test "Redirect from [<explicit>]" {
if not envelope :is "from" "backscatter@example.net" {
test_fail "envelope sender incorrect";
}

if not header :contains "x-sieve-redirected-from"
"timo@example.net" {
test_fail "x-sieve-redirected-from header is incorrect";
}
}

test_result_reset;
Expand Down Expand Up @@ -201,6 +225,11 @@ test "Redirect from [<>]" {
if not envelope :is "from" "" {
test_fail "envelope sender incorrect";
}

if not header :contains "x-sieve-redirected-from"
"timo@example.net" {
test_fail "x-sieve-redirected-from header is incorrect";
}
}

test_result_reset;
Expand Down Expand Up @@ -235,6 +264,11 @@ test "Redirect from <> with [<explicit>]" {
if not envelope :is "from" "" {
test_fail "envelope sender incorrect";
}

if not header :contains "x-sieve-redirected-from"
"timo@example.net" {
test_fail "x-sieve-redirected-from header is incorrect";
}
}

test_result_reset;
Expand Down Expand Up @@ -265,6 +299,11 @@ test "Redirect from [user email - fallback default]" {
if not envelope :is "from" "timo@example.net" {
test_fail "envelope sender incorrect";
}

if not header :contains "x-sieve-redirected-from"
"timo@example.net" {
test_fail "x-sieve-redirected-from header is incorrect";
}
}

test_result_reset;
Expand Down Expand Up @@ -300,5 +339,10 @@ test "Redirect from [user email]" {
if not envelope :is "from" "t.sirainen@example.net" {
test_fail "envelope sender incorrect";
}

if not header :contains "x-sieve-redirected-from"
"t.sirainen@example.net" {
test_fail "x-sieve-redirected-from header is incorrect";
}
}

0 comments on commit 0828d80

Please sign in to comment.