diff --git a/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c b/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c index 60e2a1549..b0d598644 100644 --- a/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c +++ b/src/lib-sieve/plugins/enotify/mailto/ntfy-mailto.c @@ -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\"", diff --git a/src/lib-sieve/plugins/notify/cmd-notify.c b/src/lib-sieve/plugins/notify/cmd-notify.c index 02de65aa2..964fdecc7 100644 --- a/src/lib-sieve/plugins/notify/cmd-notify.c +++ b/src/lib-sieve/plugins/notify/cmd-notify.c @@ -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); diff --git a/src/lib-sieve/plugins/vacation/cmd-vacation.c b/src/lib-sieve/plugins/vacation/cmd-vacation.c index acf698eec..7ef62ae3d 100644 --- a/src/lib-sieve/plugins/vacation/cmd-vacation.c +++ b/src/lib-sieve/plugins/vacation/cmd-vacation.c @@ -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' ) diff --git a/tests/extensions/enotify/mailto.svtest b/tests/extensions/enotify/mailto.svtest index 82f47be84..e0d46b6c4 100644 --- a/tests/extensions/enotify/mailto.svtest +++ b/tests/extensions/enotify/mailto.svtest @@ -2,6 +2,7 @@ require "vnd.dovecot.testsuite"; require "enotify"; require "relational"; require "envelope"; +require "variables"; require "comparator-i;ascii-numeric"; /* @@ -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 "; + set "cc" "Dieter T. =?utf-8?q?Stoppelr=C3=BCbe?= "; + + 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 "; + 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 "; + 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} +. +; + } +} diff --git a/tests/extensions/vacation/utf-8.svtest b/tests/extensions/vacation/utf-8.svtest index 6697849f1..e94f7b9b8 100644 --- a/tests/extensions/vacation/utf-8.svtest +++ b/tests/extensions/vacation/utf-8.svtest @@ -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: + +Frop +. +; + + +test "MIME Encoded From" { + vacation :subject "Frop" + :from "=?utf-8?q?G=C3=BCnther?= M. Karotte " + "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 "; + 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: + +Frop +. +; + + +test "MIME Encoded From - UTF-8 in phrase" { + vacation :subject "Frop" + :from "Günther M. Karotte " + "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 "; + 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} +. +; + } +}