diff --git a/src/lib-sieve/plugins/notify/ext-notify-common.c b/src/lib-sieve/plugins/notify/ext-notify-common.c index bd06dd4572395f1758c8575ad15e67014b825d50..a6b7001a1b63d995bd873bf397e822b74036b8a6 100644 --- a/src/lib-sieve/plugins/notify/ext-notify-common.c +++ b/src/lib-sieve/plugins/notify/ext-notify-common.c @@ -243,14 +243,14 @@ void ext_notify_construct_message /* Scan message for substitutions */ p = msg_format; while ( *p != '\0' ) { - const char *const *header; + const char *header; if ( strncasecmp(p, "$from$", 6) == 0 ) { p += 6; - /* Fetch sender from oriinal message */ - if ( mail_get_headers_utf8(msgdata->mail, "from", &header) >= 0 ) - str_append(out_msg, header[0]); + /* Fetch sender from original message */ + if ( mail_get_first_header_utf8(msgdata->mail, "from", &header) > 0 ) + str_append(out_msg, header); } else if ( strncasecmp(p, "$env-from$", 10) == 0 ) { p += 10; @@ -262,8 +262,8 @@ void ext_notify_construct_message p += 9; /* Fetch sender from oriinal message */ - if ( mail_get_headers_utf8(msgdata->mail, "subject", &header) >= 0 ) - str_append(out_msg, header[0]); + if ( mail_get_first_header_utf8(msgdata->mail, "subject", &header) > 0 ) + str_append(out_msg, header); } else if ( strncasecmp(p, "$text", 5) == 0 && (p[5] == '[' || p[5] == '$') ) { diff --git a/tests/deprecated/notify/basic.svtest b/tests/deprecated/notify/basic.svtest index cd6b31d04151cc53244c158fab4843aa18582ddc..974f8ca5b53da05b2b0c72e0c94051083da9a4c2 100644 --- a/tests/deprecated/notify/basic.svtest +++ b/tests/deprecated/notify/basic.svtest @@ -1,5 +1,6 @@ require "vnd.dovecot.testsuite"; require "notify"; +require "body"; test "Execute" { /* Test to catch runtime segfaults */ @@ -8,4 +9,51 @@ test "Execute" { :low :method "mailto" :options ["stephan@example.com", "stephan@example.org"]; + + if not test_result_execute { + test_fail "Execute failed"; + } +} + +test_result_reset; + +test_set "message" text: +To: user@example.com +From: stephan@example.org +Subject: Mail + +Test! +. +; + +test "Substitutions" { + notify + :message "$from$: $subject$" + :options "stephan@example.com"; + if not test_result_execute { + test_fail "Execute failed"; + } + test_message :smtp 0; + if not body :contains "stephan@example.org: Mail" { + test_fail "Substitution failed"; + } } + +test_result_reset; + +test_set "message" text: +To: user@example.com + +Test! +. +; + +test "Empty substitutions" { + notify + :message "$from$: $subject$" + :options "stephan@example.com"; + if not test_result_execute { + test_fail "Execute failed"; + } +} +