Skip to content

Commit

Permalink
lib-sieve: Fixed writing address headers to outgoing messages.
Browse files Browse the repository at this point in the history
It erroneously applied another layer of MIME header encoding.
The problem is that existing Sieve scripts may rely on this behaviour; i.e. scripts may contain addresesses with literal UTF8 in the phrase part.
Therefore, this change allows both behaviors.
  • Loading branch information
stephanbosch committed Dec 15, 2017
1 parent 811f84f commit 1b2454c
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c
Expand Up @@ -574,13 +574,12 @@ static int ntfy_mailto_send
rfc2822_header_write(msg, "Date", message_date_create(ioloop_time));
rfc2822_header_utf8_printf(msg, "Subject", "%s", subject);

rfc2822_header_utf8_printf(msg, "From", "%s", from);
rfc2822_header_write_address(msg, "From", from);

if ( to != NULL )
rfc2822_header_utf8_printf(msg, "To", "%s", str_c(to));

rfc2822_header_write_address(msg, "To", str_c(to));
if ( cc != NULL )
rfc2822_header_utf8_printf(msg, "Cc", "%s", str_c(cc));
rfc2822_header_write_address(msg, "Cc", str_c(cc));

rfc2822_header_printf(msg, "Auto-Submitted",
"auto-notified; owner-email=\"%s\"",
Expand Down
2 changes: 1 addition & 1 deletion src/lib-sieve/plugins/notify/cmd-notify.c
Expand Up @@ -773,7 +773,7 @@ static bool act_notify_send
}
}

rfc2822_header_write(msg, "To", str_c(to));
rfc2822_header_write_address(msg, "To", str_c(to));

/* Generate message body */
str_printfa(msg, "\r\n%s\r\n", act->message);
Expand Down
2 changes: 1 addition & 1 deletion src/lib-sieve/plugins/vacation/cmd-vacation.c
Expand Up @@ -1015,7 +1015,7 @@ static int act_vacation_send
rfc2822_header_write(msg, "Date", message_date_create(ioloop_time));

if ( ctx->from != NULL && *(ctx->from) != '\0' ) {
rfc2822_header_utf8_printf(msg, "From", "%s", ctx->from);
rfc2822_header_write_address(msg, "From", ctx->from);
} else {
if ( reply_from == NULL || reply_from->mailbox == NULL ||
*reply_from->mailbox == '\0' )
Expand Down
57 changes: 57 additions & 0 deletions tests/extensions/enotify/mailto.svtest
Expand Up @@ -2,6 +2,7 @@ require "vnd.dovecot.testsuite";
require "enotify";
require "relational";
require "envelope";
require "variables";
require "comparator-i;ascii-numeric";

/*
Expand Down Expand Up @@ -483,3 +484,59 @@ test "Envelope config - user_email" {
test_fail "envelope recipient set incorrectly";
}
}

/*
* UTF-8 addresses
*/

test_result_reset;

test_set "message" text:
From: stephan@example.org
To: nico@frop.example.org
Subject: Frop!

Klutsefluts.
.
;

test "UTF-8 address" {
set "to" "=?utf-8?q?G=C3=BCnther?= M. Karotte <g.m.karotte@example.com>";
set "cc" "Dieter T. =?utf-8?q?Stoppelr=C3=BCbe?= <d.t.stoppelruebe@example.com>";

set :encodeurl "to_enc" "${to}";
set :encodeurl "cc_enc" "${cc}";

notify "mailto:?to=${to_enc}&cc=${cc_enc}";

if not test_result_execute {
test_fail "failed to execute notify";
}

test_message :smtp 0;
test_message_print;

set "expected" "Günther M. Karotte <g.m.karotte@example.com>";
if not header :is "to" "${expected}" {
if header :matches "to" "*" { set "decoded" "${1}"; }

test_fail text:
to header is not encoded/decoded properly:
expected: ${expected}
decoded: ${decoded}
.
;
}

set "expected" "Dieter T. Stoppelrübe <d.t.stoppelruebe@example.com>";
if not header :is "cc" "${expected}" {
if header :matches "cc" "*" { set "decoded" "${1}"; }

test_fail text:
to header is not encoded/decoded properly:
expected: ${expected}
decoded: ${decoded}
.
;
}
}
82 changes: 82 additions & 0 deletions tests/extensions/vacation/utf-8.svtest
Expand Up @@ -84,3 +84,85 @@ decoded: ${subject}
;
}
}

test_result_reset;

test_set "message" text:
From: stephan@example.org
Subject: frop
Message-ID: <432df324@example.org>
To: <g.m.karotte@example.com>

Frop
.
;


test "MIME Encoded From" {
vacation :subject "Frop"
:from "=?utf-8?q?G=C3=BCnther?= M. Karotte <g.m.karotte@example.com>"
"I am not in today";

/* Execute Sieve result (sending message to dummy SMTP) */
if not test_result_execute {
test_fail "execution of result failed";
}

/* Retrieve message from dummy SMTP and set it as the active message under
* test.
*/
test_message :smtp 0;

set "expected" "Günther M. Karotte <g.m.karotte@example.com>";
if not header :is "from" "${expected}" {
if header :matches "from" "*" { set "decoded" "${1}"; }

test_fail text:
from header is not encoded/decoded properly:
expected: ${expected}
decoded: ${decoded}
.
;
}
}

test_result_reset;

test_set "message" text:
From: stephan@example.org
Subject: frop
Message-ID: <432df324@example.org>
To: <g.m.karotte@example.com>

Frop
.
;


test "MIME Encoded From - UTF-8 in phrase" {
vacation :subject "Frop"
:from "Günther M. Karotte <g.m.karotte@example.com>"
"I am not in today";

/* Execute Sieve result (sending message to dummy SMTP) */
if not test_result_execute {
test_fail "execution of result failed";
}

/* Retrieve message from dummy SMTP and set it as the active message under
* test.
*/
test_message :smtp 0;

set "expected" "Günther M. Karotte <g.m.karotte@example.com>";
if not header :is "from" "${expected}" {
if header :matches "from" "*" { set "decoded" "${1}"; }

test_fail text:
from header is not encoded/decoded properly:
expected: ${expected}
decoded: ${decoded}
.
;
}
}

0 comments on commit 1b2454c

Please sign in to comment.